Skip to content

Commit

Permalink
Merge pull request #999 from qiboteam/0.2
Browse files Browse the repository at this point in the history
0.2
  • Loading branch information
scarrazza authored Sep 20, 2024
2 parents 9bbbbe8 + baeed90 commit 78b02a1
Show file tree
Hide file tree
Showing 206 changed files with 12,695 additions and 30,491 deletions.
4 changes: 2 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

nix_direnv_watch_file flake.nix
nix_direnv_watch_file flake.lock
watch_file flake.nix
watch_file flake.lock
if ! use flake . --impure; then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
6 changes: 3 additions & 3 deletions .github/workflows/capi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Prepare virtual environment
run: |
python -m venv env
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
python-version: [3.9, "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
uses: qiboteam/workflows/.github/workflows/deploy-pip-poetry.yml@v1
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
publish: ${{ github.event_name == 'release' && github.event.action == 'published' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' }}
publish: ${{ github.event_name == 'release' && github.event.action == 'published' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
poetry-extras: "--with docs,tests,analysis --all-extras"
secrets: inherit
6 changes: 3 additions & 3 deletions .github/workflows/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
python-version: [3.9, "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
uses: qiboteam/workflows/.github/workflows/rules-poetry.yml@v1
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
doctests: ${{ matrix.os == 'ubuntu-latest'}}
doctests: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version != '3.12'}}
poetry-extras: "--with docs,tests,analysis --all-extras"
secrets: inherit
14 changes: 5 additions & 9 deletions .github/workflows/rustapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
name: Rust API

on:
push:
workflow_dispatch:

jobs:
tests:
strategy:
matrix:
os: [ubuntu-latest, macos-13]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Prepare virtual environment
run: |
pip install .
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: dtolnay/rust-toolchain@stable
- name: Check and lint
working-directory: crate
run: |
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ repos:
- id: pycln
args:
- --config=pyproject.toml
- --all
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.18.0
hooks:
Expand Down
116 changes: 65 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +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.
- Provide a emulator backend equipped with various quantum dynamics simulation engines (currently support: QuTiP) for seamless emulation of quantum hardware.
- Use calibration procedures from [Qibocal](https://github.com/qiboteam/qibocal).

## Documentation

Expand All @@ -26,79 +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 DrivePulse, ReadoutPulse, PulseSequence

# Define PulseSequence
sequence = PulseSequence()
# Add some pulses to the pulse sequence
sequence.add(
DrivePulse(
start=0,
amplitude=0.3,
duration=4000,
frequency=200_000_000,
relative_phase=0,
shape="Gaussian(5)", # Gaussian shape with std = duration / 5
channel=1,
)
)

sequence.add(
ReadoutPulse(
start=4004,
amplitude=0.9,
duration=2000,
frequency=20_000_000,
relative_phase=0,
shape="Rectangular",
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_pulse_sequence(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
2 changes: 1 addition & 1 deletion capi/src/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is part of
from cqibolab import ffi

from qibolab import execute_qasm as py_execute_qasm
from qibolab._core.backends import execute_qasm as py_execute_qasm


@ffi.def_extern()
Expand Down
18 changes: 17 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

import qibolab

# TODO: the following is a workaround for Sphinx doctest, cf.
# - https://github.com/qiboteam/qibolab/commit/e04a6ab
# - https://github.com/pydantic/pydantic/discussions/7763
import qibolab._core.instruments.dummy
import qibolab._core.instruments.oscillator
import qibolab._core.instruments.zhinst

# -- Project information -----------------------------------------------------

project = "qibolab"
Expand All @@ -32,7 +39,15 @@
# https://stackoverflow.com/questions/56336234/build-fail-sphinx-error-contents-rst-not-found
# master_doc = "index"

autodoc_mock_imports = ["qm"]
autodoc_mock_imports = ["icarusq_rfsoc_driver"]
try:
import qibolab.instruments.qm
except ModuleNotFoundError:
autodoc_mock_imports.extend(["qm", "qualang_tools"])
try:
import qibolab.instruments.rfsoc
except ModuleNotFoundError:
autodoc_mock_imports.extend(["qibosoq"])

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -45,6 +60,7 @@
"sphinx.ext.intersphinx",
"recommonmark",
"sphinx_copybutton",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
]

Expand Down
Loading

0 comments on commit 78b02a1

Please sign in to comment.