Skip to content

Commit

Permalink
Shifts from Rows, Doc Fix, Default Layout (#189)
Browse files Browse the repository at this point in the history
* no arm builder

* placeholder + doc link

* doc workflow

* docstrings correction

* updated user docs

* default

* set_dev

* endpoint call correction

* default-layout qoqo

* default-layout roq + row allowed shifts

* two_tweezer edges qoqo + better api test

* allowed_shifts_from_row tests

* shifts from rows interface + tests

* shifts validity check correction

* versioning + fmt

* missing versioning

* doc correction

* fmt
  • Loading branch information
mlodi-hqs authored Sep 22, 2023
1 parent 814dea4 commit 12ef730
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hqs-build-deploy-rust-pyo3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
py_interface_folder: "qoqo-qryd"
deploy: true
# Whether to build for aarch64. Can fail if there are C/C++ dependencies
build_for_arm: true
build_for_arm: false
secrets: inherit

build_maturin_builds_macos:
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/hqs-build-deploy-sphinx-doc-rust-pyo3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -19,16 +21,23 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip maturin
pip install ./qoqo-qryd
python -m pip install -r ./userdoc/requirements.txt
pip install ./qoqo-qryd[docs]
- uses: peaceiris/actions-mdbook@v1
with:
version: latest
- name: build
run: |
cd ./userdoc
# qoqo-qryd
cd qoqo-qryd/docs
python -m sphinx -T -E -b html . _build/html
cd ../../
cd ../..
cp -r ./qoqo-qryd/docs/_build/html ./documentation/src/qoqo_qryd_api
# Generating doc
cd documentation/
mdbook build

- name: publish
uses: peaceiris/actions-gh-pages@v3
# if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./userdoc/_build/html/
publish_dir: documentation/book
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Tracks qoqo-qryd changes after 0.5

# 0.11.1

* Corrected the check of the validity of a `PragmaShiftQubitsTweezers` operation for `TweezerDevice`
* Added `TweezerDevice.set_allowed_tweezer_shifts_from_rows()`
* Added `TweezerDevice.two_tweezer_edges()`
* Added `TweezerDevice.set_default_layout()`
* Added `APIBackend.set_dev()`
* Corrected docs after mdbook port

# 0.11.0

* Substituted `httpmock` with `mockito` in mock testing
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions documentation/src/qoqo_qryd_api.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
qoqo-qryd API documentation
===========================

The qoqo-qryd provides software components for [qoqo](https://github.com/HQSquantumsimulations/qoqo>) that support QRydDemo quantum computers.
The qoqo-qryd provides software components for [qoqo](https://github.com/HQSquantumsimulations/qoqo>) that support QRydDemo quantum computers.

The qoqo-qryd module provides:

1. Backends that execute a compiled qoqo QuantumProgram on QRydDemo hardware (when available), via a WebAPI emulation (APIBackend) or simulators (SimulatorBackend).
2. A set of specific operations only available on QRydDemo hardware.
3. A collection of devices, representations of the hardware devices available in QrydDemo.

This is the API documentation of qoqo-qryd, for a more general overview see the User Documentation.
This is the [API documentation of qoqo-qryd](qoqo_qryd_api/html/index.html), for a more general overview see the User Documentation.
Empty file.
68 changes: 53 additions & 15 deletions documentation/src/qrydspecifics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ Note that all functionality described here is a preview and does not represent a
Special operations
------------------

To support the full flexibility of the QRydDemo devices, two additional qoqo operations are provided ``PragmaChangeQRydLayout`` and ``PragmaShiftQRydQubit``.
``PragmaChangeQRydLayout`` allows a quantum circuit to change between predefined calibrated optical tweezer positions.
``PragmaShiftQRydQubit`` allows a quantum circuit to shift a qubit from one tweezer position to another.
To support the full flexibility of the QRydDemo devices, two additional qoqo operations are provided ``PragmaChangeQRydLayout``, ``PragmaSwitchDeviceLayout``, ``PragmaShiftQRydQubit`` and ``PragmaShiftQubitsTweezers``.
``PragmaChangeQRydLayout`` allows a quantum circuit to change between predefined calibrated optical tweezer positions. It indexes the layouts by integer. A similar operation, but meant for ``TweezerDevice`` and ``TweezerMutableDevice``, is ``PragmaSwitchDeviceLayout``, which indexes the new layout via a string.
``PragmaShiftQRydQubit`` allows a quantum circuit to shift a qubit from one tweezer position to another. ``PragmaShiftQubitsTweezers`` is the equivalent operation meant to be used with ``TweezerDevice`` and ``TweezerMutableDevice``.

```python
from qoqo import Circuit
from qoqo_qryd.pragma_operations import PragmaChangeQRydLayout, PragmaShiftQRydQubit
from qoqo_qryd.pragma_operations import PragmaChangeQRydLayout, PragmaShiftQRydQubit, PragmaSwitchDeviceLayout, PragmaShiftQubitsTweezers

circuit = Circuit()
# Switch to predefined layout 1
circuit += PragmaChangeQRydLayout(new_layout=1).to_pragma_change_device()
# Switch to predefined layout "triangle"
circuit += PragmaSwitchDeviceLayout(new_layout="triangle").to_pragma_change_device()
# Shift qubit 0 to tweezer position: row 0, column 1 and qubit 1 to postion row 1, column 1
circuit += PragmaShiftQRydQubit(new_positions={0: (0,1), 1: (1,1)}).to_pragma_change_device()
# Shift the qubit state present in tweezer 0 to tweezer 1, and the qubit state present in tweezer 2 to tweezer 3
circuit += PragmaShiftQubitsTweezers(shifts=[(0, 1), (2, 3)]).to_pragma_change_device()
()
```


Devices
QRyd and Tweezer devices
-------

Each type of QRydDemo hardware or Simulator device can be represented by a Device class.
Each type of QRydDemo hardware or Simulator device can be represented by either the QRydDevice or the TweezerDevice classes.
The available hardware operations are defined in the devices. They save the 2D connectivity and can be queried for the availability of certain gate operations on the qubit.
At the moment there is only an example Device class ``FirstDevice``, that can be used for simulations. More devices will be added as the hardware specifications are finalized.
At the moment the most general example Device class is ``FirstDevice``, that can be used for simulations. Other available devices include ``TweezerMutableDevice``, which works by first defining the underlying tweezer structure and then populate it with qubits as needed. ``TweezerDevice`` works in a similar way. The main difference is it does not allow any setting of the Tweezer information. This should be obtained via the `.from_api()` call (see the [WebAPI](webapi.md) section).

The fundamental gates that are available on the QRydDemo devices are the following qoqo operations: ``RotateX``, ``RotateY``, ``RotateZ``, ``RotateXY``, ``PauliX``, ``PauliY``, ``PauliZ``, ``PhaseShiftState1`` , ``SqrtPauliX``, ``InvSqrtPauliX``, ``PhaseShiftedControlledZ`` and ``PhaseShiftedControlledPhase``.
The single-qubit gates are assumed to be available on all qubits.
Expand All @@ -42,10 +48,12 @@ The phase shifts can in principle be device dependent.
The devices can optionally contain the ``controlled_z_phase_relation`` and ``controlled_phase_phase_relation`` parameters that define the phase shift relations of the two-qubit gates for the device. The first parameter can also be set explicitly by putting a string defining a float value as input.

```python
from qoqo_qryd import devices
from qoqo_qryd.qryd_devices import FirstDevice
from qoqo_qryd.tweezer_devices import TweezerMutableDevice
import numpy as np
# create a FirstDevice
device = devices.FirstDevice(

# Create a FirstDevice
first_device = FirstDevice(
# The number of tweezer position rows in the 2D Grid is fixed
number_rows=2,
# The number of tweezer position columns in the 2D grid is also fixed
Expand All @@ -64,10 +72,40 @@ The devices can optionally contain the ``controlled_z_phase_relation`` and ``con
# Using a string that defines a relation is also possible
controlled_z_phase_relation="0.23",
# The relation to use for the PhaseShiftedControlledPhase phase shift value
controlled_phase_phase_relation="DefaultRelation")
controlled_phase_phase_relation="DefaultRelation"
)

# Print the two-qubit-operation connectivity graph of the device
print(device.two_qubit_edges())
print(first_device.two_qubit_edges())

# Create a TweezerMutableDevice
tweezer_device = TweezerMutableDevice(
# The phase shift value related to the PhaseShiftedControlledZ gate
# Using a string that defines a relation is also possible
controlled_z_phase_relation="0.23",
# The relation to use for the PhaseShiftedControlledPhase phase shift value
controlled_phase_phase_relation="DefaultRelation"
)

# Add a tweezer layout to the device
tweezer_device.add_layout(name="triangle")

# Set single-qubit tweezer gate time information on the new layout
tweezer_device.set_tweezer_single_qubit_gate_time(
hqslang="PhaseShiftState1",
tweezer=0,
gate_time=0.23,
layout="triangle",
)

# Populate the newly set tweezer with qubit indexed as 0
tweezer_device.add_qubit_tweezer_mapping(
qubit=0,
tweezer=0,
)

# Print the available layouts of the device
print(tweezer_device.available_layouts())
```


Expand All @@ -79,11 +117,11 @@ Executing a circuit with the ``SimulatorBackend`` initialized by the ``FirstDevi
operations available in ``FirstDevice`` are used.

```python
from qoqo_qryd import devices
from qoqo_qryd.qryd_devices import FirstDevice
from qoqo_qryd import SimulatorBackend
import numpy as np
# create a FirstDevice
device = devices.FirstDevice(
# Create a FirstDevice
device = FirstDevice(
# The number of tweezer position rows in the 2D Grid is fixed
number_rows=2,
# The number of tweezer position columns in the 2D grid is also fixed
Expand Down
17 changes: 17 additions & 0 deletions documentation/src/webapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,21 @@ The four API calls can be used to obtain a result the following way:
break
# alternatively delete job
# backend.delete_job(job_location)
```

TweezerDevice
----------

By calling the `.from_api()` static method, an instance of the ``TweezerDevice`` class can be created with Tweezer information already set.

```python
from qoqo_qryd.tweezer_devices import TweezerDevice

# Creating a new TweezerDevice instance.
device = TweezerDevice.from_api(
# The name of the device to use.
device_name="test_device",
# Optional token. This is not necessary if the token is already an environment variable.
access_token="YOUR_QRYD_API_TOKEN"
)
```
3 changes: 2 additions & 1 deletion qoqo-qryd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qoqo-qryd"
version = "0.11.0"
version = "0.11.1"
authors = ["HQS Quantum Simulations <info@quantumsimulations.de>"]
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -52,6 +52,7 @@ roqoqo-qryd = { version = "0.11", path = "../roqoqo-qryd", default-features = fa
[dev-dependencies]
test-case = "3.0"
mockito = { version = "1.1", default-features = false }
serde_json = "1.0"

[build-dependencies]
pyo3-build-config = "0.19"
Expand Down
2 changes: 1 addition & 1 deletion qoqo-qryd/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "qoqo_qryd"
version = "0.11.0"
version = "0.11.1"
dependencies = [
'numpy',
'qoqo>=1.6',
Expand Down
4 changes: 2 additions & 2 deletions qoqo-qryd/qoqo_qryd/DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -19662,7 +19662,7 @@ LICENSE:


====================================================
qoqo-qryd 0.11.0
qoqo-qryd 0.11.1
https://github.com/HQSquantumsimulations/qoqo_qryd
by HQS Quantum Simulations <info@quantumsimulations.de>
QRyd backend for qoqo quantum computing toolkit
Expand Down Expand Up @@ -23405,7 +23405,7 @@ LICENSE:


====================================================
roqoqo-qryd 0.11.0
roqoqo-qryd 0.11.1
https://github.com/HQSquantumsimulations/qoqo_qryd
by HQS Quantum Simulations <info@quantumsimulations.de>
QRyd interface for roqoqo rust quantum computing toolkit
Expand Down
1 change: 1 addition & 0 deletions qoqo-qryd/qoqo_qryd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pragma_operations
SimulatorBackend
APIBackend
tweezer_devices

"""

Expand Down
9 changes: 9 additions & 0 deletions qoqo-qryd/src/api_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ impl APIBackendWrapper {
)
})
}

/// Setter for the dev option of the APIDevice.
///
/// Args:
/// dev (bool): The boolean to set the dev option to.
///
pub fn set_dev(&mut self, dev: bool) {
self.internal.set_dev(dev);
}
}

/// Convert generic python object to [roqoqo_qryd::APIBackend].
Expand Down
11 changes: 6 additions & 5 deletions qoqo-qryd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ use pyo3::wrap_pymodule;
/// Provides devices for the QRyd quantum hardware for the qoqo quantum toolkit.
/// Also provides qoqo PRAGMA operations specific to those devices.
/// Includes an optional QRydSimulator backend.
/// Furthermore, provides a collection of all QRyd devices for the WebAPI.
/// Furthermore, provides a collection of all QRyd as well as Tweezer devices for the WebAPI.
///
/// .. autosummary::
/// :toctree: generated/
///
/// qryd_devices
/// api_devices
/// APIBackend
/// Backend
/// pragma_operations
/// devices
/// SimulatorBackend
/// APIBackend
/// tweezer_devices
///
pub mod qryd_devices;
pub use qryd_devices::*;
Expand Down Expand Up @@ -88,7 +89,7 @@ pub use api_devices::*;
/// Backend
/// pragma_operations
/// qryd_devices
/// experimental_devices
/// tweezer_devices
///
///
#[pymodule]
Expand Down
Loading

0 comments on commit 12ef730

Please sign in to comment.