Skip to main content

Prefect workflow integration for Qiskit Primitives.

Project description

Prefect Qiskit

License Release Python

This library integrates Prefect with Qiskit Primitives, which are vendor-agnostic abstractions for quantum computation.

Given the high cost and limited processing time of quantum computation, fatal errors can disrupt the entire workflow. This library enhances software fault tolerance by implementing primitive execution within a Prefect workflow.

For more details, visit the full documentation here.

Installation

Prefect Qiskit requires Python 3.10 or later. We encourage install via pip

pip install prefect-qiskit

Pip will handle all dependencies automatically and you will always install the latest version.

Quantum Computing Workflow

The programming model and syntax are largely consistent with conventional Qiskit primitives, allowing easy integration of Prefect's powerful job management features into existing experiment codebases. The key difference is the use of the QuantumRuntime Block, which implements the Prefect API for quantum computing.

Unlike the conventional pattern that uses primitive class instances to create jobs, the runtime Block encapsulates vendor-specific job handling and provides robust error handling during execution.

For example, the following script samples the probability distribution of the Bell state using the Qiskit Aer simulator.

from prefect import flow, task
from prefect_qiskit import QuantumRuntime
from prefect_qiskit.vendors import QiskitAerCredentials
from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager


@task
def transpile_task(circuit, target):
    pm = generate_preset_pass_manager(
        optimization_level=2,
        target=target,
    )
    return pm.run(circuit)


@flow
def sample_bell():
    # 1. Create QuantumRuntime for Aer backend
    credentials = QiskitAerCredentials(
        num_qubits=2, 
        noise=True,
    )
    runtime = QuantumRuntime(
        resource_name="aer_simulator", 
        credentials=credentials,
    )
    # 2. Create ISA quantum circuit
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0, 1)
    bell.measure_all()
    isa_circ = transpile_task(
        circuit=bell, 
        target=runtime.get_target(),
    )
    # 3. Execute workflow sampler
    result = runtime.sampler(
        [isa_circ], 
        options={"default_shots": 100},
    )
    print(result[0].data.meas.get_counts())


# Run the flow
if __name__ == "__main__":
    sample_bell()

Before running your workflow, start the Prefect server:

prefect server start --background

You can then run the workflow as a standard Python script. Once the workflow begins, you can monitor its execution status in the Prefect console. For common workflow usage, refer to the Prefect documentation.

[!TIP] The runtime Block also supports asynchronous execution. For massive parallel execution of primitives, using the await expression will efficiently utilize your computational resources.

Registering Blocks

Register Blocks to make them available for use with the Prefect console.

prefect block register -m prefect_qiskit
prefect block register -m prefect_qiskit.vendors

Contribution Guidelines

If you'd like to contribute to Prefect Qiskit, please take a look at our contribution guidelines. By participating, you are expected to uphold our code of conduct.

We use GitHub issues for tracking requests and bugs. For Prefect workflow, open issues and PRs against PrefectHQ/prefect instead of this repository. Likewise, open issues and PRs against Qiskit/qiskit for Qiskit Primitives.

License

Apache License 2.0

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

prefect_qiskit-0.1.0.tar.gz (896.5 kB view details)

Uploaded Source

Built Distribution

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

prefect_qiskit-0.1.0-py3-none-any.whl (717.2 kB view details)

Uploaded Python 3

File details

Details for the file prefect_qiskit-0.1.0.tar.gz.

File metadata

  • Download URL: prefect_qiskit-0.1.0.tar.gz
  • Upload date:
  • Size: 896.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for prefect_qiskit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aec13b390d359c68fc19d1db9aa1f6ef61be2826888dd978d0671bd782c04695
MD5 cb1f1bc5a6eca247fa528bda9bf61577
BLAKE2b-256 521413e839b4ebee54a64c3cd9bdc61052285ff15bc2d41bee771a568213e0fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for prefect_qiskit-0.1.0.tar.gz:

Publisher: release.yml on qiskit-community/prefect-qiskit

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

File details

Details for the file prefect_qiskit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: prefect_qiskit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 717.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for prefect_qiskit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75d0916ade6f649000831ea3bbbbc79ec39708d458c698c00df3591bac2e327d
MD5 669884a35e8f2f15aab908591aa69bc4
BLAKE2b-256 cfedb3eba5ff4f7d77b96103b8a8af4228f3b05caafeb48680bb1fd1f846a0f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for prefect_qiskit-0.1.0-py3-none-any.whl:

Publisher: release.yml on qiskit-community/prefect-qiskit

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