From 6139abb43a72b03066a667096d0283e908d30bf7 Mon Sep 17 00:00:00 2001 From: Stavros Efthymiou <35475381+stavros11@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:47:43 +0400 Subject: [PATCH 1/5] chore: drop logging from platform.connect --- src/qibolab/_core/platform/platform.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 From 9bc6e58fb5aadc65a246aaddeed6df149fc979fb Mon Sep 17 00:00:00 2001 From: Stavros Efthymiou <35475381+stavros11@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:48:01 +0400 Subject: [PATCH 2/5] docs: update README --- README.md | 109 +++++++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 38ddce813..6334c1010 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 @@ -26,43 +26,14 @@ A simple example on how to connect to a platform and use it execute a pulse sequ ```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, - ) -) # 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() @@ -71,38 +42,74 @@ options = ExecutionParameters(nshots=1000) results = platform.execute([sequence], options) # Print the acquired shots -print(results.samples) +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 From ee0b9d07478a45dd9a1ab159bb8d1f82f4d431ec Mon Sep 17 00:00:00 2001 From: Stavros Efthymiou <35475381+stavros11@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:36:52 +0400 Subject: [PATCH 3/5] fix: drop usage of ExecutionParameters --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6334c1010..8aa2dea95 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ 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 import create_platform # Define platform and load specific runcard platform = create_platform("my_platform") @@ -38,8 +38,7 @@ sequence = natives.RX() | natives.MZ() 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 readout_id = sequence.acquisitions[0][1].id From aa113bffe399ed3bb581bcda2e9cbd5b45db59bc Mon Sep 17 00:00:00 2001 From: Stavros Efthymiou <35475381+stavros11@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:40:28 +0400 Subject: [PATCH 4/5] docs: explain use of id --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8aa2dea95..b3a7e2f17 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,11 @@ platform.connect() # Execute a pulse sequence results = platform.execute([sequence], nshots=1000) -# Print the acquired shots +# 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]) From b5f8db4a169c81e35dcfb4437135efec81e767da Mon Sep 17 00:00:00 2001 From: Stavros Efthymiou <35475381+stavros11@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:44:01 +0400 Subject: [PATCH 5/5] docs: propagate features to sphinx --- doc/source/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ============================