Skip to main content

QFactor and QFactor-Sample Implementations on GPUs Using JAX

bqskit-qfactor-jax is a Python package that implements circuit instantiation using the QFactor and QFactor-Sample algorithms on GPUs to accelerate BQSKit. It uses JAX as an abstraction layer of the GPUs, seamlessly utilizing JIT compilation and GPU parallelism.

Installation

bqskit-qfactor-jax is available for Python 3.9+ on Linux. It can be installed using pip

pip install bqskit-qfactor-jax

If you are experiencing issues with JAX please refer to JAX's installation instructions.

Basic Usage

QFactor and QFactor-Sample are instantiation algorithms that, given a unitary matrix and a parameterized circuit, optimize the circuit parameters to best approximate the target unitary matrix.

import numpy as np
from bqskit import Circuit
from bqskit.ir.gates import VariableUnitaryGate
from bqskit.qis.unitary import UnitaryMatrix

from qfactorjax.qfactor_sample_jax import QFactorSampleJax



# Load a circuit from QASM
circuit = Circuit.from_file("template.qasm")

# Load the target unitary
unitary_target = UnitaryMatrix.from_file("target.mat")

# Create the instantiator object
qfactor_sample_gpu_instantiator = QFactorSampleJax()

# Perform the instantiation
circuit.instantiate(
        unitary_target,
        multistarts=16,
        method=qfactor_sample_gpu_instantiator,
    )

# Calculate and print final distance
dist = circuit.get_unitary().get_distance_from(unitary_target, 1)

print('Final Distance: ', dist)

Please look at the examples for a more detailed usage, especially at performance comparison between QFactor and QFactor-Sample.

GPU Configuration and Memory Management

Please set the environment variable XLA_PYTHON_CLIENT_PREALLOCATE=False when using this package. Also, if you encounter OOM issues consider setting XLA_PYTHON_CLIENT_ALLOCATOR=platform.

When using several workers on the same GPU, we recommend using Nvidia's MPS. You may initiate it using the command line

nvidia-cuda-mps-control -d

You can disable it by running this command line:

echo quit | nvidia-cuda-mps-control

References

If you are using QFactor please cite:
Kukliansky, Alon, et al. "QFactor: A Domain-Specific Optimizer for Quantum Circuit Instantiation." 2023 IEEE International Conference on Quantum Computing and Engineering (QCE). Vol. 1. IEEE, 2023. Link.

If you are using QFactor-Sample please cite:
Kukliansky, Alon, et al. "Leveraging Quantum Machine Learning Generalization to Significantly Speed-up Quantum Compilation" arXiv preprint arXiv:2405.12866 (2024).

License

The software in this repository is licensed under a BSD free software license and can be used in source or binary form for any purpose as long as the simple licensing requirements are followed. See the LICENSE file for more information.

Copyright

Quantum Fast Circuit Optimizer (QFactor) JAX implementation Copyright (c) 2024, U.S. Federal Government and the Government of Israel. All rights reserved.

Metadata

Release files for bqskit-qfactor-jax 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bqskit-qfactor-jax 1.0.1
File Size Uploaded Provenance
bqskit_qfactor_jax-1.0.1.tar.gz 21.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bqskit-qfactor-jax 1.0.1
File Interpreter ABI Platform
bqskit_qfactor_jax-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 45.3 kB

Release files / bqskit_qfactor_jax-1.0.1.tar.gz

Download URL bqskit_qfactor_jax-1.0.1.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
43e26a59bd3277e3e36bed62c9c1f4d408b3e4bd203b016416cb32c5b46c2cae
BLAKE2b-256 checksum
How to use checksums
8c214becdbd7a4e8bbecccb2d176764061dfa5178443c6cc56a4091de49b7d4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Release files / bqskit_qfactor_jax-1.0.1-py2.py3-none-any.whl

Download URL bqskit_qfactor_jax-1.0.1-py2.py3-none-any.whl
Size 24.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
39e1958d4b50f4b5ef100db6102bb5860d7ba053cada215430383cf7e7fe0647
BLAKE2b-256 checksum
How to use checksums
d0e1db3655d85f911bfdbbf3a9295f1bd7732abcdc932b437ce4ce0386b798c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Security for bqskit-qfactor-jax 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page