Skip to main content

Quantum Resource Estimation Format

Project description

QREF

Quantum Resource Estimation Format (QREF) is an open format for representing quantum algorithms, optimized for usage in quantum resource estimation (QRE).

QREF comprises:

  • Definition of data format, formalized as a JSON schema.
  • A Python library for validation of quantum programs written in QREF format using Pydantic.
  • Rudimentary visualization tool qref-render.

Installation

Using QREF data format does not require installation - you can easily write quantum programs in YAML or JSON.

To install QREF Python package, run pip install qref.

Alternatively, you can clone this repository and build it from source:

# Clone QREF repo (you can use HTTP link as well)
git clone git@github.com:PsiQ/qref.git
cd qref
pip install .

QREF format

QREF format represents quantum programs as a hierarchical directed acyclic graphs (DAGs). That's a mouthful, so let us unpack what it means:

  • hierarchical: each node can contain subgraphs, i.e. routines can be nested inside larger routines.
  • directed: information flow is unidirectional, and the direction is unambiguous.
  • acyclic: meaning there are no loops.

Consider the following hierarchical DAG of a hypothetical quantum program:

program example

It can be succinctly written in QREF format as:

version: v1
program:
  name: my_algorithm
  ports:
  - direction: input
    name: in_0
    size: 2
  - direction: input
    name: in_1
    size: 2
  - direction: output
    name: out_0
    size: 4
  children:
  - name: subroutine_1
    ports:
    - direction: input
      name: in_0
      size: 2
    - direction: output
      name: out_0
      size: 3
  - name: subroutine_2
    ports:
    - direction: input
      name: in_0
      size: 2
    - direction: output
      name: out_0
      size: 1
    - direction: output
      name: out_1
      size: 1
  - name: merge
    ports:
    - direction: input
      name: in_0
      size: 1
    - direction: input
      name: in_1
      size: 1
    - direction: input
      name: in_2
      size: 2
    - direction: output
      name: out_0
      size: 4
  connections:
  - source: in_0
    target: subroutine_1.in_0
  - source: in_1
    target: subroutine_2.in_0
  - source: subroutine_1.out_0
    target: merge.in_2
  - source: subroutine_2.out_0
    target: merge.in_0
  - source: subroutine_2.out_1
    target: merge.in_1
  - source: merge.out_0
    target: out_0

For full description of QREF format, check our docs.

Using QREF package

Using JSON schema for validating data in QREF format

JSON schema for QREF format can be obtained by calling generate_program_schema function. Such schema can be then used for validating user's input, e.g. using jsonschema package:

from jsonschema import validate
from qref import generate_program_schema

# Hypothetical function loading your data as native Python dictionary.
data = load_some_program()
schema = generate_program_schema()

# This will raise if there are some validation errors.
validate(schema, data)

Validation using Pydantic models

If you are familiar with Pydantic, you might find it easier to work with QREF Pydantic models instead of interacting with JSON schema directly. In the example below, we create an instance of SchemaV1 model from validated data stored in QREF format:

from qref import SchemaV1

data = load_some_program()

# This will raise if data is not valid
program = SchemaV1.model_validate(data)

Development

In order to install development environment or build documentation locally, please refer to Development Guide.

Documentation

Documentation for qref can be found here.

To run docs locally install it with docs option: pip install ".[docs]" (or poetry install --with docs) and then run mkdocs serve.

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

qref-0.5.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

qref-0.5.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file qref-0.5.0.tar.gz.

File metadata

  • Download URL: qref-0.5.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for qref-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d0921d3bf08953cbdabbc8f475beec299252fe41d2d1708cbe44315bb916e537
MD5 32b81936c1f3d4bdf210531a090cbd29
BLAKE2b-256 947be61573246d8642557f6292e88932b70792319e0a04278c391cadc1ec95f1

See more details on using hashes here.

File details

Details for the file qref-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: qref-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for qref-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e7fd1117ac5ae05c5a7f14e3f86f45e4a9d8e2c9057a78ee7fa65b8ff5b8f39
MD5 ef95a2b3e625d091d8f4205e11664358
BLAKE2b-256 8929b9f5c735a5ff9acb5fe439ceca82c4d767fbd9eeb5892ece5087d1be8043

See more details on using hashes here.

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