Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CR order #181

Closed
wants to merge 13 commits into from
108 changes: 54 additions & 54 deletions QGL/BasicSequences/CR.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ def PiRabi(controlQ,
calRepeats=2,
showPlot=False):
"""
Variable length CX experiment.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
targetQ: logical channel for the target qubit (LogicalChannel)
lengths : pulse lengths of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
amp : amplitude of the CR pulse
phase : phase of the CR pulse (rad)
showPlot : whether to plot (boolean)
"""
Variable length CX experiment.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
targetQ: logical channel for the target qubit (LogicalChannel)
lengths : pulse lengths of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
amp : amplitude of the CR pulse
phase : phase of the CR pulse (rad)
showPlot : whether to plot (boolean)
"""

CRchan = EdgeFactory(controlQ, targetQ)
seqs = [[Id(controlQ),
Expand Down Expand Up @@ -59,19 +59,19 @@ def EchoCRLen(controlQ,
calRepeats=2,
showPlot=False, canc_amp=0, canc_phase=np.pi/2):
"""
Variable length CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
targetQ: logical channel for the target qubit (LogicalChannel)
lengths : pulse lengths of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
amp : amplitude of the CR pulse
phase : phase of the CR pulse (rad)
calRepeats : number of repetitions of readout calibrations for each 2-qubit state
showPlot : whether to plot (boolean)
"""
Variable length CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
targetQ: logical channel for the target qubit (LogicalChannel)
lengths : pulse lengths of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
amp : amplitude of the CR pulse
phase : phase of the CR pulse (rad)
calRepeats : number of repetitions of readout calibrations for each 2-qubit state
showPlot : whether to plot (boolean)
"""
seqs = [[Id(controlQ),
echoCR(controlQ, targetQ, length=l, phase=phase, amp=amp, riseFall=riseFall, canc_amp=canc_amp, canc_phase=canc_phase),
Id(controlQ),
Expand All @@ -80,7 +80,7 @@ def EchoCRLen(controlQ,
echoCR(controlQ, targetQ, length=l, phase= phase, amp=amp, riseFall=riseFall, canc_amp=canc_amp, canc_phase=canc_phase),
X(controlQ),
MEAS(targetQ)*MEAS(controlQ)] for l in lengths] + \
create_cal_seqs((targetQ,controlQ), calRepeats, measChans=(targetQ, controlQ))
create_cal_seqs((controlQ,targetQ), calRepeats, measChans=(targetQ,controlQ))

metafile = compile_to_hardware(seqs, 'EchoCR/EchoCR',
axis_descriptor=[
Expand All @@ -105,19 +105,19 @@ def EchoCRPhase(controlQ,
canc_amp=0,
canc_phase=np.pi/2):
"""
Variable phase CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
CRchan: logical channel for the cross-resonance pulse (LogicalChannel)
phases : pulse phases of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
amp : amplitude of the CR pulse
length : duration of each of the two flat parts of the CR pulse (s)
calRepeats : number of repetitions of readout calibrations for each 2-qubit state
showPlot : whether to plot (boolean)
"""
Variable phase CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
CRchan: logical channel for the cross-resonance pulse (LogicalChannel)
phases : pulse phases of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
amp : amplitude of the CR pulse
length : duration of each of the two flat parts of the CR pulse (s)
calRepeats : number of repetitions of readout calibrations for each 2-qubit state
showPlot : whether to plot (boolean)
"""
seqs = [[Id(controlQ),
echoCR(controlQ, targetQ, length=length, phase=ph, amp=amp, riseFall=riseFall, canc_amp=canc_amp, canc_phase=canc_phase),
X90(targetQ)*Id(controlQ),
Expand All @@ -126,7 +126,7 @@ def EchoCRPhase(controlQ,
echoCR(controlQ, targetQ, length=length, phase= ph, amp=amp, riseFall = riseFall, canc_amp=canc_amp, canc_phase=canc_phase),
X90(targetQ)*X(controlQ),
MEAS(targetQ)*MEAS(controlQ)] for ph in phases] + \
create_cal_seqs((targetQ,controlQ), calRepeats, measChans=(targetQ,controlQ))
create_cal_seqs((controlQ, targetQ), calRepeats, measChans=(targetQ,controlQ))

axis_descriptor = [
{
Expand Down Expand Up @@ -156,19 +156,19 @@ def EchoCRAmp(controlQ,
calRepeats=2,
showPlot=False):
"""
Variable amplitude CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
targetQ: logical channel for the target qubit (LogicalChannel)
amps : pulse amplitudes of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
length : duration of each of the two flat parts of the CR pulse (s)
phase : phase of the CR pulse (rad)
calRepeats : number of repetitions of readout calibrations for each 2-qubit state
showPlot : whether to plot (boolean)
"""
Variable amplitude CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.

Parameters
----------
controlQ : logical channel for the control qubit (LogicalChannel)
targetQ: logical channel for the target qubit (LogicalChannel)
amps : pulse amplitudes of the CR pulse to sweep over (iterable)
riseFall : rise/fall time of the CR pulse (s)
length : duration of each of the two flat parts of the CR pulse (s)
phase : phase of the CR pulse (rad)
calRepeats : number of repetitions of readout calibrations for each 2-qubit state
showPlot : whether to plot (boolean)
"""
seqs = [[Id(controlQ),
echoCR(controlQ, targetQ, length=length, phase=phase, riseFall=riseFall,amp=a),
Id(controlQ),
Expand All @@ -177,7 +177,7 @@ def EchoCRAmp(controlQ,
echoCR(controlQ, targetQ, length=length, phase= phase, riseFall=riseFall,amp=a),
X(controlQ),
MEAS(targetQ)*MEAS(controlQ)] for a in amps] + \
create_cal_seqs((targetQ,controlQ), calRepeats, measChans=(targetQ,controlQ))
create_cal_seqs((controlQ ,targetQ), calRepeats, measChans=(targetQ,controlQ))

axis_descriptor = [
{
Expand Down
2 changes: 1 addition & 1 deletion QGL/BasicSequences/RB.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def TwoQubitRB(q1, q2, seqs, showPlot=False, suffix="", add_cals=True):
"""
seqsBis = []
for seq in seqs:
seqsBis.append(reduce(operator.add, [clifford_seq(c, q1, q2)
seqsBis.append(reduce(operator.add, [clifford_seq(c, q2, q1)
for c in seq]))

#Add the measurement to all sequences
Expand Down
45 changes: 24 additions & 21 deletions QGL/ChannelLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,35 @@ def load_from_library(self, return_only=False):
else:
master_awgs.append(name)
# Eventually we should support multiple masters...
# if "slave_trig" in instr.keys():
# params = {}
# params["label"] = name + "_slave_trig"
# params["phys_chan"] = name + "-" + instr["slave_trig"]
# params["pulse_params"] = {"length": 1e-7, "shape_fun": "constant"}
# params["__module__"] = "QGL.Channels"
# params["__class__"] = "LogicalMarkerChannel"
# print(params["label"], "***")
# channel_dict[params["label"]] = params
if "slave_trig" in instr.keys():
params = {}
params["label"] = "slave_trig"
params["phys_chan"] = name + "-" + instr["slave_trig"]
if params["phys_chan"] in marker_lens.keys():
length = marker_lens[params["phys_chan"]]
else:
length = 1e-7
params["pulse_params"] = {"length": length, "shape_fun": "constant"}
params["__module__"] = "QGL.Channels"
params["__class__"] = "LogicalMarkerChannel"
channel_dict[params["label"]] = params

# Establish the slave trigger, assuming for now that we have a single
# APS master. This might change later.
if len(master_awgs) > 1:
raise ValueError("More than one AWG is marked as master.")
elif len(master_awgs) == 1 and instr_dict[master_awgs[0].split('-')[0]]['type'] != 'TDM':
params = {}
params["label"] = "slave_trig"
params["phys_chan"] = master_awgs[0]
if params["phys_chan"] in marker_lens.keys():
length = marker_lens[params["phys_chan"]]
else:
length = 1e-7
params["pulse_params"] = {"length": length, "shape_fun": "constant"}
params["__module__"] = "QGL.Channels"
params["__class__"] = "LogicalMarkerChannel"
channel_dict[params["label"]] = params
# elif len(master_awgs) == 1 and instr_dict[master_awgs[0].split('-')[0]]['type'] != 'TDM':
# params = {}
# params["label"] = "slave_trig"
# params["phys_chan"] = master_awgs[0]
# if params["phys_chan"] in marker_lens.keys():
# length = marker_lens[params["phys_chan"]]
# else:
# length = 1e-7
# params["pulse_params"] = {"length": length, "shape_fun": "constant"}
# params["__module__"] = "QGL.Channels"
# params["__class__"] = "LogicalMarkerChannel"
# channel_dict[params["label"]] = params

for name, filt in filter_dict.items():
if "StreamSelector" in filt["type"]:
Expand Down
17 changes: 11 additions & 6 deletions QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
MAX_NUM_INSTRUCTIONS = 2**26
MAX_REPEAT_COUNT = 2**16 - 1
MAX_TRIGGER_COUNT = 2**32 - 1
NUM_NCO = 4

# instruction encodings
WFM = 0x0
Expand Down Expand Up @@ -583,13 +584,19 @@ def to_instruction(self, write_flag=True, label=None):
NCO_SELECT_OP_OFFSET = 40
MODULATION_CLOCK = 300e6

nco_select_bits = {1 : 0b0001,
2 : 0b0010,
3 : 0b0100,
4 : 0b1000,
15: 0b1111}[self.nco_select]

op_code_map = {"MODULATE": 0x0,
"RESET_PHASE": 0x2,
"SET_FREQ": 0x6,
"SET_PHASE": 0xa,
"UPDATE_FRAME": 0xe}
payload = (op_code_map[self.instruction] << MODULATOR_OP_OFFSET) | (
self.nco_select << NCO_SELECT_OP_OFFSET)
(nco_select_bits) << NCO_SELECT_OP_OFFSET)
if self.instruction == "MODULATE":
#zero-indexed quad count
payload |= np.uint32(self.length / ADDRESS_UNIT - 1)
Expand Down Expand Up @@ -617,8 +624,8 @@ def inject_modulation_cmds(seqs):
for ct,seq in enumerate(seqs):
#check whether we have modulation commands
freqs = np.unique([entry.frequency for entry in filter(lambda s: isinstance(s,Compiler.Waveform), seq)])
if len(freqs) > 2:
raise Exception("Max 2 frequencies on the same channel allowed.")
if len(freqs) > NUM_NCO:
raise Exception("Max {} frequencies on the same channel allowed.".format(NUM_NCO))
no_freq_cmds = np.allclose(freqs, 0)
phases = [entry.phase for entry in filter(lambda s: isinstance(s,Compiler.Waveform), seq)]
no_phase_cmds = np.allclose(phases, 0)
Expand All @@ -643,7 +650,7 @@ def inject_modulation_cmds(seqs):
#heuristic to insert phase reset before trigger if we have modulation commands
if isinstance(entry, ControlFlow.Wait):
if not ( no_modulation_cmds and (cur_freq == 0) and (cur_phase == 0)):
mod_seq.append(ModulationCommand("RESET_PHASE", 0x3))
mod_seq.append(ModulationCommand("RESET_PHASE", 0xF))
for nco_ind, freq in enumerate(freqs):
mod_seq.append( ModulationCommand("SET_FREQ", nco_ind + 1, frequency = -freq) )
elif isinstance(entry, ControlFlow.Return):
Expand Down Expand Up @@ -1140,7 +1147,6 @@ def start_new_seq():
1.0 /
MAX_WAVEFORM_VALUE) * FID['/chan_2/waveforms'].value.flatten()
instructions = FID['/chan_1/instructions'].value.flatten()
NUM_NCO = 2
freq = np.zeros(NUM_NCO) #radians per timestep
phase = np.zeros(NUM_NCO)
frame = np.zeros(NUM_NCO)
Expand Down Expand Up @@ -1267,7 +1273,6 @@ def start_new_seq():
seqs['ch2'][ct] = mod_ch2

del seqs['mod_phase']

return seqs


Expand Down
4 changes: 2 additions & 2 deletions tests/test_Sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def test_RB_TwoQubitRB(self):
"""
self.set_awg_dir('TwoQubitRB')
np.random.seed(20152606) # set seed for create_RB_seqs()
TwoQubitRB(self.q1,
self.q2,
TwoQubitRB(self.q2,
self.q1,
create_RB_seqs(2, [2, 4, 8, 16, 32],
repeats=16))
self.compare_sequences('RB')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS1/EchoCRLen/EchoCR/EchoCR-APS1.h5
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS1/EchoCRLen/EchoCR/EchoCR-APS2.h5
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS1/EchoCRLen/EchoCR/EchoCR-APS3.h5
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS2/EchoCRLen/EchoCR/EchoCR-APS1.h5
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS2/EchoCRLen/EchoCR/EchoCR-APS2.h5
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS2/EchoCRLen/EchoCR/EchoCR-APS3.h5
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS2/EchoCRLen/EchoCR/EchoCR-APS4.h5
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_data/awg/TestAPS2/EchoCRLen/EchoCR/EchoCR-APS5.h5
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown