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] QPySequence cache for QProgram execution messes up with instrument sync/desync #692

Closed fedonman closed 6 months ago

fedonman commented 6 months ago

Expected behavior

When execution starts all sequencers that will be used in the execution are marked as synced and when execution finishes they are desynced.

This behavior should happen both when executing QProgram a single time like platform.execute_qprogram(qp) and when executing inside a software loop

for frequency in frequencies:
    platform.set_parameter("drive_q0_bus", Parameter.LO_FREQUENCY, frequency)
    platform.execute_qprogram(qp)

Actual behavior

When executing QProgram within a software loop, the sequencers are desynced after the first iteration, and stay desynced. This is because the syncing happens in the upload_qpysequence() method which is only called the first time (since the rest the cache is populated and upload is not called).

# qililab/instruments/qblox/qblox_module.py
def upload_qpysequence(self, qpysequence: QpySequence, port: str):
        """Upload the qpysequence to its corresponding sequencer.

        Args:
            qpysequence (QpySequence): The qpysequence to upload.
            port (str): The port of the sequencer to upload to.
        """
        sequencers = self.get_sequencers_from_chip_port_id(chip_port_id=port)
        for sequencer in sequencers:
            logger.info("Sequence program: \n %s", repr(qpysequence._program))  # pylint: disable=protected-access
            self.device.sequencers[sequencer.identifier].sequence(qpysequence.todict())
            self.device.sequencers[sequencer.identifier].sync_en(True)
            self.sequences[sequencer.identifier] = qpysequence

The desyncing however happens at the end of the platform.execute_qprogram() method, so after the first iteration the sequencers are desynced and never synced again.

Additional information

We should be able to defer the desyncing after all iterations of the software loop are done.

This is not possible right now, because the execute_qprogram() has no knowledge of what happens outside. One idea is to wrap the whole execution in a context manager, which will be responsible for interacting with the instruments. This can also involve the chain of initial_setup, turn_on_instruments, etc.

with platform.execution() as execution:
     for frequency in frequencies:
          platform.set_parameter("drive_q0_bus", Parameter.LO_FREQUENCY, frequency)
          platform.execute_qprogram(qp)

Source code

No response

Tracebacks

No response

System Information

Name: qililab
Version: 0.23.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/fedonman/conda/envs/qililab/lib/python3.10/site-packages
Editable project location: /home/fedonman/projects/qililab
Requires: h5py, lmfit, networkx, pandas, papermill, PyVISA-py, qblox-instruments, qcodes, qcodes-contrib-drivers, qibo, qiboconnection, qm-qua, qpysequence, qualang-tools, ruamel.yaml, rustworkx, submitit, tqdm, urllib3
Required-by:

Platform info:             Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.38
Python version:            3.10.12
PyVISA version:            0.7.1
QCodes version:            0.42.0
QCodes Contrib version:    0.18.0
Qblox Instrument version:  0.10.1
Qpysequence version:       0.10.0
Quantum Machines version:  1.1.6
Qibo version:              0.1.12.dev0

Existing GitHub issues

linear[bot] commented 6 months ago

QHC-246 [BUG] QPySequence cache for QProgram execution messes up with instrument sync/desync