diff --git a/README.md b/README.md index 38ddce813..b3a7e2f17 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ the automatic deployment of quantum circuits on quantum hardware. Some of the key features of Qibolab are: - Deploy Qibo models on quantum hardware easily. -- Create custom experimental drivers for custom lab setup. +- Create experimental drivers for custom lab setup. - Support multiple heterogeneous platforms. -- Use existing calibration procedures for experimentalists. +- Use calibration procedures from [Qibocal](https://github.com/qiboteam/qibocal). ## Documentation @@ -25,84 +25,94 @@ The qibolab backend documentation is available at [https://qibo.science/qibolab/ A simple example on how to connect to a platform and use it execute a pulse sequence: ```python -from qibolab import create_platform, ExecutionParameters -from qibolab.pulses import Pulse, Delay, PulseType - -# Define PulseSequence -sequence = PulseSequence() -# Add some pulses to the pulse sequence -sequence.append( - Pulse( - amplitude=0.3, - duration=4000, - frequency=200_000_000, - relative_phase=0, - shape="Gaussian(5)", # Gaussian shape with std = duration / 5 - type=PulseType.DRIVE, - channel=1, - ) -) -sequence.append( - Delay( - duration=4000, - channel=2, - ) -) -sequence.append( - ReadoutPulse( - amplitude=0.9, - duration=2000, - frequency=20_000_000, - relative_phase=0, - shape="Rectangular", - type=PulseType.READOUT, - channel=2, - ) -) +from qibolab import create_platform # Define platform and load specific runcard platform = create_platform("my_platform") +# Create a pulse sequence based on native gates of qubit 0 +natives = platform.natives.single_qubit[0] +sequence = natives.RX() | natives.MZ() + # Connects to lab instruments using the details specified in the calibration settings. platform.connect() # Execute a pulse sequence -options = ExecutionParameters(nshots=1000) -results = platform.execute([sequence], options) +results = platform.execute([sequence], nshots=1000) -# Print the acquired shots -print(results.samples) +# Grab the acquired shots corresponding to +# the measurement using its pulse id. +# The ``PulseSequence`` structure is list[tuple[ChannelId, Pulse]] +# thererefore we need to index it appropriately +# to get the acquisition pulse +readout_id = sequence.acquisitions[0][1].id +print(results[readout_id]) # Disconnect from the instruments platform.disconnect() ``` -Here is another example on how to execute circuits: +Arbitrary pulse sequences can also be created using the pulse API: ```python -import qibo -from qibo import gates, models +from qibolab import ( + Acquisition, + Delay, + Gaussian, + Pulse, + PulseSequence, + Readout, + Rectangular, +) + +# Crete some pulses +pulse = Pulse( + amplitude=0.3, + duration=40, + relative_phase=0, + envelope=Gaussian(rel_sigma=0.2), # Gaussian shape with std = 0.2 * duration +) +delay = Delay(duration=40) +readout = Readout( + acquisition=Acquisition(duration=2000), + probe=Pulse( + amplitude=0.9, + duration=2000, + envelope=Rectangular(), + relative_phase=0, + ), +) +# Add them to a PulseSequence +sequence = PulseSequence( + [ + (1, pulse), # pulse plays on channel 1 + (2, delay), # delay and readout plays on channel 2 + (2, readout), + ] +) +``` + +Here is another example on how to execute circuits: + +```python +from qibo import gates, models, set_backend -# Create circuit and add gates +# Create circuit and add native gates c = models.Circuit(1) -c.add(gates.H(0)) -c.add(gates.RX(0, theta=0.2)) -c.add(gates.X(0)) +c.add(gates.GPI2(0, phi=0.2)) c.add(gates.M(0)) # Simulate the circuit using numpy -qibo.set_backend("numpy") -for _ in range(5): - result = c(nshots=1024) - print(result.probabilities()) +set_backend("numpy") +result = c(nshots=1024) +print(result.probabilities()) # Execute the circuit on hardware -qibo.set_backend("qibolab", platform="my_platform") -for _ in range(5): - result = c(nshots=1024) - print(result.probabilities()) +set_backend("qibolab", platform="my_platform") +result = c(nshots=1024) +print(result.probabilities()) ``` ## Citation policy diff --git a/doc/source/index.rst b/doc/source/index.rst index f5ed2051b..c1649fb8a 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -23,9 +23,9 @@ Key features ------------ * Deploy Qibo models on quantum hardware easily. -* Create custom experimental drivers for custom lab setup. +* Create experimental drivers for custom lab setup. * Support multiple heterogeneous platforms. -* Use existing calibration procedures for experimentalists. +* Use calibration procedures from `Qibocal `_. How to Use the Documentation ============================ diff --git a/src/qibolab/_core/platform/platform.py b/src/qibolab/_core/platform/platform.py index d39031c7e..5fd215c26 100644 --- a/src/qibolab/_core/platform/platform.py +++ b/src/qibolab/_core/platform/platform.py @@ -171,14 +171,13 @@ def config(self, name: str) -> Config: def connect(self): """Connect to all instruments.""" if not self.is_connected: - for instrument in self.instruments.values(): + for name, instrument in self.instruments.items(): try: - log.info(f"Connecting to instrument {instrument}.") instrument.connect() except Exception as exception: raise_error( RuntimeError, - f"Cannot establish connection to {instrument} instruments. Error captured: '{exception}'", + f"Cannot establish connection to instrument {name}. Error captured: '{exception}'", ) self.is_connected = True