qilimanjaro-tech / qililab

Qililab is a generic and scalable quantum control library used for fast characterization and calibration of quantum chips. Qililab also offers the ability to execute high-level quantum algorithms with your quantum hardware.
Apache License 2.0
30 stars 2 forks source link

[BUG] vs_flux() Qprogram throwing error #771

Closed OscarQili closed 2 days ago

OscarQili commented 1 month ago

Expected behavior

I compile and then run the qprogram without crashes

Actual behavior

I compile and run the qprogram vs_flux() and it crashes and throws one error the first time. If I launch it again it throws a different error (I get the same error every subsequent run)

Additional information

I first found the error when writing new code including vs_flux() I then launched flux_vs_flux_xtalk_qblox() which contains this function and has worked before, and get the same issue

I'm using the branch qhc-622 of qililab and main of qilitools

Source code

LabScripts/Personal_folders/Oscar/Qblox/flux_vs_flux_pulse_Qblox.ipynb

readout_bus = "readout"
flux1_bus = "flux_ql"
flux2_bus = "flux_cx"
flux3_bus = "flux_cz"
flux4_bus = "flux_qr"

# Biasing:
DC_1_BIAS = 0
DC_2_BIAS = 0

BIAS_1_START = 0.2
BIAS_1_STOP = 0.4
BIAS_1_STEP = 0.1

BIAS_2_START = 0.2
BIAS_2_STOP = 0.5
BIAS_2_STEP = 0.1

PRECEDE_DURATION = 2000
RELAXATION_TIME = 2000

# QProgram:
AVERAGES = 1
RESON_DUR = 2000
RESON_AMP = 0.1

XTALK = np.eye(4) #np.array([[1, 0.1, 0.1], [0.1, 1, 0.1], [0.1, 0.1, 1]])
PARSING_FLUX = [0, 1]

amplitudes1 = np.arange(BIAS_1_START, BIAS_1_STOP + BIAS_1_STEP / 2, BIAS_1_STEP)
amplitudes2 = np.arange(BIAS_2_START, BIAS_2_STOP + BIAS_2_STEP / 2, BIAS_2_STEP)

qprogram_list = flux_vs_flux_xtalk_qblox(
    flux_1_start=BIAS_1_START,
    flux_1_stop=BIAS_1_STOP,
    flux_1_step=BIAS_1_STEP,
    flux_2_start=BIAS_2_START,
    flux_2_stop=BIAS_2_STOP,
    flux_2_step=BIAS_2_STEP,
    precede_duration=PRECEDE_DURATION,
    r_amp=RESON_AMP,
    r_duration=RESON_DUR,
    xtalk=XTALK,
    parsing_flux=PARSING_FLUX,
    averages=AVERAGES,
    relaxation_time=RELAXATION_TIME,
    debug=False,)

from qilitools import create_directories

stream_array = ql.stream_results(
    shape=(len(amplitudes1), len(amplitudes2), 2),
    loops={"amplitudes1": amplitudes1, 
           "amplitudes2": amplitudes2},
    path=create_directories("/home/jupytershared/data/") + "results.h5",
    )

for i, qprogram in enumerate(qprogram_list):
    results = platform.execute_qprogram(
        qprogram=qprogram, bus_mapping={"readout": readout_bus, "flux_1": flux1_bus, "flux_2": flux2_bus, "flux_3": flux3_bus, "flux_4": flux4_bus}
    )
    stream_array[:,i,:] = results.results["readout_2"][0].array.T

Tracebacks

/home/opihl/qililab/src/qililab/qprogram/quantum_machines_compiler.py:231: RuntimeWarning: invalid value encountered in scalar divide
np.arange(loop.start, loop.stop + loop.step / 2, loop.step)

{
    "name": "ValueError",
    "message": "arange: cannot compute length",
    "stack": "---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 12
      3 stream_array = ql.stream_results(
      4     shape=(len(amplitudes1), len(amplitudes2), 2),
      5     loops={\"amplitudes1\": amplitudes1, 
      6            \"amplitudes2\": amplitudes2},
      7     path=create_directories(\"/home/jupytershared/data/\") + \"results.h5\",
      8     )
     11 for i, qprogram in enumerate(qprogram_list):
---> 12     results = platform.execute_qprogram(
     13         qprogram=qprogram, bus_mapping={\"readout\": readout_bus, \"flux_1\": flux1_bus, \"flux_2\": flux2_bus, \"flux_3\": flux3_bus, \"flux_4\": flux4_bus}
     14     )
     15     stream_array[:,i,:] = results.results[\"readout_2\"][0].array.T

File ~/qililab/src/qililab/platform/platform.py:636, in Platform.execute_qprogram(self, qprogram, bus_mapping, calibration, debug)
    630     cluster: QuantumMachinesCluster = instruments.pop()  # type: ignore[assignment]
    631     threshold_rotations = {
    632         bus.alias: float(bus.get_parameter(parameter=Parameter.THRESHOLD_ROTATION))
    633         for bus in buses
    634         if isinstance(bus.system_control, ReadoutSystemControl)
    635     }  # type: ignore
--> 636     return self._execute_qprogram_with_quantum_machines(
    637         cluster=cluster,
    638         qprogram=qprogram,
    639         bus_mapping=bus_mapping,
    640         threshold_rotations=threshold_rotations,  # type: ignore
    641         calibration=calibration,
    642         debug=debug,
    643     )
    644 raise NotImplementedError(\"Executing QProgram in a mixture of instruments is not supported.\")

File ~/qililab/src/qililab/platform/platform.py:714, in Platform._execute_qprogram_with_quantum_machines(self, cluster, qprogram, bus_mapping, threshold_rotations, calibration, debug)
    704 def _execute_qprogram_with_quantum_machines(  # pylint: disable=too-many-locals
    705     self,
    706     cluster: QuantumMachinesCluster,
   (...)
    711     debug: bool = False,
    712 ) -> QProgramResults:
    713     compiler = QuantumMachinesCompiler()
--> 714     qua_program, configuration, measurements = compiler.compile(
    715         qprogram=qprogram, bus_mapping=bus_mapping, threshold_rotations=threshold_rotations, calibration=calibration
    716     )
    718     try:
    719         cluster.append_configuration(configuration=configuration)

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:169, in QuantumMachinesCompiler.compile(self, qprogram, bus_mapping, threshold_rotations, calibration)
    167 self._declare_variables()
    168 # Recursive traversal to convert QProgram to QUA program.
--> 169 traverse(self._qprogram.body)
    170 # Stream Processing
    171 with qua.stream_processing():

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:132, in QuantumMachinesCompiler.compile.<locals>.traverse(block)
    130 if isinstance(element, (InfiniteLoop, ForLoop, Loop, Average, Parallel)):
    131     with handler(element):
--> 132         traverse(element)
    133 else:
    134     handler(element)

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:131, in QuantumMachinesCompiler.compile.<locals>.traverse(block)
    127     raise NotImplementedError(
    128         f\"{element.__class__} operation is currently not supported in Quantum Machines.\"
    129     )
    130 if isinstance(element, (InfiniteLoop, ForLoop, Loop, Average, Parallel)):
--> 131     with handler(element):
    132         traverse(element)
    133 else:

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:231, in QuantumMachinesCompiler._handle_parallel_loop(self, element)
    228 for loop in element.loops:
    229     qua_variable = self._qprogram_to_qua_variables[loop.variable]
    230     values = (
--> 231         np.arange(loop.start, loop.stop + loop.step / 2, loop.step)
    232         if isinstance(loop, ForLoop)
    233         else loop.values
    234     )
    235     if loop.variable.domain is Domain.Phase:
    236         values = values / self.PHASE_COEFF

ValueError: arange: cannot compute length"
}

after running it the second time

```jsx
{
    "name": "ValueError",
    "message": "arange: cannot compute length",
    "stack": "---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[9], line 12
      3 stream_array = ql.stream_results(
      4     shape=(len(amplitudes1), len(amplitudes2), 2),
      5     loops={\"amplitudes1\": amplitudes1, 
      6            \"amplitudes2\": amplitudes2},
      7     path=create_directories(\"/home/jupytershared/data/\") + \"results.h5\",
      8     )
     11 for i, qprogram in enumerate(qprogram_list):
---> 12     results = platform.execute_qprogram(
     13         qprogram=qprogram, bus_mapping={\"readout\": readout_bus, \"flux_1\": flux1_bus, \"flux_2\": flux2_bus, \"flux_3\": flux3_bus, \"flux_4\": flux4_bus}
     14     )
     15     stream_array[:,i,:] = results.results[\"readout_2\"][0].array.T

File ~/qililab/src/qililab/platform/platform.py:636, in Platform.execute_qprogram(self, qprogram, bus_mapping, calibration, debug)
    630     cluster: QuantumMachinesCluster = instruments.pop()  # type: ignore[assignment]
    631     threshold_rotations = {
    632         bus.alias: float(bus.get_parameter(parameter=Parameter.THRESHOLD_ROTATION))
    633         for bus in buses
    634         if isinstance(bus.system_control, ReadoutSystemControl)
    635     }  # type: ignore
--> 636     return self._execute_qprogram_with_quantum_machines(
    637         cluster=cluster,
    638         qprogram=qprogram,
    639         bus_mapping=bus_mapping,
    640         threshold_rotations=threshold_rotations,  # type: ignore
    641         calibration=calibration,
    642         debug=debug,
    643     )
    644 raise NotImplementedError(\"Executing QProgram in a mixture of instruments is not supported.\")

File ~/qililab/src/qililab/platform/platform.py:714, in Platform._execute_qprogram_with_quantum_machines(self, cluster, qprogram, bus_mapping, threshold_rotations, calibration, debug)
    704 def _execute_qprogram_with_quantum_machines(  # pylint: disable=too-many-locals
    705     self,
    706     cluster: QuantumMachinesCluster,
   (...)
    711     debug: bool = False,
    712 ) -> QProgramResults:
    713     compiler = QuantumMachinesCompiler()
--> 714     qua_program, configuration, measurements = compiler.compile(
    715         qprogram=qprogram, bus_mapping=bus_mapping, threshold_rotations=threshold_rotations, calibration=calibration
    716     )
    718     try:
    719         cluster.append_configuration(configuration=configuration)

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:169, in QuantumMachinesCompiler.compile(self, qprogram, bus_mapping, threshold_rotations, calibration)
    167 self._declare_variables()
    168 # Recursive traversal to convert QProgram to QUA program.
--> 169 traverse(self._qprogram.body)
    170 # Stream Processing
    171 with qua.stream_processing():

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:132, in QuantumMachinesCompiler.compile.<locals>.traverse(block)
    130 if isinstance(element, (InfiniteLoop, ForLoop, Loop, Average, Parallel)):
    131     with handler(element):
--> 132         traverse(element)
    133 else:
    134     handler(element)

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:131, in QuantumMachinesCompiler.compile.<locals>.traverse(block)
    127     raise NotImplementedError(
    128         f\"{element.__class__} operation is currently not supported in Quantum Machines.\"
    129     )
    130 if isinstance(element, (InfiniteLoop, ForLoop, Loop, Average, Parallel)):
--> 131     with handler(element):
    132         traverse(element)
    133 else:

File ~/qililab/src/qililab/qprogram/quantum_machines_compiler.py:231, in QuantumMachinesCompiler._handle_parallel_loop(self, element)
    228 for loop in element.loops:
    229     qua_variable = self._qprogram_to_qua_variables[loop.variable]
    230     values = (
--> 231         np.arange(loop.start, loop.stop + loop.step / 2, loop.step)
    232         if isinstance(loop, ForLoop)
    233         else loop.values
    234     )
    235     if loop.variable.domain is Domain.Phase:
    236         values = values / self.PHASE_COEFF

ValueError: arange: cannot compute length"
}

### System Information

```Shell
Name: qililab
Version: 0.27.0
Summary: Fundamental package for fast characterization and calibration of quantum chips.
Home-page: https://github.com/qilimanjaro-tech/qililab
Author: Qilimanjaro Quantum Tech
Author-email: info@qilimanjaro.tech
License: Apache License 2.0
Location: /home/opihl/miniconda3/envs/qililab/lib/python3.10/site-packages
Editable project location: /home/opihl/qililab
Requires: h5py, lmfit, networkx, pandas, papermill, PyVISA-py, qblox-instruments, qcodes, qcodes-contrib-drivers, qibo, qm-qua, qpysequence, qualang-tools, ruamel.yaml, rustworkx, submitit, tqdm, urllib3
Required-by: qilitools

Platform info:             Linux-5.15.0-113-generic-x86_64-with-glibc2.35
Python version:            3.10.14
PyVISA version:            0.7.1
QCodes version:            0.42.0
QCodes Contrib version:    0.18.0
Qblox Instrument version:  0.11.2
Qpysequence version:       0.10.1
Quantum Machines version:  1.2.0
Qibo version:              0.2.8

Existing GitHub issues

linear[bot] commented 1 month ago

QHC-665 [BUG] vs_flux() Qprogram throwing error