-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Baking compatibility with add_compiled (#12)
* Update of the config now optional+ possibility to retrieve baked wfs Baking now allows a simple retrieval of baked waveforms, that can be created according under the constraint of being of a certain length (to ensure compatibility with overriding waveforms with add_compiled feature). Update of original config file no more compulsory, one can now also specify if update of the config should induce an overridable waveform or not * Added example for pre_compile usage + changed the input parameters for b Instead of declaring a matching length constraint, one has now to indicate a baking index that indicates which baked waveform should be overwritten (and ensure it matches its length for overriding it with add_compiled) * Reformat * Added method delete_baked_Op This new method (called using b.delete_baked_Op(qe)) allows the direct removal from the input config of the baking object the associated baked operation and associated waveforms
- Loading branch information
1 parent
eb193a5
commit 4d0f013
Showing
3 changed files
with
353 additions
and
49 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
examples/bakery_examples/pre_compile_compatibility/baked_add_compile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from qualang_tools import baking | ||
from qm.qua import * | ||
from qm.QuantumMachinesManager import QuantumMachinesManager | ||
from config import config | ||
|
||
# Create a first baked waveform, overridable | ||
# and which will be inserted in the config | ||
with baking( | ||
config, padding_method="right", override=True, update_config=True | ||
) as b_template: | ||
samples_I = [0.1, 0.1, 0.2, 0.1, 0.2] | ||
samples_Q = [0.2, 0.2, 0.3, 0.1, 0.0] | ||
b_template.add_Op("Op", "qe1", [samples_I, samples_Q]) | ||
b_template.play("Op", "qe1") | ||
|
||
# Re-open the context manager with either same baking object (b_template) or a new one (b_new) to generate a | ||
# new waveform | ||
# Only important thing is to indicate which baking index it shall use to generate the right name to override waveform | ||
# Note that override parameter and update_config are not relevant anymore (since program is already compiled with a | ||
# previous config, as we only want to retrieve the waveforms out | ||
# of this new baking object | ||
with baking( | ||
config, | ||
padding_method="right", | ||
override=False, | ||
update_config=False, | ||
baking_index=b_template.get_baking_index(), | ||
) as b_new: | ||
samples_I = [0.3, 0.3, 0.4] | ||
samples_Q = [0.0, 0.1, 0.2] | ||
b_new.add_Op("Op", "qe1", [samples_I, samples_Q]) | ||
b_new.play("Op", "qe1") | ||
|
||
print(b_template.get_waveforms_dict()) | ||
print(b_new.get_waveforms_dict()) | ||
qmm = QuantumMachinesManager() | ||
qm = qmm.open_qm(config) | ||
|
||
with program() as prog: | ||
b_template.run() | ||
|
||
pid = qm.queue.compile(prog) | ||
pjob = qm.queue.add_compiled(prog, overrides={b_new.get_waveforms_dict()}) | ||
job = qm.queue.wait_for_execution(pjob) | ||
job.results_handles.wait_for_all_values() |
170 changes: 170 additions & 0 deletions
170
examples/bakery_examples/pre_compile_compatibility/config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import numpy as np | ||
|
||
pulse_len = 80 | ||
readout_len = 400 | ||
qubit_IF = 50e6 | ||
rr_IF = 50e6 | ||
qubit_LO = 6.345e9 | ||
rr_LO = 4.755e9 | ||
|
||
|
||
def gauss(amplitude, mu, sigma, length): | ||
t = np.linspace(-length / 2, length / 2, length) | ||
gauss_wave = amplitude * np.exp(-((t - mu) ** 2) / (2 * sigma ** 2)) | ||
return [float(x) for x in gauss_wave] | ||
|
||
|
||
def IQ_imbalance(g, phi): | ||
c = np.cos(phi) | ||
s = np.sin(phi) | ||
N = 1 / ((1 - g ** 2) * (2 * c ** 2 - 1)) | ||
return [float(N * x) for x in [(1 - g) * c, (1 + g) * s, (1 - g) * s, (1 + g) * c]] | ||
|
||
|
||
gauss_pulse = gauss(0.2, 0, 20, pulse_len) | ||
|
||
config = { | ||
"version": 1, | ||
"controllers": { | ||
"con1": { | ||
"type": "opx1", | ||
"analog_outputs": { | ||
1: {"offset": +0.0}, # qe-I | ||
2: {"offset": +0.0}, # qe-Q | ||
3: {"offset": +0.0}, # rr-I | ||
4: {"offset": +0.0}, # rr-Q | ||
}, | ||
"digital_outputs": { | ||
1: {}, | ||
}, | ||
"analog_inputs": { | ||
1: {"offset": +0.0}, | ||
}, | ||
} | ||
}, | ||
"elements": { | ||
"qe1": { | ||
"mixInputs": { | ||
"I": ("con1", 1), | ||
"Q": ("con1", 2), | ||
"lo_frequency": qubit_LO, | ||
"mixer": "mixer_qubit", | ||
}, | ||
"intermediate_frequency": qubit_IF, | ||
"operations": { | ||
"I": "IPulse", | ||
"X/2": "X/2Pulse", | ||
"X": "XPulse", | ||
"-X/2": "-X/2Pulse", | ||
"Y/2": "Y/2Pulse", | ||
"Y": "YPulse", | ||
"-Y/2": "-Y/2Pulse", | ||
}, | ||
}, | ||
"rr": { | ||
"mixInputs": { | ||
"I": ("con1", 3), | ||
"Q": ("con1", 4), | ||
"lo_frequency": rr_LO, | ||
"mixer": "mixer_RR", | ||
}, | ||
"intermediate_frequency": rr_IF, | ||
"operations": { | ||
"readout": "readout_pulse", | ||
}, | ||
"outputs": {"out1": ("con1", 1)}, | ||
"time_of_flight": 28, | ||
"smearing": 0, | ||
}, | ||
}, | ||
"pulses": { | ||
"constPulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "gauss_wf", "Q": "gauss_wf"}, | ||
}, | ||
"IPulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "zero_wf", "Q": "zero_wf"}, | ||
}, | ||
"XPulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "const_wf", "Q": "zero_wf"}, | ||
}, | ||
"X/2Pulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "pi/2_wf", "Q": "zero_wf"}, | ||
}, | ||
"-X/2Pulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "-pi/2_wf", "Q": "zero_wf"}, | ||
}, | ||
"YPulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "zero_wf", "Q": "pi_wf"}, | ||
}, | ||
"Y/2Pulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "zero_wf", "Q": "pi/2_wf"}, | ||
}, | ||
"-Y/2Pulse": { | ||
"operation": "control", | ||
"length": pulse_len, | ||
"waveforms": {"I": "zero_wf", "Q": "-pi/2_wf"}, | ||
}, | ||
"readout_pulse": { | ||
"operation": "measurement", | ||
"length": readout_len, | ||
"waveforms": {"I": "readout_wf", "Q": "zero_wf"}, | ||
"integration_weights": { | ||
"integW1": "integW1", | ||
"integW2": "integW2", | ||
}, | ||
"digital_marker": "ON", | ||
}, | ||
}, | ||
"waveforms": { | ||
"const_wf": {"type": "constant", "sample": 0.2}, | ||
"gauss_wf": {"type": "arbitrary", "samples": gauss_pulse}, | ||
"pi_wf": {"type": "arbitrary", "samples": gauss(0.2, 0, 12, pulse_len)}, | ||
"-pi/2_wf": {"type": "arbitrary", "samples": gauss(-0.1, 0, 12, pulse_len)}, | ||
"pi/2_wf": {"type": "arbitrary", "samples": gauss(0.1, 0, 12, pulse_len)}, | ||
"zero_wf": {"type": "constant", "sample": 0.0}, | ||
"readout_wf": {"type": "constant", "sample": 0.3}, | ||
}, | ||
"digital_waveforms": { | ||
"ON": {"samples": [(1, 0)]}, | ||
}, | ||
"integration_weights": { | ||
"integW1": { | ||
"cosine": [1.0] * int(readout_len / 4), | ||
"sine": [0.0] * int(readout_len / 4), | ||
}, | ||
"integW2": { | ||
"cosine": [0.0] * int(readout_len / 4), | ||
"sine": [1.0] * int(readout_len / 4), | ||
}, | ||
}, | ||
"mixers": { | ||
"mixer_qubit": [ | ||
{ | ||
"intermediate_frequency": qubit_IF, | ||
"lo_frequency": qubit_LO, | ||
"correction": IQ_imbalance(0.0, 0.0), | ||
} | ||
], | ||
"mixer_RR": [ | ||
{ | ||
"intermediate_frequency": rr_IF, | ||
"lo_frequency": rr_LO, | ||
"correction": IQ_imbalance(0.0, 0.0), | ||
} | ||
], | ||
}, | ||
} |
Oops, something went wrong.