Skip to content

Commit

Permalink
Supply axis_descriptors and extra_meta data to QGL1 compile_to_hardwa…
Browse files Browse the repository at this point in the history
…re, matching QGL1 versions
  • Loading branch information
ahelsing committed Sep 16, 2019
1 parent 516aea6 commit 91ecf14
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 57 deletions.
77 changes: 65 additions & 12 deletions src/python/qgl2/basic_sequences/CR.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qgl2.qgl1 import Id, X, MEAS, X90, flat_top_gaussian_edge, echoCR, Y90m

from qgl2.basic_sequences.helpers import create_cal_seqs, measConcurrently
from qgl2.basic_sequences.helpers import create_cal_seqs, measConcurrently, cal_descriptor, delay_descriptor
from qgl2.util import init

from itertools import product
Expand Down Expand Up @@ -301,19 +301,72 @@ def main():
q1 = QRegister("q1")
q2 = QRegister("q2")

# Axis Descriptor generator functions here
# This is ugly; they're method dependent, but I can't do them in the QGL2 itself
# Additionally, each uses values from the args to the function
# So here we make those arguments be constants so we can use them twice
# without rewriting the values
pirlengths = np.linspace(0, 4e-6, 11) # Lengths arg to PiRabi
eclLengths = np.linspace(0, 2e-6, 11) # Lengths arg to EchoCRLen
trisefall = 40e-9 # riseFall arg for many
tamp = 1 # amp arg for many
t2amp = 0.8 # amp arg for CRTomo
tphase = 0 # phase arg for many
tcalr = 2 # calRepeats arg for many
ecpPhases = np.linspace(0, np.pi/2, 11) # phases arg for EchoCRPhase
ecaAmps = np.linspace(0, 5e-6, 11) # amps arg for echoCRAmp
crtLengths = np.linspace(0, 2e-6, 11) # lengths arg for CRtomo_seq
def getPRAxisDesc(lengths, calRepeats):
return [
delay_descriptor(np.concatenate((lengths, lengths))),
# Hard code there are 2 qubits
cal_descriptor(('c', 't'), calRepeats)
]
def getECLAxisDesc(lengths, calRepeats):
return [
delay_descriptor(np.concatenate((lengths, lengths))),
# Hard code there are 2 qubits
cal_descriptor(('controlQ', 'targetQ'), calRepeats)
]
def getECPAxisDesc(phases, calRepeats):
return [
{
'name': 'phase',
'unit': 'radians',
'points': list(phases)+list(phases),
'partition': 1
},
cal_descriptor(('controlQ', 'targetQ'), calRepeats)
]
def getECAAxisDesc(amps, calRepeats):
return [
{
'name': 'amplitude',
'unit': None,
'points': list(amps)+list(amps),
'partition': 1
},
cal_descriptor(('controlQ', 'targetQ'), calRepeats)
]
def getCRtAxisDesc(lengths):
return [
delay_descriptor(np.concatenate((np.repeat(lengths,3), np.repeat(lengths,3)))),
cal_descriptor(('targetQ',), 2)
]

# FIXME: See issue #44: Must supply all args to qgl2main for now

# for func, args, label in [("PiRabi", (q1, q2, np.linspace(0, 4e-6, 11)), "PiRabi"),
# ("EchoCRLen", (q1, q2, np.linspace(0, 2e-6, 11)), "EchoCR"),
# ("EchoCRPhase", (q1, q2, np.linspace(0, np.pi/2, 11)), "EchoCR"),
# ("EchoCRAmp", (q1, q2, np.linspace(0, 5e-6, 11)), "EchoCR"), # FIXME: Right values?
# ("CRtomo_seq", (q1, q2, np.linspace(0, 2e-6, 11), 0), "CR") # FIXME: Right values?
# for func, args, label, axisDesc in [("PiRabi", (q1, q2, pirlengths), "PiRabi", getPRAxisDesc(pirlengths, tcalr)),
# ("EchoCRLen", (q1, q2, np.linspace(0, 2e-6, 11)), "EchoCR", getECLAxisDesc(eclLengths, tcalr)),
# ("EchoCRPhase", (q1, q2, np.linspace(0, np.pi/2, 11)), "EchoCR", getECPAxisDesc(ecpPhases, tcalr)),
# ("EchoCRAmp", (q1, q2, np.linspace(0, 5e-6, 11)), "EchoCR", getECAAxisDesc(ecaAmps, tcalr)), # FIXME: Right values?
# ("CRtomo_seq", (q1, q2, np.linspace(0, 2e-6, 11), 0), "CR", getCRtAxisDesc(crtLengths)) # FIXME: Right values?
# ]:
for func, args, label in [("PiRabi", (q1, q2, np.linspace(0, 4e-6, 11), 40e-9,1,0,2), "PiRabi"),
("EchoCRLen", (q1, q2, np.linspace(0, 2e-6, 11),40e-9,1,0,2,0,np.pi/2), "EchoCR"),
("EchoCRPhase", (q1, q2, np.linspace(0, np.pi/2, 11),40e-9,1,100e-9,2,0,np.pi/2), "EchoCR"),
("EchoCRAmp", (q1, q2, np.linspace(0, 5e-6, 11),40e-9,50e-9,0,2), "EchoCR"), # FIXME: Right values?
("CRtomo_seq", (q1, q2, np.linspace(0, 2e-6, 11), 0, 0.8,20e-9), "CR") # FIXME: Right values?
for func, args, label, axisDesc in [("PiRabi", (q1, q2, pirlengths, trisefall,tamp,tphase,tcalr), "PiRabi", getPRAxisDesc(pirlengths, tcalr)),
("EchoCRLen", (q1, q2, eclLengths, trisefall, tamp, tphase, tcalr, 0, np.pi/2), "EchoCR", getECLAxisDesc(eclLengths, tcalr)),
("EchoCRPhase", (q1, q2, ecpPhases, trisefall,tamp,100e-9,tcalr,0,np.pi/2), "EchoCR", getECPAxisDesc(ecpPhases, tcalr)),
("EchoCRAmp", (q1, q2, ecaAmps, trisefall,50e-9,tphase,tcalr), "EchoCR", getECAAxisDesc(ecaAmps, tcalr)), # FIXME: Right values?
("CRtomo_seq", (q1, q2, crtLengths, 0, t2amp,20e-9), "CR", getCRtAxisDesc(crtLengths)) # FIXME: Right values?
]:

print(f"\nRun {func}...")
Expand All @@ -325,7 +378,7 @@ def main():
seq = resFunc()
if toHW:
print(f"Compiling {func} sequences to hardware\n")
fileNames = qgl2_compile_to_hardware(seq, f'{label}/{label}')
fileNames = qgl2_compile_to_hardware(seq, filename=f'{label}/{label}', axis_descriptor=axisDesc)
print(f"Compiled sequences; metafile = {fileNames}")
if plotPulses:
from QGL.PulseSequencePlotter import plot_pulse_files
Expand Down
36 changes: 29 additions & 7 deletions src/python/qgl2/basic_sequences/Decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from qgl2.qgl2 import qgl2decl, qreg, QRegister

from qgl2.qgl1 import X90, Id, Y, U90, MEAS, pulseCentered
from qgl2.basic_sequences.helpers import create_cal_seqs
from qgl2.basic_sequences.helpers import create_cal_seqs, cal_descriptor, delay_descriptor
from qgl2.util import init

from math import pi
Expand Down Expand Up @@ -106,7 +106,7 @@ def main():
import numpy as np

toHW = True
plotPulses = False
plotPulses = False # This tries to produce graphics to display
pyqgl2.test_cl.create_default_channelLibrary(toHW, True)

# # To turn on verbose logging in compile_function
Expand All @@ -125,13 +125,35 @@ def main():
# Pass in QRegister(s) NOT real Qubits
q1 = QRegister("q1")

# Axis Descriptor generator functions here
# This is ugly; they're method dependent, but I can't do them in the QGL2 itself
# Additionally, each uses values from the args to the function
# So here we make those arguments be constants so we can use them twice
# without rewriting the values
hahnSpacings = np.linspace(0, 5e-6, 11)
tCalR = 2 # calRepeats
cpmgNumPulses = [0, 2, 4, 6]
cpmgSpacing = 500e-9
def getHahnAxisDesc(pulseSpacings, calRepeats):
return [
delay_descriptor(2 * pulseSpacings),
cal_descriptor(('qubit',), calRepeats)
]
def getCPMGAxisDesc(pulseSpacing, numPulses, calRepeats):
return [
# NOTE: numPulses is not a numpy array, so cannot multiply by a float
# But thankfully, np.array(np.array) = np.array so this is always a good move here.
delay_descriptor(pulseSpacing * np.array(numPulses)),
cal_descriptor(('qubit',), calRepeats)
]

# FIXME: See issue #44: Must supply all args to qgl2main for now

# for func, args, label in [("HahnEcho", (q1, np.linspace(0, 5e-6, 11)), "HahnEcho"),
# ("CPMG", (q1, [0, 2, 4, 5], 500e-9), "CPMG"),
# for func, args, label, axisDesc in [("HahnEcho", (q1, hahnSpacings), "HahnEcho", getHahnAxisDesc(hahnSpacings, tCalR)),
# ("CPMG", (q1, cpmgNumPulses, cpmgSpacing), "CPMG", getCPMGAxisDesc(cpmgSpacing, cpmgNumPulses, tCalR)),
# ]:
for func, args, label in [("HahnEcho", (q1, np.linspace(0, 5e-6, 11), 0, 2), "HahnEcho"),
("CPMG", (q1, [0, 2, 4, 6], 500e-9, 2), "CPMG"),
for func, args, label, axisDesc in [("HahnEcho", (q1, hahnSpacings, 0, tCalR), "HahnEcho", getHahnAxisDesc(hahnSpacings, tCalR)),
("CPMG", (q1, cpmgNumPulses, cpmgSpacing, tCalR), "CPMG", getCPMGAxisDesc(cpmgSpacing, cpmgNumPulses, tCalR)),
]:

print(f"\nRun {func}...")
Expand All @@ -143,7 +165,7 @@ def main():
seq = resFunc()
if toHW:
print(f"Compiling {func} sequences to hardware\n")
fileNames = qgl2_compile_to_hardware(seq, f'{label}/{label}')
fileNames = qgl2_compile_to_hardware(seq, filename=f'{label}/{label}', axis_descriptor=axisDesc)
print(f"Compiled sequences; metafile = {fileNames}")
if plotPulses:
from QGL.PulseSequencePlotter import plot_pulse_files
Expand Down
82 changes: 68 additions & 14 deletions src/python/qgl2/basic_sequences/RB.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# from QGL.Cliffords import clifford_seq, clifford_mat, inverse_clifford
from qgl2.Cliffords import clifford_mat, inverse_clifford

from qgl2.basic_sequences.helpers import create_cal_seqs, measConcurrently
from qgl2.basic_sequences.helpers import create_cal_seqs, measConcurrently, cal_descriptor, delay_descriptor

from qgl2.util import init

Expand Down Expand Up @@ -595,24 +595,75 @@ def beforeSingleRBAC():

# FIXME: Add test of SingleQubitRB_DiAC

# for func, args, label, beforeFunc in [("SingleQubitRB", (q1, create_RB_seqs(1, 2**np.arange(1,7))), "RB", beforeSingleRB),
# ("TwoQubitRB", (q1, q2, create_RB_seqs(2, [2, 4, 8, 16, 32], repeats=16)), "RB", beforeTwoRB),
# ("SimultaneousRB_AC", (qr, (create_RB_seqs(1, 2**np.arange(1,7)), create_RB_seqs(1, 2**np.arange(1,7)))), "RB", beforeSimRBAC),
# ("SingleQubitRB_AC", (q1,create_RB_seqs(1, 2**np.arange(1,7))), "RB", beforeSingleRBAC),
# ("SingleQubitIRB_AC", (q1,''), "RB"),
sqCSeqs = create_RB_seqs(1, 2**np.arange(1,7))
tqCSeqs = create_RB_seqs(2, [2, 4, 8, 16, 32], repeats=16)
simCSeqs = (sqCSeqs, sqCSeqs)
tAddCals = True
def getSingleQubitRBAD(seqs, add_cals):
ad = [{
'name': 'length',
'unit': None,
'points': list(map(len, seqs)),
'partition': 1
}]
if add_cals:
ad.append(cal_descriptor(('qubit',), 2))
return ad

def getTwoQubitRBAD(seqs, add_cals):
axis_descriptor = [{
'name': 'length',
'unit': None,
'points': list(map(len, seqs)),
'partition': 1
}]
if add_cals:
axis_descriptor.append(cal_descriptor(('q1', 'q2'), 2))
return axis_descriptor

def getSingleQubitRBAC_AD(seqs, add_cals):
axis_descriptor = [{
'name': 'length',
'unit': None,
'points': list(map(len, seqs)),
'partition': 1
}]
if add_cals:
axis_descriptor.append(cal_descriptor(('qubit',), 2))
return axis_descriptor

def getSimRBACAD(seqs, add_cals, qubits):
axis_descriptor = [{
'name': 'length',
'unit': None,
'points': list(map(len, seqs)),
'partition': 1
}]
if add_cals:
axis_descriptor.append(cal_descriptor((qubits), 2))
return axis_descriptor

# FIXME: SingleQubitIRB_AC filenames are more complex
# FIXME: SingleQubitRBT has complex suffix it should pass to compile_to_hardware

# for func, args, label, beforeFunc, axisDesc, cseqs in [("SingleQubitRB", (q1, sqCSeqs), "RB", beforeSingleRB, getSingleQubitRBAD(sqCSeqs, tAddCals), sqCSeqs),
# ("TwoQubitRB", (q1, q2, tqCSeqs), "RB", beforeTwoRB, getTwoQubitRBAD(tqCSeqs, tAddCals), tqCSeqs),
# ("SingleQubitRB_AC", (q1,sqCSeqs), "RB", beforeSingleRBAC, getSingleQubitRBAC_AD(sqCSeqs, tAddCals), sqCSeqs),
# ("SimultaneousRB_AC", (qr, simCSeqs), "RB", beforeSimRBAC, getSimRBACAD(simCSeqs, tAddCals, qr), simCSeqs),
# ("SingleQubitIRB_AC", (q1,''), "RB", None, None, None),
# Comment says this next one relies on a specific file, so don't bother running
# ("SingleQubitRBT", (q1,'', fixmePulse), "RBT"),
# ("SingleQubitRBT", (q1,'', fixmePulse), "RBT", None, None, None),
# ]:

for func, args, label, beforeFunc in [("SingleQubitRB", (q1, create_RB_seqs(1, 2**np.arange(1,7)), False, True), "RB", beforeSingleRB),
("TwoQubitRB", (q1, q2, create_RB_seqs(2, [2, 4, 8, 16, 32], repeats=16), True), "RB", beforeTwoRB),
("SingleQubitRB_AC", (q1,create_RB_seqs(1, 2**np.arange(1,7)), False, True), "RB", beforeSingleRBAC),
for func, args, label, beforeFunc, axisDesc, cseqs in [("SingleQubitRB", (q1, sqCSeqs, False, tAddCals), "RB", beforeSingleRB, getSingleQubitRBAD(sqCSeqs, tAddCals), sqCSeqs),
("TwoQubitRB", (q1, q2, tqCSeqs, tAddCals), "RB", beforeTwoRB, getTwoQubitRBAD(tqCSeqs, tAddCals), tqCSeqs),
("SingleQubitRB_AC", (q1,sqCSeqs, False, tAddCals), "RB", beforeSingleRBAC, getSingleQubitRBAC_AD(sqCSeqs, tAddCals), sqCSeqs),
# Warning: This next one is slow....
("SimultaneousRB_AC", (qr, (create_RB_seqs(1, 2**np.arange(1,7)), create_RB_seqs(1, 2**np.arange(1,7))), True), "RB", beforeSimRBAC),
("SimultaneousRB_AC", (qr, simCSeqs, tAddCals), "RB", beforeSimRBAC, getSimRBACAD(simCSeqs, tAddCals, qr), simCSeqs),
# This next one relies on a file of sequence strings, which I don't have
# ("SingleQubitIRB_AC", (q1,None), "RB", None),
# ("SingleQubitIRB_AC", (q1,None), "RB", None, None, None),
# Comment says this next one relies on a specific file, so don't bother running
# # ("SingleQubitRBT", (q1,'', fixmePulse, True), "RBT", None),
# # ("SingleQubitRBT", (q1,'', fixmePulse, True), "RBT", None, None, None),
]:

print(f"\nRun {func}...")
Expand All @@ -631,7 +682,10 @@ def beforeSingleRBAC():
import QGL
print(f"Compiling {func} sequences to hardware\n")
# QGL.Compiler.set_log_level()
fileNames = qgl2_compile_to_hardware(seq, f'{label}/{label}')
em = None
if cseqs:
em = {'sequences':cseqs}
fileNames = qgl2_compile_to_hardware(seq, filename=f'{label}/{label}', axis_descriptor=axisDesc, extra_meta = em)
print(f"Compiled sequences; metafile = {fileNames}")
if plotPulses:
from QGL.PulseSequencePlotter import plot_pulse_files
Expand Down
67 changes: 51 additions & 16 deletions src/python/qgl2/basic_sequences/Rabi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2016 by Raytheon BBN Technologies Corp. All Rights Reserved.

from qgl2.basic_sequences.helpers import create_cal_seqs, measConcurrently
from qgl2.basic_sequences.helpers import create_cal_seqs, measConcurrently, cal_descriptor, delay_descriptor
from qgl2.qgl2 import qgl2decl, qreg, QRegister
from qgl2.qgl1 import Utheta, MEAS, X, Id
from qgl2.util import init
Expand Down Expand Up @@ -213,24 +213,59 @@ def main():
q2 = QRegister("q2")
qr = QRegister(q1, q2)

rAmpAmps = np.linspace(0, 1, 1)
rWidthWidths = np.linspace(0, 5e-6, 11)
ranqAmps = np.linspace(0, 5e-6, 11)
tCalR = 2
rAmpPiAmps = np.linspace(0, 1, 11)

def getRAmpAD(amps):
return [{
'name': 'amplitude',
'unit': None,
'points': list(amps),
'partition': 1
}]
def getRWidthAD(widths):
return [delay_descriptor(widths)]

def getRAmpNQAD(qubits, amps, calRepeats):
return [
{
'name': 'amplitude',
'unit': None,
'points': list(amps),
'partition': 1
},
cal_descriptor(qubits, calRepeats)
]

def getRAmpPiAD(amps):
return [{
'name': 'amplitude',
'unit': None,
'points': list(amps),
'partition': 1
}]

# FIXME: See issue #44: Must supply all args to qgl2main for now

# for func, args, label in [("RabiAmp", (q1, np.linspace(0, 1, 1)), "Rabi"),
# ("RabiWidth", (q1, np.linspace(0, 5e-6, 11)), "Rabi"),
# ("RabiAmpPi", (q1, q2, np.linspace(0, 1, 11)), "Rabi"),
# ("SingleShow", (q1,), "SingleShot"),
# ("PulsedSpec", (q1,), "Spec"),
# ("RabiAmp_NQubits", (qr,np.linspace(0, 5e-6, 11)), "Rabi"),
# ("Swap", (q1, np.linspace(0, 5e-6, 11), "Swap"),
# for func, args, label, axisDec in [("RabiAmp", (q1, rAmpAmps), "Rabi", getRAmpAD(rAmpAmps)),
# ("RabiWidth", (q1, rWidthWidths), "Rabi", getRWidthAD(rWidthWidths)),
# ("RabiAmpPi", (q1, q2, rAmpPiAmps), "Rabi", getRAmpPiAD(rAmpPiAmps)),
# ("SingleShow", (q1,), "SingleShot", None),
# ("PulsedSpec", (q1,), "Spec", None),
# ("RabiAmp_NQubits", (qr,ranqAmps), "Rabi", getRAmpNQAD(qr, ranqAmps, tCalR)),
# ("Swap", (q1, np.linspace(0, 5e-6, 11), "Swap", None),
# ]:

for func, args, label in [("RabiAmp", (q1, np.linspace(0, 1, 1), 0), "Rabi"),
("RabiWidth", (q1, np.linspace(0, 5e-6, 11), 1, 0, QGL.PulseShapes.tanh), "Rabi"),
("RabiAmpPi", (q1, q2, np.linspace(0, 1, 11), 0), "Rabi"),
("SingleShot", (q1,), "SingleShot"),
("PulsedSpec", (q1,True), "Spec"),
("RabiAmp_NQubits", (qr,np.linspace(0, 5e-6, 11), 0, qr, False, 2), "Rabi"),
("Swap", (q1, np.linspace(0, 5e-6, 11), q2), "Swap")
for func, args, label, axisDesc in [("RabiAmp", (q1, rAmpAmps, 0), "Rabi", getRAmpAD(rAmpAmps)),
("RabiWidth", (q1, rWidthWidths, 1, 0, QGL.PulseShapes.tanh), "Rabi", getRWidthAD(rWidthWidths)),
("RabiAmpPi", (q1, q2, rAmpPiAmps, 0), "Rabi", getRAmpPiAD(rAmpPiAmps)),
("SingleShot", (q1,), "SingleShot", None),
("PulsedSpec", (q1,True), "Spec", None),
("RabiAmp_NQubits", (qr,ranqAmps, 0, qr, False, tCalR), "Rabi", getRAmpNQAD(qr, ranqAmps, tCalR)),
("Swap", (q1, np.linspace(0, 5e-6, 11), q2), "Swap", None)
]:

print(f"\nRun {func}...")
Expand All @@ -244,7 +279,7 @@ def main():
print(f"Compiling {func} sequences to hardware\n")
# To get verbose logging including showing the compiled sequences:
# QGL.Compiler.set_log_level()
fileNames = qgl2_compile_to_hardware(seq, f'{label}/{label}')
fileNames = qgl2_compile_to_hardware(seq, filename=f'{label}/{label}', axis_descriptor=axisDesc)
print(f"Compiled sequences; metafile = {fileNames}")
if plotPulses:
from QGL.PulseSequencePlotter import plot_pulse_files
Expand Down
Loading

0 comments on commit 91ecf14

Please sign in to comment.