Skip to content

Commit

Permalink
Merge branch 'main' into Zurich_freq_sweepers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacfomg committed Dec 13, 2023
2 parents fbebe17 + 05c64b7 commit 2f29f45
Show file tree
Hide file tree
Showing 69 changed files with 3,455 additions and 6,585 deletions.
85 changes: 76 additions & 9 deletions .github/workflows/selfhosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,81 @@ concurrency:
cancel-in-progress: true

jobs:
build:
prepare:
if: contains(join(github.event.pull_request.labels.*.name), 'run-on')
uses: qiboteam/workflows/.github/workflows/selfhosted.yml@main
with:
used-labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
python-version: "3.10"
artifact-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
poetry-extras: "--with tests --all-extras"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Read platforms from labels
id: set-matrix
env:
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
run: |
echo $LABELS
platforms="["
combined=""
shopt -s lastpipe
jq -c '.[]' <<< "$LABELS" | while read label; do
platform=(${label//-/ })
if [ ${platform[0]} == "\"run" ] && [ ${platform[1]} == "on" ]; then
platforms+="${combined:+,}\"${platform[2]}"
combined=${platforms}
fi
done
platforms+="]"
echo ${platforms}
echo matrix="${platforms}" >> $GITHUB_OUTPUT
secrets:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tests:
needs: prepare
strategy:
matrix:
platform: ${{ fromJSON(needs.prepare.outputs.matrix) }}
fail-fast: false
runs-on: self-hosted
steps:
- name: Cleanup workspace manually
run: |
rm -rf _work/*
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install and configure poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
- name: Install qibolab main
run: |
python -m venv testenv
source testenv/bin/activate
poetry install --no-interaction --all-extras --with tests
- name: Execute on ${{ matrix.platform }}
run: |
source testenv/bin/activate
export platform=${{ matrix.platform }}
git clone https://github.com/qiboteam/qibolab_platforms_qrc
queues=`cat qibolab_platforms_qrc/queues.json`
export QIBOLAB_PLATFORMS=./qibolab_platforms_qrc
partition="$(jq -r -n --argjson data "$queues" '$data.'$platform)"
srun -p $partition selfhosted
mkdir coverage
mv coverage.xml coverage/
mv htmlcov coverage/
- name: Upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: coverage-from-self-hosted
path: coverage/
- name: Notify the Pull Request
uses: thollander/actions-comment-pull-request@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
Run on QPU `${{ matrix.platform }}` completed! :atom:
> *You can download the coverage report as an artifact, from the workflow summary page:*
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ repos:
- id: check-toml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.11.0
hooks:
- id: black
args:
- --line-length=120
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.1
hooks:
- id: isort
args: ["--profile", "black"]
Expand All @@ -25,7 +25,7 @@ repos:
hooks:
- id: pyupgrade
- repo: https://github.com/hadialqattan/pycln
rev: v2.3.0
rev: v2.4.0
hooks:
- id: pycln
args:
Expand Down
22 changes: 12 additions & 10 deletions doc/source/main-documentation/qibolab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ This instrument is also part of the dummy platform which is defined in :py:mod:`
This platform is equivalent to real platforms in terms of attributes and functions, but returns just random numbers.
It is useful for testing parts of the code that do not necessarily require access to an actual quantum hardware platform.

.. testcode:: python

from qibolab import create_platform

platform = create_platform("dummy_couplers")

will create a dummy platform that also has coupler qubits.


.. _main_doc_qubits:

Qubits
Expand Down Expand Up @@ -653,15 +662,9 @@ This procedure typically involves the following steps:
2. All gates are transpiled to native gates, which represent the universal set of gates that can be implemented (via pulses) in the chip.
3. Native gates are compiled to a pulse sequence.

The transpilation and compilation process is taken care of automatically by the :class:`qibolab.backends.QibolabBackend` when a circuit is executed, using :class:`qibolab.transpilers.abstract.Transpiler` and :class:`qibolab.compilers.compiler.Compiler`.
The transpiler is responsible for steps 1 and 2, while the compiler for step 3 of the list above. In order to accomplish this, several transpilers are provided, some of which are listed below:

- :class:`qibolab.transpilers.gate_decompositions.NativeGates`: Transpiles single-qubit Qibo gates to Z, RZ, GPI2 or U3 and two-qubit gates to CZ and/or iSWAP (depending on platform support).
- :class:`qibolab.transpilers.star_connectivity.StarConnectivity`: Transforms a circuit to respect a 5-qubit star chip topology, with one middle qubit connected to each of the remaining four qubits.
- :class:`qibolab.transpilers.routing.ShortestPaths`: Transforms a circuit to respect a general chip topology given as a networkx graph, using a greedy algorithm.
- :class:`qibolab.transpilers.pipeline.Pipeline`: Applies a list of other transpilers sequentially.

Custom transpilers can be added by inheriting the abstract :class:`qibolab.transpilers.abstract.Transpiler` class.
The transpilation and compilation process is taken care of automatically by the :class:`qibolab.backends.QibolabBackend` when a circuit is executed, using circuit transpilers provided by Qibo and :class:`qibolab.compilers.compiler.Compiler`.
The transpiler is responsible for steps 1 and 2, while the compiler for step 3 of the list above.
For more information on the transpiler please refer the `examples in the Qibo documentation <https://qibo.science/qibo/stable/code-examples/advancedexamples.html#how-to-modify-the-transpiler>`_.

Once a circuit has been transpiled, it is converted to a :class:`qibolab.pulses.PulseSequence` by the :class:`qibolab.compilers.compiler.Compiler`.
This is a container of rules which define how each native gate can be translated to pulses.
Expand Down Expand Up @@ -691,7 +694,6 @@ U3, the most general single-qubit gate can be implemented using two RX90 pi-puls
Typical two-qubit native gates are the CZ and iSWAP, with their availability being platform dependent.
These are implemented with a sequence of flux pulses, potentially to multiple qubits, and virtual Z-phases.
Depending on the platform and the quantum chip architecture, two-qubit gates may require pulses acting on qubits that are not targeted by the gate.
The :class:`qibolab.native.NativeType` flag is used for communicating the set of available native two-qubit gates to the transpiler.

.. _main_doc_instruments:

Expand Down
14 changes: 10 additions & 4 deletions doc/source/tutorials/circuits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ circuits definition that we leave to the `Qibo
qibo.set_backend("qibolab", "dummy")
hardware_result = circuit(nshots=5000)

# retrieve measured probabilities
freq = hardware_result.frequencies()
p0 = freq["0"] / 5000 if "0" in freq else 0
p1 = freq["1"] / 5000 if "1" in freq else 0
hardware = [p0, p1]

# execute with classical quantum simulation
qibo.set_backend("numpy")
simulation_result = circuit(nshots=5000)

# retrieve measured probabilities
hardware = hardware_result.probabilities(qubits=(0,))
simulation = simulation_result.probabilities(qubits=(0,))


Expand Down Expand Up @@ -87,8 +91,10 @@ results:
circuit.set_parameters([angle])

# execute circuit
state = circuit.execute(nshots=4000)
p0, p1 = state.probabilities(qubits=(0,))
result = circuit.execute(nshots=4000)
freq = result.frequencies()
p0 = freq['0'] / 4000 if '0' in freq else 0
p1 = freq['1'] / 4000 if '1' in freq else 0

# store probability in state |1>
res.append(p1)
Expand Down
17 changes: 8 additions & 9 deletions doc/source/tutorials/transpiler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Creating an instance of the backend provides access to these objects:
.. testoutput:: python
:hide:

<class 'qibolab.transpilers.pipeline.Passes'>
<class 'qibo.transpiler.pipeline.Passes'>
<class 'qibolab.compilers.compiler.Compiler'>

The transpiler is responsible for transforming the circuit to respect the chip connectivity and native gates,
Expand Down Expand Up @@ -56,11 +56,11 @@ Instead of completely disabling, custom transpilation steps can be given:
.. testcode:: python

from qibolab.backends import QibolabBackend
from qibolab.native import NativeType
from qibolab.transpilers.unroller import NativeGates

from qibo.transpiler.unroller import NativeGates, Unroller

backend = QibolabBackend(platform="dummy")
backend.transpiler = NativeGates(two_qubit_natives=NativeType.CZ)
backend.transpiler = Unroller(native_gates=NativeGates.CZ)


Now circuits will only be transpiled to native gates, without any connectivity matching steps.
Expand All @@ -75,16 +75,15 @@ Multiple transpilation steps can be implemented using the :class:`qibolab.transp

.. testcode:: python

from qibolab.native import NativeType
from qibolab.transpilers.pipeline import Passes
from qibolab.transpilers.star_connectivity import StarConnectivity
from qibolab.transpilers.unroller import NativeGates
from qibo.transpiler import Passes
from qibo.transpiler.unroller import NativeGates, Unroller
from qibo.transpiler.star_connectivity import StarConnectivity

backend = QibolabBackend(platform="dummy")
backend.transpiler = Passes(
[
StarConnectivity(middle_qubit=2),
NativeGates(two_qubit_natives=NativeType.CZ),
Unroller(native_gates=NativeGates.CZ),
]
)

Expand Down
Loading

0 comments on commit 2f29f45

Please sign in to comment.