Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLaudatQM committed Nov 24, 2023
1 parent a152eb7 commit be6cf48
Show file tree
Hide file tree
Showing 11 changed files with 594 additions and 159 deletions.
441 changes: 363 additions & 78 deletions examples/Callable_from_qua/configuration.py

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions examples/Callable_from_qua/configuration_octave.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
x180_sigma = x180_len / 5
x180_amp = 0.35
x180_wf, x180_der_wf = np.array(
drag_gaussian_pulse_waveforms(x180_amp, x180_len, x180_sigma, drag_coef, anharmonicity, AC_stark_detuning)
drag_gaussian_pulse_waveforms(
x180_amp, x180_len, x180_sigma, drag_coef, anharmonicity, AC_stark_detuning
)
)
x180_I_wf = x180_wf
x180_Q_wf = x180_der_wf
Expand All @@ -79,7 +81,9 @@
x90_sigma = x90_len / 5
x90_amp = x180_amp / 2
x90_wf, x90_der_wf = np.array(
drag_gaussian_pulse_waveforms(x90_amp, x90_len, x90_sigma, drag_coef, anharmonicity, AC_stark_detuning)
drag_gaussian_pulse_waveforms(
x90_amp, x90_len, x90_sigma, drag_coef, anharmonicity, AC_stark_detuning
)
)
x90_I_wf = x90_wf
x90_Q_wf = x90_der_wf
Expand All @@ -106,7 +110,9 @@
y180_sigma = y180_len / 5
y180_amp = x180_amp
y180_wf, y180_der_wf = np.array(
drag_gaussian_pulse_waveforms(y180_amp, y180_len, y180_sigma, drag_coef, anharmonicity, AC_stark_detuning)
drag_gaussian_pulse_waveforms(
y180_amp, y180_len, y180_sigma, drag_coef, anharmonicity, AC_stark_detuning
)
)
y180_I_wf = (-1) * y180_der_wf
y180_Q_wf = y180_wf
Expand All @@ -116,7 +122,9 @@
y90_sigma = y90_len / 5
y90_amp = y180_amp / 2
y90_wf, y90_der_wf = np.array(
drag_gaussian_pulse_waveforms(y90_amp, y90_len, y90_sigma, drag_coef, anharmonicity, AC_stark_detuning)
drag_gaussian_pulse_waveforms(
y90_amp, y90_len, y90_sigma, drag_coef, anharmonicity, AC_stark_detuning
)
)
y90_I_wf = (-1) * y90_der_wf
y90_Q_wf = y90_wf
Expand Down Expand Up @@ -153,7 +161,9 @@

opt_weights = False
if opt_weights:
from qualang_tools.config.integration_weights_tools import convert_integration_weights
from qualang_tools.config.integration_weights_tools import (
convert_integration_weights,
)

weights = np.load("optimal_weights.npz")
opt_weights_real = convert_integration_weights(weights["weights_real"])
Expand Down Expand Up @@ -454,4 +464,4 @@
"sine": [(-np.cos(rotation_angle), readout_len)],
},
},
}
}
6 changes: 4 additions & 2 deletions examples/Callable_from_qua/set_octave.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ def octave_declaration(octaves: list = ()):
if octaves[i].name is None:
raise TypeError(f"Please insert the octave name for the {i}'s octave")
if octaves[i].con is None:
raise TypeError(f"Please insert the controller that is connected to the {i}'s octave")
raise TypeError(
f"Please insert the controller that is connected to the {i}'s octave"
)
if octaves[i].ip is None:
raise TypeError(f"Please insert the octave ip for the {i}'s octave")
if octaves[i].port is None:
raise TypeError(f"Please insert the octave port for the {i}'s octave")
octave_config.add_device_info(octaves[i].name, octaves[i].ip, octaves[i].port)

return octave_config
return octave_config
21 changes: 16 additions & 5 deletions examples/Callable_from_qua/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager
from callable_from_qua import program, run_local

# from callable_from_qua import program, run_local # TODO
from qualang_tools.addons.callable_from_qua.callable_from_qua import program, run_local
from configuration import *


# Define your run_local functions
@run_local
def qua_print(*args):
text = ""
for i in range(0, len(args)-1, 2):
for i in range(0, len(args) - 1, 2):
text += f"{args[i]} = {args[i+1]} | "
print(text)


#####################################
# Open Communication with the QOP #
#####################################
# Open the quantum machine manager
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# Open a quantum machine
qm = qmm.open_qm(config)


###################
# The QUA program #
###################
# Define your QUA program with the run_local functions
with program() as prog:
n1 = declare(int)
Expand All @@ -26,16 +37,16 @@ def qua_print(*args):
with for_(n2, 0, n2 < 3, n2 + 1):
measure(
"readout",
"readout_element",
"resonator",
None,
integration.full("constant", I, "out1"),
integration.full("cos", I, "out1"),
)
save(I, I_st)
qua_print("n1", n1, "n2", n2, "I", I)

with stream_processing():
I_st.save_all("I")

# Execute the QUA program using the callable from QUA framework
# Execute the QUA program using the local_run context manager
with prog.local_run(qm):
job = qm.execute(prog)
52 changes: 52 additions & 0 deletions examples/Callable_from_qua/test_feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager
import matplotlib.pyplot as plt
from time import sleep

# from callable_from_qua import program, run_local # TODO
from qualang_tools.addons.callable_from_qua.callable_from_qua import program, run_local
from configuration import *


@run_local
def update_offset(QM, channel: str, signal: float):
target = 0.05 # Target voltage in V
signal = -signal * 2**12 / readout_len
correction = target - signal # Correction to apply
print(f"Set DC offset of channel {channel} to {correction} V (signal = {signal})")
# Can be QDAC or whatever
QM.set_output_dc_offset_by_element(channel, "single", correction)
sleep(0.5)


qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
qm = qmm.open_qm(config)


with program() as prog:
n = declare(int)
n2 = declare(int)
I = declare(fixed)
signal = declare(fixed)
signal_st = declare_stream()
with for_(n2, 0, n2 < 20, n2 + 1):
assign(signal, 0)
with for_(n, 0, n < 2**8, n + 1):
measure("readout", "resonator", None, integration.full("cos", I, "out1"))
assign(signal, signal + (I >> 8))
update_offset(QM=qm, channel="flux_line", signal=signal)
save(signal, signal_st)
with stream_processing():
signal_st.save_all("signal")


def live_plot(res_handles):
data = -res_handles.get("signal").fetch_all()["value"] * 2**12 / readout_len
plt.cla()
plt.plot(data, "ko")
plt.pause(0.01)


# Execute the QUA program using the local_run context manager
with prog.local_run(qm, [live_plot]):
job = qm.execute(prog)
10 changes: 6 additions & 4 deletions examples/Callable_from_qua/test_from_python_to_qua.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
from callable_from_qua import program, run_local
from configuration import *


# Define your run_local functions
@run_local
def update_from_python(qm, value,n):
out = value*100+0.1
def update_from_python(qm, value, n):
out = value * 100 + 0.1
f = np.random.randint(1e6, 300e6)
print(f"Got {value}, sent {out} and {f}")
return out, f


@run_local
def qua_print(*args):
text = ""
for i in range(0, len(args)-1, 2):
for i in range(0, len(args) - 1, 2):
text += f"{args[i]} = {args[i+1]} | "
print(text)

Expand All @@ -32,7 +34,7 @@ def qua_print(*args):
I_st = declare_stream()
with for_(n, 0, n < 10, n + 1):
measure(
"readout"*amp(a),
"readout" * amp(a),
"resonator",
None,
integration.full("cos", I, "out1"),
Expand Down
46 changes: 34 additions & 12 deletions examples/Callable_from_qua/test_from_python_to_qua_inputstreams.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,65 @@
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager
from callable_from_qua import program, run_local
from qualang_tools.loops import from_array

# from callable_from_qua import program, run_local # TODO
from qualang_tools.addons.callable_from_qua.callable_from_qua import program, run_local
from configuration import *


# Define your run_local functions
@run_local
def update_from_python(qm, value,n):
out = float(value*10000)
def update_from_python(qm, value, n):
out = float(value * 10000)
f = np.random.randint(1e6, 300e6)
qm.get_running_job().insert_input_stream('frequency', f)
qm.get_running_job().insert_input_stream('amplitude', out)
qm.get_running_job().insert_input_stream("frequency", f)
qm.get_running_job().insert_input_stream("amplitude", out)
print(f"Got {value}, sent {out} and {f}")


@run_local
def qua_print(*args):
text = ""
for i in range(0, len(args)-1, 2):
for i in range(0, len(args) - 1, 2):
text += f"{args[i]} = {args[i+1]} | "
print(text)


#####################################
# Open Communication with the QOP #
#####################################
# Open the quantum machine manager
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# Open a quantum machine
qm = qmm.open_qm(config)


###################
# The QUA program #
###################
frequencies = np.arange(15, 250, 0.1) * u.MHz
# Define your QUA program with the run_local functions
with program() as prog:
n = declare(int)
f = declare_input_stream(int, name='frequency')
f = declare(int)
f_res = declare_input_stream(int, name="frequency")
I = declare(fixed)
a = declare_input_stream(fixed, name='amplitude')
Q = declare(fixed)
a = declare_input_stream(fixed, name="amplitude")
I_st = declare_stream()
with for_(n, 0, n < 10, n + 1):
with for_(*from_array(f, frequencies)):
# Update the qubit frequency
update_frequency("resonator", f)
# Measure the readout resonator
measure(
"readout"*amp(a),
"readout",
"resonator",
None,
integration.full("cos", I, "out1"),
dual_demod.full("cos", "out1", "sin", "out2", I),
dual_demod.full("minus_sin", "out1", "cos", "out2", Q),
)
# Wait for the resonator to deplete
wait(1000, "resonator")
save(I, I_st)
update_from_python(qm=qm, value=I, n=n)
advance_input_stream(f)
Expand All @@ -48,6 +70,6 @@ def qua_print(*args):
with stream_processing():
I_st.save_all("I")

# Execute the QUA program using the callable from QUA framework
# Execute the QUA program using the local_run context manager
with prog.local_run(qm):
job = qm.execute(prog)
6 changes: 5 additions & 1 deletion examples/Callable_from_qua/test_live_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def set_lo_power(q: str, qm, value):
qm.set_output_dc_offset_by_element("AOM", "single", float(value) / 10)
print(f"setting POWER to {value} Hz to qubit {q}")


# Open the quantum machine manager
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# Open a quantum machine
Expand All @@ -47,15 +48,18 @@ def set_lo_power(q: str, qm, value):

with stream_processing():
I_st.save_all("I")

# Execute the QUA program using the callable from QUA framework
fig = plt.figure()


def live_plot(res_handles):
data = res_handles.get("I").fetch_all()["value"]
plt.cla()
plt.plot(data, "ko")
plt.pause(0.01)


with prog.local_run(qm, funcs=[live_plot]):
job = qm.execute(prog)

Expand Down
2 changes: 2 additions & 0 deletions examples/Callable_from_qua/test_qua_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from callable_from_qua import program, run_local
from configuration import *


# Define your run_local functions
@run_local
def set_lo_freq(q: str, qm, value):
Expand All @@ -15,6 +16,7 @@ def set_lo_power(q: str, qm, value):
qm.set_output_dc_offset_by_element("AOM", "single", float(value) / 10)
print(f"setting POWER to {value} Hz to qubit {q}")


# Open the quantum machine manager
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# Open a quantum machine
Expand Down
Loading

0 comments on commit be6cf48

Please sign in to comment.