Skip to content

Commit

Permalink
Merge pull request #65 from BBN-Q/feature/meta-output
Browse files Browse the repository at this point in the history
Add basic meta program output
  • Loading branch information
caryan committed Aug 4, 2016
2 parents baa7d4d + ae0fa7c commit 4d1fa25
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 61 deletions.
36 changes: 28 additions & 8 deletions QGL/BasicSequences/CR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..Compiler import compile_to_hardware
from ..ChannelLibrary import EdgeFactory
from ..PulseSequencePlotter import plot_pulse_files
from .helpers import create_cal_seqs
from .helpers import create_cal_seqs, time_descriptor, cal_descriptor


def PiRabi(controlQ,
Expand All @@ -22,7 +22,7 @@ def PiRabi(controlQ,
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
amp : amplitude of the CR pulse
phase : phase of the CR pulse (rad)
showPlot : whether to plot (boolean)
"""
Expand All @@ -37,7 +37,9 @@ def PiRabi(controlQ,
MEAS(targetQ)*MEAS(controlQ)] for l in lengths] + \
create_cal_seqs([targetQ,controlQ], calRepeats, measChans=(targetQ,controlQ))

fileNames = compile_to_hardware(seqs, 'PiRabi/PiRabi')
fileNames = compile_to_hardware(seqs, 'PiRabi/PiRabi',
axis_descriptor=time_descriptor(lengths),
cal_descriptor=cal_descriptor((controlQ, targetQ), calRepeats, len(lengths)+1))
print(fileNames)

if showPlot:
Expand All @@ -61,7 +63,7 @@ def EchoCRLen(controlQ,
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
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)
Expand All @@ -70,7 +72,9 @@ def EchoCRLen(controlQ,
for l in lengths]+ [[X(controlQ)] + echoCR(controlQ, targetQ, length=l, phase= phase, riseFall=riseFall) + [X(controlQ), MEAS(targetQ)*MEAS(controlQ)]\
for l in lengths] + create_cal_seqs((targetQ,controlQ), calRepeats, measChans=(targetQ,controlQ))

fileNames = compile_to_hardware(seqs, 'EchoCR/EchoCR')
fileNames = compile_to_hardware(seqs, 'EchoCR/EchoCR',
axis_descriptor=time_descriptor(lengths),
cal_descriptor=cal_descriptor((controlQ, targetQ), calRepeats, len(lengths)+1))
print(fileNames)

if showPlot:
Expand All @@ -94,7 +98,7 @@ def EchoCRPhase(controlQ,
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
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)
Expand All @@ -103,7 +107,15 @@ def EchoCRPhase(controlQ,
for ph in phases]+[[X(controlQ)] + echoCR(controlQ, targetQ, length=length, phase= ph, riseFall = riseFall) + [X90(targetQ)*X(controlQ), MEAS(targetQ)*MEAS(controlQ)]\
for ph in phases]+create_cal_seqs((targetQ,controlQ), calRepeats, measChans=(targetQ,controlQ))

fileNames = compile_to_hardware(seqs, 'EchoCR/EchoCR')
axis_descriptor = [{
'name': 'phase',
'unit': 'radians',
'points': list(phases)
}]

fileNames = compile_to_hardware(seqs, 'EchoCR/EchoCR',
axis_descriptor=axis_descriptor,
cal_descriptor=cal_descriptor((controlQ, targetQ), calRepeats, len(phases)+1))
print(fileNames)

if showPlot:
Expand Down Expand Up @@ -136,7 +148,15 @@ def EchoCRAmp(controlQ,
for a in amps]+ [[X(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))

fileNames = compile_to_hardware(seqs, 'EchoCR/EchoCR')
axis_descriptor = [{
'name': 'amplitude',
'unit': None,
'points': list(amps)
}]

fileNames = compile_to_hardware(seqs, 'EchoCR/EchoCR',
axis_descriptor=axis_descriptor,
cal_descriptor=cal_descriptor((controlQ, targetQ), calRepeats, len(amps)+1))
print(fileNames)

if showPlot:
Expand Down
16 changes: 10 additions & 6 deletions QGL/BasicSequences/Decoupling.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from ..PulsePrimitives import *
from ..Compiler import compile_to_hardware
from ..PulseSequencePlotter import plot_pulse_files
from .helpers import create_cal_seqs
from .helpers import create_cal_seqs, time_descriptor, cal_descriptor


def HahnEcho(qubit, pulseSpacings, periods=0, calRepeats=2, showPlot=False):
"""
A single pulse Hahn echo with variable phase of second pi/2 pulse.
A single pulse Hahn echo with variable phase of second pi/2 pulse.
Parameters
----------
qubit : logical channel to implement sequence (LogicalChannel)
qubit : logical channel to implement sequence (LogicalChannel)
pulseSpacings : pulse spacings to sweep over; the t in 90-t-180-t-180 (iterable)
periods: number of artificial oscillations
calRepeats : how many times to repeat calibration scalings (default 2)
Expand All @@ -28,7 +28,9 @@ def HahnEcho(qubit, pulseSpacings, periods=0, calRepeats=2, showPlot=False):
#Tack on the calibration scalings
seqs += create_cal_seqs((qubit, ), calRepeats)

fileNames = compile_to_hardware(seqs, 'Echo/Echo')
fileNames = compile_to_hardware(seqs, 'Echo/Echo',
axis_descriptor=time_descriptor(2 * pulseSpacings),
cal_descriptor=cal_descriptor((qubit,), calRepeats, len(pulseSpacings)+1))
print(fileNames)

if showPlot:
Expand All @@ -42,7 +44,7 @@ def CPMG(qubit, numPulses, pulseSpacing, calRepeats=2, showPlot=False):
Parameters
----------
qubit : logical channel to implement sequence (LogicalChannel)
qubit : logical channel to implement sequence (LogicalChannel)
numPulses : number of 180 pulses; should be even (iterable)
pulseSpacing : spacing between the 180's (seconds)
calRepeats : how many times to repeat calibration scalings (default 2)
Expand All @@ -63,7 +65,9 @@ def CPMG(qubit, numPulses, pulseSpacing, calRepeats=2, showPlot=False):
#Tack on the calibration scalings
seqs += create_cal_seqs((qubit, ), calRepeats)

fileNames = compile_to_hardware(seqs, 'CPMG/CPMG')
fileNames = compile_to_hardware(seqs, 'CPMG/CPMG',
axis_descriptor=time_descriptor(pulseSpacing * numPulses),
cal_descriptor=cal_descriptor((qubit,), calRepeats, len(numPulses)+1))
print(fileNames)

if showPlot:
Expand Down
42 changes: 36 additions & 6 deletions QGL/BasicSequences/Rabi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..Compiler import compile_to_hardware
from ..PulseSequencePlotter import plot_pulse_files
import QGL.PulseShapes
from .helpers import create_cal_seqs
from .helpers import create_cal_seqs, time_descriptor, cal_descriptor
from functools import reduce


Expand All @@ -24,7 +24,13 @@ def RabiAmp(qubit, amps, phase=0, showPlot=False):
"""
seqs = [[Utheta(qubit, amp=amp, phase=phase), MEAS(qubit)] for amp in amps]

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi')
axis_descriptor = [{
'name': 'amplitude',
'unit': None,
'points': list(amps)
}]

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi', axis_descriptor=axis_descriptor)
print(fileNames)

if showPlot:
Expand Down Expand Up @@ -59,7 +65,8 @@ def RabiWidth(qubit,
phase=phase,
shapeFun=shapeFun), MEAS(qubit)] for l in widths]

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi')
fileNames = compile_to_hardware(seqs, 'Rabi/Rabi',
axis_descriptor=time_descriptor(widths))
print(fileNames)

if showPlot:
Expand Down Expand Up @@ -101,7 +108,15 @@ def RabiAmp_NQubits(qubits,
if docals:
seqs += create_cal_seqs(qubits, calRepeats, measChans=measChans)

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi')
axis_descriptor = [{
'name': 'amplitude',
'unit': None,
'points': list(amps)
}]

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi',
axis_descriptor=axis_descriptor,
cal_descriptor=cal_descriptor(qubits, calRepeats, len(amps)+1))
print(fileNames)

if showPlot:
Expand All @@ -127,7 +142,13 @@ def RabiAmpPi(qubit, mqubit, amps, phase=0, showPlot=False):
seqs = [[X(mqubit), Utheta(qubit, amp=amp, phase=phase), X(mqubit),
MEAS(mqubit)] for amp in amps]

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi')
axis_descriptor = [{
'name': 'amplitude',
'unit': None,
'points': list(amps)
}]

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi', axis_descriptor=axis_descriptor)
print(fileNames)

if showPlot:
Expand All @@ -140,6 +161,13 @@ def SingleShot(qubit, showPlot=False):
2-segment sequence with qubit prepared in |0> and |1>, useful for single-shot fidelity measurements and kernel calibration
"""
seqs = [[Id(qubit), MEAS(qubit)], [X(qubit), MEAS(qubit)]]

axis_descriptor = {
'name': 'state',
'unit': None,
'points': [0, 1]
}

filenames = compile_to_hardware(seqs, 'SingleShot/SingleShot')
print(filenames)

Expand Down Expand Up @@ -181,7 +209,9 @@ def Swap(qubit, mqubit, delays, showPlot=False):
(mqubit, qubit), 2,
measChans=(mqubit, qubit))

fileNames = compile_to_hardware(seqs, 'Rabi/Rabi')
fileNames = compile_to_hardware(seqs, 'Rabi/Rabi',
time_descriptor=time_descriptor(delays),
cal_descriptor=cal_descriptor((mqubit, qubit), 2, len(delays)+1))
print(fileNames)

if showPlot:
Expand Down
72 changes: 36 additions & 36 deletions QGL/BasicSequences/T1T2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..Compiler import compile_to_hardware
from ..PulseSequencePlotter import plot_pulse_files
from scipy.constants import pi
from .helpers import create_cal_seqs
from .helpers import create_cal_seqs, time_descriptor, cal_descriptor


def InversionRecovery(qubit,
Expand All @@ -11,30 +11,30 @@ def InversionRecovery(qubit,
calRepeats=2,
suffix=False):
"""
Inversion recovery experiment to measure qubit T1
Parameters
----------
qubit : logical channel to implement sequence (LogicalChannel)
delays : delays after inversion before measurement (iterable; seconds)
showPlot : whether to plot (boolean)
calRepeats : how many repetitions of calibration pulses (int)
Returns
-------
plotHandle : handle to plot window to prevent destruction
"""
Inversion recovery experiment to measure qubit T1
Parameters
----------
qubit : logical channel to implement sequence (LogicalChannel)
delays : delays after inversion before measurement (iterable; seconds)
showPlot : whether to plot (boolean)
calRepeats : how many repetitions of calibration pulses (int)
Returns
-------
plotHandle : handle to plot window to prevent destruction
"""

#Create the basic sequences
seqs = [[X(qubit), Id(qubit, d), MEAS(qubit)] for d in delays]

#Tack on the calibration scalings
seqs += create_cal_seqs((qubit, ), calRepeats)

fileNames = compile_to_hardware(seqs, 'T1' +
('_' + qubit.label) * suffix + '/T1' +
('_' + qubit.label) * suffix)
fileNames = compile_to_hardware(seqs,
'T1' + ('_' + qubit.label) * suffix + '/T1' + ('_' + qubit.label) * suffix,
axis_descriptor=time_descriptor(delays),
cal_descriptor=cal_descriptor((qubit,), calRepeats, len(delays)+1))
print(fileNames)

if showPlot:
Expand All @@ -48,21 +48,20 @@ def Ramsey(qubit,
calRepeats=2,
suffix=False):
"""
Variable pulse spacing Ramsey (pi/2 - tau - pi/2) with optional TPPI.
Parameters
----------
qubit : logical channel to implement sequence (LogicalChannel)
pulseSpacings : pulse spacings (iterable; seconds)
TPPIFreq : frequency for TPPI phase updates of second Ramsey pulse (Hz)
showPlot : whether to plot (boolean)
calRepeats : how many repetitions of calibration pulses (int)
Returns
-------
plotHandle : handle to plot window to prevent destruction
"""
Variable pulse spacing Ramsey (pi/2 - tau - pi/2) with optional TPPI.
Parameters
----------
qubit : logical channel to implement sequence (LogicalChannel)
pulseSpacings : pulse spacings (iterable; seconds)
TPPIFreq : frequency for TPPI phase updates of second Ramsey pulse (Hz)
showPlot : whether to plot (boolean)
calRepeats : how many repetitions of calibration pulses (int)
Returns
-------
plotHandle : handle to plot window to prevent destruction
"""

#Create the phases for the TPPI
phases = 2 * pi * TPPIFreq * pulseSpacings
Expand All @@ -74,9 +73,10 @@ def Ramsey(qubit,
#Tack on the calibration scalings
seqs += create_cal_seqs((qubit, ), calRepeats)

fileNames = compile_to_hardware(seqs, 'Ramsey' +
('_' + qubit.label) * suffix + '/Ramsey' +
('_' + qubit.label) * suffix)
fileNames = compile_to_hardware(seqs,
'Ramsey' + ('_' + qubit.label) * suffix + '/Ramsey' + ('_' + qubit.label) * suffix,
axis_descriptor=time_descriptor(pulseSpacings),
cal_descriptor=cal_descriptor((qubit,), calRepeats, len(pulseSpacings)+1))
print(fileNames)

if showPlot:
Expand Down
28 changes: 28 additions & 0 deletions QGL/BasicSequences/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding=utf-8

from itertools import product
import operator
from ..PulsePrimitives import Id, X, MEAS
Expand Down Expand Up @@ -28,3 +30,29 @@ def create_cal_seqs(qubits, numRepeats, measChans=None, waitcmp=False):
measBlock = reduce(operator.mul, [MEAS(q) for q in qubits])
return [[seq, measBlock, qwait('CMP')] if waitcmp else [seq, measBlock]
for seq in calSeqs]

def cal_descriptor(qubits, numRepeats, startIdx):
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 = {}
cal_range = range(startIdx, startIdx + numRepeats*len(state_set))
for ct, state in enumerate(state_set):
descriptor[state] = list(cal_range[ct*numRepeats : (ct+1)*numRepeats])
return descriptor

def time_descriptor(times, desired_units="us"):
if desired_units == "s":
scale = 1
elif desired_units == "ms":
scale = 1e3
elif desired_units == "us" or desired_units == u"μs":
scale = 1e6
elif desired_units == "ns":
scale = 1e9
axis_descriptor = [{
'name': 'time',
'unit': desired_units,
'points': list(scale * times)
}]
return axis_descriptor
Loading

0 comments on commit 4d1fa25

Please sign in to comment.