Skip to main content

Platform-dependent engines and model to execute compiled expressions with common set of methods.

Project description

Qadence 2 Platforms

!!! note Qadence 2 Platforms is currently a work in progress and is under active development.

Please be aware that the software is in an early stage, and frequent updates, including breaking changes, are to be expected. This means that:
* Features and functionalities may change without prior notice.
* The codebase is still evolving, and parts of the software may not function as intended.
* Documentation and user guides may be incomplete or subject to significant changes.

Qadence 2 Platforms is a collection of functionalities that transforms Qadence IR into backend-specific data and constructors, to be executed by backend methods. It is not intended to be used directly by Qadence 2 users, but rather those who need to implement or extend backends, quantum instruction primitives, compiler or backend directives, etc.

Installation

!!! note it is advised to set up a python environment before installing the package.

To install the current version, there is currently one option:

Installation from Source

Clone this repository by typing on the terminal

git clone https://github.com/pasqal-io/qadence2-platforms.git

Go to qadence2-platforms folder and install it using hatch:

python -m pip install hatch

and run hatch to create or reuse the project environment:

hatch -v shell

Description

Platforms

This package should not be used directly by the user. It is used to convert Qadence IR into backend-compatible data, and to execute it with extra options (provided by the compilation process, either on Qadence 2 expressions or Qadence 2 core).

Qadence 2 Intermediate Representation (IR)

Qadence 2 expressions is being compiled into an IR comprised of both quantum and classical operations.

Platforms API

The backend module exposes a single compile_to_backend function which accepts a Model and a string denoting the backend.

Platforms Backend

Each submodule under backend is expected (1) to translate the IR data into backend-compatible data, (2) to provide instruction conversions from IR to backend, (3) to handle the storage and embedding of parameters, and (4) to implement execution process for run, sample and expectation.

Usage

Example

from qadence2_ir.types import (
    Model,
    Alloc,
    AllocQubits,
    Call,
    Assign,
    QuInstruct,
    Support,
    Load
)


Model(
    register = AllocQubits(
        num_qubits = 3,
        qubit_positions = [(-2,1), (0,1), (1,3)],
        grid_type = "triangular",
        grid_scale = 1.0,
        options = {"initial_state": "010"}
    ),
    inputs = {
        "x": Alloc(1, trainable=False),
        "t": Alloc(1, trainable=False),      # time
        "Omega": Alloc(4, trainable=True),   # 4-points amp. modulation
        "delta": Alloc(1, trainable=False), # detuning
    },
    instructions = [
        # -- Feature map
        Assign("%0", Call("mul", 1.57, Load("x"))),
        Assign("%1", Call("sin", Load("%0"))),
        QuInstruct("rx", Support(target=(0,)), Load("%1")),
        # --
        QuInstruct("h", Support.target_all()),
        QuInstruct("not", Support(target=(1,), control=(0,))),
        QuInstruct(
		        "qubit_dyn",
		        Support(control=(0,), target=(2,)),
		        Load("t"),
		        Load("Omega"),
		        Load("delta"),
		    )
    ],
    directives = {"digital-analog": True},
)

Compiling a pyqtorch circuit and computing gradients using torch.autograd

import torch
import pyqtorch as pyq
from qadence2_ir.types import (
    Model, Alloc, AllocQubits, Load, Call, Support, QuInstruct, Assign
)

from qadence2_platforms.compiler import compile_to_backend


model = Model(
    register=AllocQubits(num_qubits=2),
    inputs={
        "x": Alloc(size=1, trainable=False),
    },
    instructions=[
        Assign("%0", Call("mul", 1.57, Load("x"))),
        Assign("%1", Call("sin", Load("%0"))),
        QuInstruct("rx", Support(target=(0,)), Load("%1")),
        QuInstruct("not", Support(target=(1,), control=(0,))),
    ],
    directives={"digital": True},
)
api = compile_to_backend(model, "pyqtorch")
f_params = {"x": torch.rand(1, requires_grad=True)}
wf = api.run(state=pyq.zero_state(2), values=f_params)
dfdx = torch.autograd.grad(wf, f_params["x"], torch.ones_like(wf))[0]

Documentation

!!! note Documentation in progress.

Contribute

Before making a contribution, please review our code of conduct.

  • Submitting Issues: To submit bug reports or feature requests, please use our issue tracker.
  • Developing in qadence 2 platforms: To learn more about how to develop within qadence 2 platforms, please refer to contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qadence2_platforms-0.2.2.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qadence2_platforms-0.2.2-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file qadence2_platforms-0.2.2.tar.gz.

File metadata

  • Download URL: qadence2_platforms-0.2.2.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for qadence2_platforms-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a67d4f55fb86b4e5846620918070297d2de6ad0d88ba30e44f3f73ec6757c8c2
MD5 8135203b0710aeea478a07dfb6579f82
BLAKE2b-256 c2f7b6fe96b650a4d5b1ed64c83c3206a4e8b7931f224f9a754d4f960f232ae1

See more details on using hashes here.

Provenance

The following attestation bundles were made for qadence2_platforms-0.2.2.tar.gz:

Publisher: test.yml on pasqal-io/qadence2-platforms

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qadence2_platforms-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for qadence2_platforms-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4b39504d31f4aa43ef67c3fbb7da5144f2f9fde1dcb84ec150d1376092103c2
MD5 1914c5228916ce8d8bbc143edb8b62c7
BLAKE2b-256 08c1177b856a5ef806851729d937b23b9220a2fee8c93a8f1607f53766e3f52c

See more details on using hashes here.

Provenance

The following attestation bundles were made for qadence2_platforms-0.2.2-py3-none-any.whl:

Publisher: test.yml on pasqal-io/qadence2-platforms

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page