Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ristè committed Jan 4, 2019
2 parents e5861a1 + 15dc15f commit 145f03d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 18 deletions.
45 changes: 39 additions & 6 deletions QGL/BasicSequences/CR.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..PulseSequencePlotter import plot_pulse_files
from .helpers import create_cal_seqs, delay_descriptor, cal_descriptor
import numpy as np
from itertools import product

def PiRabi(controlQ,
targetQ,
Expand Down Expand Up @@ -56,7 +57,7 @@ def EchoCRLen(controlQ,
amp=1,
phase=0,
calRepeats=2,
showPlot=False):
showPlot=False, canc_amp=0, canc_phase=np.pi/2):
"""
Variable length CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.
Expand All @@ -72,11 +73,11 @@ def EchoCRLen(controlQ,
showPlot : whether to plot (boolean)
"""
seqs = [[Id(controlQ),
echoCR(controlQ, targetQ, length=l, phase=phase, amp=amp, riseFall=riseFall),
echoCR(controlQ, targetQ, length=l, phase=phase, amp=amp, riseFall=riseFall, canc_amp=canc_amp, canc_phase=canc_phase),
Id(controlQ),
MEAS(targetQ)*MEAS(controlQ)] for l in lengths] + \
[[X(controlQ),
echoCR(controlQ, targetQ, length=l, phase= phase, amp=amp, riseFall=riseFall),
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((controlQ,targetQ), calRepeats, measChans=(targetQ,controlQ))
Expand All @@ -100,7 +101,9 @@ def EchoCRPhase(controlQ,
amp=1,
length=100e-9,
calRepeats=2,
showPlot=False):
showPlot=False,
canc_amp=0,
canc_phase=np.pi/2):
"""
Variable phase CX experiment, with echo pulse sandwiched between two CR opposite-phase pulses.
Expand All @@ -116,11 +119,11 @@ def EchoCRPhase(controlQ,
showPlot : whether to plot (boolean)
"""
seqs = [[Id(controlQ),
echoCR(controlQ, targetQ, length=length, phase=ph, amp=amp, riseFall=riseFall),
echoCR(controlQ, targetQ, length=length, phase=ph, amp=amp, riseFall=riseFall, canc_amp=canc_amp, canc_phase=canc_phase),
X90(targetQ)*Id(controlQ),
MEAS(targetQ)*MEAS(controlQ)] for ph in phases] + \
[[X(controlQ),
echoCR(controlQ, targetQ, length=length, phase= ph, amp=amp, riseFall = riseFall),
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((controlQ, targetQ), calRepeats, measChans=(targetQ,controlQ))
Expand Down Expand Up @@ -192,3 +195,33 @@ def EchoCRAmp(controlQ,
plot_pulse_files(metafile)

return metafile

def CRtomo_seq(controlQ, targetQ, lengths, ph, amp=0.8, riseFall=20e-9):
"""
Variable length CX experiment, for Hamiltonian tomography.
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)
ph : phase of the CR pulse (rad)
"""
CRchan = ChannelLibraries.EdgeFactory(controlQ, targetQ)
tomo_pulses = [Y90m, X90, Id]
seqs = [[Id(controlQ),
flat_top_gaussian(CRchan, amp=amp, riseFall=riseFall, length=l, phase=ph, label="CR"),
Id(controlQ)*tomo_pulse(targetQ),
MEAS(targetQ)] for l,tomo_pulse in product(lengths, tomo_pulses)] + \
[[X(controlQ),
flat_top_gaussian(CRchan, amp=amp, riseFall=riseFall, length=l, phase=ph, label="CR"),
X(controlQ)*tomo_pulse(targetQ),
MEAS(targetQ)] for l,tomo_pulse in product(lengths, tomo_pulses)] + \
create_cal_seqs((targetQ,), 2,)
metafile = compile_to_hardware(seqs, 'CR/CR',
axis_descriptor=[
delay_descriptor(np.concatenate((np.repeat(lengths,3), np.repeat(lengths,3)))),
cal_descriptor((targetQ,), 2)
])
return metafile
2 changes: 1 addition & 1 deletion QGL/BasicSequences/Rabi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def RabiAmp_NQubits(qubits,
if measChans is None:
measChans = qubits

measBlock = reduce(operator.mul, [MEAS(q) for q in qubits])
measBlock = reduce(operator.mul, [MEAS(q) for q in measChans])
seqs = [[reduce(operator.mul,
[Utheta(q, amp=amp, phase=phase) for q in qubits]),
measBlock] for amp in amps]
Expand Down
3 changes: 1 addition & 2 deletions QGL/BasicSequences/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def create_cal_seqs(qubits, numRepeats, measChans=None, waitcmp=False, delay=Non
[cal_seq.append(qwait(kind='CMP')) for cal_seq in full_cal_seqs]
return full_cal_seqs

def cal_descriptor(qubits, numRepeats, partition=2):
states = ['0', '1']
def cal_descriptor(qubits, numRepeats, partition=2, states = ['0', '1']):
# generate state set in same order as we do above in create_cal_seqs()
state_set = [reduce(operator.add, s) for s in product(states, repeat=len(qubits))]
descriptor = {
Expand Down
16 changes: 11 additions & 5 deletions QGL/Compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def compile_to_hardware(seqs,

# convert to hardware formats
# files = {}
awg_metas = {}
for awgName, data in awgData.items():
# create the target folder if it does not exist
targetFolder = os.path.split(os.path.normpath(os.path.join(
Expand All @@ -429,15 +430,16 @@ def compile_to_hardware(seqs,
fullFileName = os.path.normpath(os.path.join(
config.AWGDir, fileName + '-' + awgName + suffix + data[
'seqFileExt']))
data['translator'].write_sequence_file(data, fullFileName)
new_meta = data['translator'].write_sequence_file(data, fullFileName)
if new_meta:
awg_metas[awgName] = new_meta

# Allow for per channel and per AWG seq files
if awgName in label_to_inst:
if awgName in label_to_chan:
files[label_to_inst[awgName]][label_to_chan[awgName]] = fullFileName
else:
files[awgName] = fullFileName

# generate TDM sequences FIXME: what's the best way to identify the need for a TDM seq.? Support for single TDM
if tdm_seq and 'APS2Pattern' in [wire.translator for wire in physWires]:
aps2tdm_module = import_module('QGL.drivers.APS2Pattern') # this is redundant with above
Expand All @@ -447,6 +449,10 @@ def compile_to_hardware(seqs,
'seqFileExt']))
aps2tdm_module.write_tdm_seq(tdm_instr, files['TDM'])

if extra_meta:
extra_meta.update(awg_metas)
else:
extra_meta = awg_metas
# create meta output
if not axis_descriptor:
axis_descriptor = [{
Expand All @@ -467,7 +473,7 @@ def compile_to_hardware(seqs,
'receivers': receiver_measurements
}
if extra_meta:
meta.update(extra_meta)
meta.update({'extra_meta': extra_meta})
metafilepath = os.path.join(config.AWGDir, fileName + '-meta.json')
with open(metafilepath, 'w') as FID:
json.dump(meta, FID, indent=2, sort_keys=True)
Expand Down Expand Up @@ -666,7 +672,7 @@ def __init__(self, pulse=None):
self.frameChange = 0
self.isTimeAmp = False
self.frequency = 0

self.logicalChan = ""
self.maddr = (-1, 0)
else:
self.label = pulse.label
Expand All @@ -677,7 +683,7 @@ def __init__(self, pulse=None):
self.frameChange = pulse.frameChange
self.isTimeAmp = pulse.isTimeAmp
self.frequency = pulse.frequency

self.logicalChan = pulse.channel
self.maddr = pulse.maddr

def __repr__(self):
Expand Down
21 changes: 19 additions & 2 deletions QGL/PulsePrimitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def echoCR(controlQ,
phase=0,
length=200e-9,
riseFall=20e-9,
lastPi=True):
lastPi=True, canc_amp = 0.0, canc_phase=np.pi/2):
"""
An echoed CR pulse. Used for calibration of CR gate
"""
Expand All @@ -668,6 +668,19 @@ def echoCR(controlQ,
length=length,
phase=phase + np.pi,
label="echoCR_second_half")]
if canc_amp != 0:
seq[0]*=flat_top_gaussian(targetQ,
amp=canc_amp,
riseFall=riseFall,
length=length,
phase=canc_phase,
label="cancCR_first_half")
seq[2]*=flat_top_gaussian(targetQ,
amp=canc_amp,
riseFall=riseFall,
length=length,
phase=canc_phase + np.pi,
label="cancCR_second_half")
if lastPi:
seq += [X(controlQ)]
return CompoundGate(seq)
Expand All @@ -679,12 +692,16 @@ def ZX90_CR(controlQ, targetQ, **kwargs):
"""
CRchan = ChannelLibraries.EdgeFactory(controlQ, targetQ)
params = overrideDefaults(CRchan, kwargs)
canc_amp = params['canc_amp'] if 'canc_amp' in params else 0
canc_phase = params['canc_phase'] if 'canc_phase' in params else 0
return echoCR(controlQ,
targetQ,
amp=params['amp'],
phase=params['phase'],
length=params['length'],
riseFall=params['riseFall'])
riseFall=params['riseFall'],
canc_phase=canc_phase,
canc_amp=canc_amp)


def CNOT_CR(controlQ, targetQ, **kwargs):
Expand Down
9 changes: 8 additions & 1 deletion QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,14 @@ def write_sequence_file(awgData, fileName):
chanStr = '/chan_{0}'.format(chanct + 1)
chanGroup = FID.create_group(chanStr)
#Write the waveformLib to file
FID.create_dataset(chanStr + '/waveforms', data=wfInfo[chanct][0])
if wfInfo[chanct][0].size == 0:
#If there are no waveforms, ensure that there is some element
#so that the waveform group gets written to file.
#TODO: Fix this in libaps2
data = np.array([0], dtype=np.uint16)
else:
data = wfInfo[chanct][0]
FID.create_dataset(chanStr + '/waveforms', data=data)

#Write the instructions to channel 1
if np.mod(chanct, 2) == 0:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ The QGL config file will be created the first time you run `import QGL` or `from
* Bokeh 0.11
* networkx
* iPython/Jupyter 4.0 (only for Jupyter notebooks)
* ruamel_yaml
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"networkx >= 1.11",
"future >= 0.16",
"watchdog >= 0.8.3",
"bokeh >= 0.11"
"bokeh >= 0.11",
"ruamel_yaml >= 0.11.14"
],
extras_require={"gst": "pygsti>0.9.4"}
)

0 comments on commit 145f03d

Please sign in to comment.