Skip to content

Commit

Permalink
Merge pull request #1051 from qiboteam/readme
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
stavros11 authored Sep 20, 2024
2 parents d51abf2 + b5f8db4 commit 486c6c7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 60 deletions.
120 changes: 65 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/qiboteam/qibocal>`_.

How to Use the Documentation
============================
Expand Down
5 changes: 2 additions & 3 deletions src/qibolab/_core/platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 486c6c7

Please sign in to comment.