Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #1051

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 58 additions & 51 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).
scarrazza marked this conversation as resolved.
Show resolved Hide resolved

## Documentation

Expand All @@ -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
stavros11 marked this conversation as resolved.
Show resolved Hide resolved
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()

Expand All @@ -71,38 +42,74 @@ options = ExecutionParameters(nshots=1000)
results = platform.execute([sequence], options)
stavros11 marked this conversation as resolved.
Show resolved Hide resolved

# Print the acquired shots
print(results.samples)
readout_id = sequence.acquisitions[0][1].id
scarrazza marked this conversation as resolved.
Show resolved Hide resolved
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
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