Skip to content

Commit

Permalink
Modifications to callable_from_qua (#178)
Browse files Browse the repository at this point in the history
* move callable_from_qua away from addons

* rename folders

* Rename run_local -> callable_from_qua

* add patches to qua classes

* add to import

* Added patches

* patches and transformed to ProgramAddon

* add creation of QuaCallableEventManager

* rename everything to qua_callable

* Add callables attr

* add enable_callable_from_qua

* fix: classmethods

* fixed bugs related to class

* update tests

* Switch order in execute and addons execution

* fix bug

* qua_patches decoupled

* work in progress

* remove "enable_callable"

* get program from scope

---------

Co-authored-by: TheoQM <[email protected]>
  • Loading branch information
nulinspiratie and TheoLaudatQM authored Feb 1, 2024
1 parent be6cf48 commit cc2ef67
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 120 deletions.
22 changes: 15 additions & 7 deletions examples/Callable_from_qua/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager

# 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 *
from qualang_tools.callable_from_qua import *

patch_callable_from_qua()

# Define your run_local functions
@run_local

# Define your callable_from_qua functions
@callable_from_qua
def qua_print(*args):
text = ""
for i in range(0, len(args) - 1, 2):
Expand All @@ -20,14 +21,22 @@ def qua_print(*args):
#####################################
# Open the quantum machine manager
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# from qm.simulate.credentials import create_credentials
# from qm.QuantumMachinesManager import QuantumMachinesManager
#
# qmm = QuantumMachinesManager(
# host="serwan-dd85ae55.dev.quantum-machines.co",
# port=443,
# credentials=create_credentials(),
# )
# Open a quantum machine
qm = qmm.open_qm(config)


###################
# The QUA program #
###################
# Define your QUA program with the run_local functions
# Define your QUA program with the callable_from_qua functions
with program() as prog:
n1 = declare(int)
n2 = declare(int)
Expand All @@ -48,5 +57,4 @@ def qua_print(*args):
I_st.save_all("I")

# Execute the QUA program using the local_run context manager
with prog.local_run(qm):
job = qm.execute(prog)
job = qm.execute(prog)
27 changes: 22 additions & 5 deletions examples/Callable_from_qua/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
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 *
from qualang_tools.callable_from_qua import *

patch_callable_from_qua()
enable_callable_from_qua()

@run_local

@callable_from_qua
def update_offset(QM, channel: str, signal: float):
target = 0.05 # Target voltage in V
signal = -signal * 2**12 / readout_len
Expand All @@ -20,8 +22,24 @@ def update_offset(QM, channel: str, signal: float):


qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
from qm.simulate.credentials import create_credentials
from qm.QuantumMachinesManager import QuantumMachinesManager

qmm = QuantumMachinesManager(
host="serwan-dd85ae55.dev.quantum-machines.co",
port=443,
credentials=create_credentials(),
)

qm = qmm.open_qm(config)

from qcodes.instrument_drivers.qdac import QDAC

qdac = QDAC("qdac", "ASRL4::INSTR")
qdac = convert_qcodes_to_qua(qdac)

qdac.ch17.voltage(0.05)


with program() as prog:
n = declare(int)
Expand All @@ -48,5 +66,4 @@ def live_plot(res_handles):


# Execute the QUA program using the local_run context manager
with prog.local_run(qm, [live_plot]):
job = qm.execute(prog)
job = qm.execute(prog)
13 changes: 8 additions & 5 deletions examples/Callable_from_qua/test_from_python_to_qua.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager
from callable_from_qua import program, run_local
from configuration import *
from qualang_tools.callable_from_qua import *

patch_callable_from_qua()
enable_callable_from_qua()

# Define your run_local functions
@run_local

# Define your callable_from_qua functions
@callable_from_qua
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
@callable_from_qua
def qua_print(*args):
text = ""
for i in range(0, len(args) - 1, 2):
Expand All @@ -25,7 +28,7 @@ def qua_print(*args):
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# Open a quantum machine
qm = qmm.open_qm(config)
# Define your QUA program with the run_local functions
# Define your QUA program with the callable_from_qua functions
with program() as prog:
n = declare(int)
f = declare(int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from qm.QuantumMachinesManager import QuantumMachinesManager
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 *
from qualang_tools.callable_from_qua import *

patch_callable_from_qua()
enable_callable_from_qua()

# Define your run_local functions
@run_local

# Define your callable_from_qua functions
@callable_from_qua
def update_from_python(qm, value, n):
out = float(value * 10000)
f = np.random.randint(1e6, 300e6)
Expand All @@ -17,7 +19,7 @@ def update_from_python(qm, value, n):
print(f"Got {value}, sent {out} and {f}")


@run_local
@callable_from_qua
def qua_print(*args):
text = ""
for i in range(0, len(args) - 1, 2):
Expand All @@ -38,7 +40,7 @@ def qua_print(*args):
# The QUA program #
###################
frequencies = np.arange(15, 250, 0.1) * u.MHz
# Define your QUA program with the run_local functions
# Define your QUA program with the callable_from_qua functions
with program() as prog:
n = declare(int)
f = declare(int)
Expand Down
9 changes: 6 additions & 3 deletions examples/Callable_from_qua/test_live_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
import warnings
from qm import generate_qua_script

from callable_from_qua import program, run_local
from qualang_tools.callable_from_qua import *

patch_callable_from_qua()
enable_callable_from_qua()


warnings.filterwarnings("ignore")


@run_local
@callable_from_qua
def set_lo_freq(q: str, qm, value):
qm.set_output_dc_offset_by_element("AOM", "single", float(value) / 10)
print(f"setting LO to {value} Hz to qubit {q}")


@run_local
@callable_from_qua
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}")
Expand Down
14 changes: 9 additions & 5 deletions examples/Callable_from_qua/test_qua_for.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager
from callable_from_qua import program, run_local
from configuration import *

from qualang_tools.callable_from_qua import *

# Define your run_local functions
@run_local
patch_callable_from_qua()
enable_callable_from_qua()


# Define your callable_from_qua functions
@callable_from_qua
def set_lo_freq(q: str, qm, value):
qm.set_output_dc_offset_by_element("AOM", "single", float(value) / 10)
print(f"setting LO to {value} Hz to qubit {q}")


@run_local
@callable_from_qua
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}")
Expand All @@ -21,7 +25,7 @@ def set_lo_power(q: str, qm, value):
qmm = QuantumMachinesManager(host="172.16.33.101", cluster_name="Cluster_83")
# Open a quantum machine
qm = qmm.open_qm(config)
# Define your QUA program with the run_local functions
# Define your QUA program with the callable_from_qua functions
with program() as prog:
n = declare(int)
n2 = declare(int)
Expand Down
8 changes: 5 additions & 3 deletions examples/Callable_from_qua/test_wide_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import matplotlib.pyplot as plt
import warnings
from qualang_tools.loops import from_array
from qualang_tools.callable_from_qua import *

patch_callable_from_qua()
enable_callable_from_qua()

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

warnings.filterwarnings("ignore")

Expand Down Expand Up @@ -44,7 +46,7 @@ def calibrate_several_LOs(element, lo_frequencies, central_if_frequency):
qm.calibrate_element(element, {lo: (central_if_frequency,)})


@run_local
@callable_from_qua
def set_lo_freq(QM, lo_freq_kHz):
lo_freq_Hz = lo_freq_kHz * u.kHz
print(f"setting LO to {lo_freq_Hz / u.GHz} GHz")
Expand Down
1 change: 1 addition & 0 deletions qualang_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
"multi_user",
"units",
"external_frameworks",
"callable_from_qua",
]
7 changes: 7 additions & 0 deletions qualang_tools/callable_from_qua/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ._callable_from_qua import *
from ._qua_patches import *

__all__ = [
*_callable_from_qua.__all__,
*_qua_patches.__all__,
]
Loading

0 comments on commit cc2ef67

Please sign in to comment.