Skip to main content

Quaternionic quantum compiler for the RQM ecosystem

Project description

rqm-compiler

rqm-compiler is the backend-neutral compilation layer for the RQM ecosystem. It converts RQM circuit objects into canonical gate descriptors that can be translated by execution backends such as Qiskit and Amazon Braket.


Ecosystem position

RQM physics / math
        ↓
    rqm-core
        ↓
   rqm-compiler          ← this repo
        ↓
rqm-qiskit   rqm-braket

rqm-compiler sits between the physics math layer (rqm-core) and the vendor execution layers. It does not implement quantum math and does not import vendor SDKs.


Quick start

from rqm_compiler import Circuit, compile_circuit

c = Circuit(2)
c.h(0)
c.cx(0, 1)
c.measure(0, key="m0")
c.measure(1, key="m1")

compiled = compile_circuit(c)
print(compiled.descriptors)
# [
#   {'gate': 'h',       'targets': [0], 'controls': [],  'params': {}},
#   {'gate': 'cx',      'targets': [1], 'controls': [0], 'params': {}},
#   {'gate': 'measure', 'targets': [0], 'controls': [],  'params': {'key': 'm0'}},
#   {'gate': 'measure', 'targets': [1], 'controls': [],  'params': {'key': 'm1'}},
# ]

Installation

pip install rqm-compiler

Or in development mode from the repository root:

pip install -e ".[dev]"

Core concepts

Canonical descriptor

Every gate operation is represented as a plain dictionary:

{
    "gate": "rx",       # lowercase gate name
    "targets": [0],     # list of target qubit indices (always present)
    "controls": [],     # list of control qubit indices (always present)
    "params": {"angle": 1.5707963267948966}  # parameter dict (always present)
}

This is the source of truth for the entire ecosystem. Backend repos translate these descriptors into their respective SDK objects.

Circuit

Circuit(num_qubits) is the canonical circuit container. It provides a fluent builder API:

from rqm_compiler import Circuit

c = Circuit(3)

# Single-qubit gates
c.i(0); c.x(0); c.y(1); c.z(2); c.h(0); c.s(1); c.t(2)

# Parameterised single-qubit gates
c.rx(0, 1.57).ry(1, 0.78).rz(2, 3.14).phaseshift(0, 0.5)

# Two-qubit gates
c.cx(0, 1).cy(1, 2).cz(0, 2)
c.swap(0, 1).iswap(1, 2)

# Measurement
c.measure(0, key="m0")

# Barrier
c.barrier()

# Export
descriptors = c.to_descriptors()

compile_circuit

compile_circuit(circuit) is the main entry point:

from rqm_compiler import compile_circuit

compiled = compile_circuit(c)

compiled.descriptors   # list of canonical descriptor dicts
compiled.num_qubits    # int
compiled.metadata      # dict with compilation metadata

The pipeline: validate → normalize → canonicalize → flatten → export.

IO helpers

from rqm_compiler.io import circuit_to_dict, circuit_from_dict

data = circuit_to_dict(c)         # serialize to JSON-compatible dict
restored = circuit_from_dict(data) # reconstruct Circuit from dict

Supported gates (v0)

Category Gates
Single-qubit i x y z h s t
Parameterised single-qubit rx ry rz phaseshift (param: angle)
Two-qubit cx cy cz swap iswap
Other measure barrier

Backend integration

Backend repos use rqm-compiler like this:

from rqm_compiler import compile_circuit

compiled = compile_circuit(circuit)

for op in compiled.descriptors:
    translate_to_backend(op)

The backend never needs to re-implement normalization, validation, or gate naming conventions.


Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

Architecture rules

See AGENTS.md for the full list of contributor boundary rules.

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

rqm_compiler-0.1.5.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

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

rqm_compiler-0.1.5-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file rqm_compiler-0.1.5.tar.gz.

File metadata

  • Download URL: rqm_compiler-0.1.5.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rqm_compiler-0.1.5.tar.gz
Algorithm Hash digest
SHA256 20d4a45bd02cc05488a93649a60c1a4b3afc55b86bade6829ae1d8d2f5c7277a
MD5 c7a23b341738de00a77f2f4d8e5f740f
BLAKE2b-256 5cc27da93480da51dd596af2b4fae0a572c7ad45b8bbc518f2784f2bdab865e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rqm_compiler-0.1.5.tar.gz:

Publisher: publish.yml on RQM-Technologies-dev/rqm-compiler

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

File details

Details for the file rqm_compiler-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: rqm_compiler-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rqm_compiler-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7029fff27bf3af508705566edf07249b8461e1d87c1eb2a287c1afed4e9d8050
MD5 3cd84b8c0c3dc936d40c21733e5d6509
BLAKE2b-256 f1d91083b001164c4543b0d238adff10b2e0047319cb3cb4afeb71a2f04d3396

See more details on using hashes here.

Provenance

The following attestation bundles were made for rqm_compiler-0.1.5-py3-none-any.whl:

Publisher: publish.yml on RQM-Technologies-dev/rqm-compiler

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