IBM Quantum Compute Service QRMI - Examples in Rust#


Prerequisites#

Set environment variables#

Because QRMI is an environment variable driven software library, all configuration parameters must be specified in environment variables. The required environment variables are listed below. This example assumes that a .env file is available under the current directory.

Environment variables

Descriptions

{resource_name}_QRMI_IBM_QCS_ENDPOINT

IBM Quantum Compute Service endpoint URL (e.g. https://quantum.cloud.ibm.com/api)

{resource_name}_QRMI_IBM_QCS_IAM_ENDPOINT

IBM Cloud IAM endpoint URL (e.g. https://iam.cloud.ibm.com)

{resource_name}_QRMI_IBM_QCS_IAM_APIKEY

IBM Cloud IAM API Key

{resource_name}_QRMI_IBM_QCS_SERVICE_CRN

Cloud Resource Name (CRN) of the provisioned Quantum Compute Service instance, starting with crn:v1:.

{resource_name}_QRMI_IBM_QCS_SESSION_MODE

Execution mode to run the session in, default='dedicated', batch or dedicated.

{resource_name}_QRMI_IBM_QCS_SESSION_MAX_TTL

The maximum time (in seconds) for the session to run, subject to plan limits, default: 28800.

{resource_name}_QRMI_IBM_QCS_TIMEOUT_SECONDS

(Optional) Cost of the job as the estimated time it should take to complete (in seconds). Should not exceed the cost of the program, default: None.

{resource_name}_QRMI_IBM_QCS_SESSION_ID

(Optional) Session ID, can be obtanied by acquire function. If exists, used in the target functions.

Create Qiskit Primitive input file as input#

Refer to this tool to generate. You can customise quantum circuits by editing the code.

Note

Use the file with name ending _params_only.json, e.g. sampler_input_ibm_torino_params_only.json.

How to build this example#

cargo clean
cargo build --example qrmi-example-quantum-compute-service --release

How to run this example#

../target/release/qrmi-example-quantum-compute-service --help

QRMI for IBM Quantum Compute Service - Example

Usage: qrmi-example-quantum_compute_service --backend <BACKEND> --input <INPUT> --program-id <PROGRAM_ID>

Options:
  -b, --backend <BACKEND>        backend name
  -i, --input <INPUT>            primitive input file
  -p, --program-id <PROGRAM_ID>  program id
  -h, --help                     Print help
  -V, --version                  Print version

For example, using the generated input file, run the package:

export ibm_torino_QRMI_IBM_QCS_ENDPOINT=https://quantum.cloud.ibm.com/api/v1
export ibm_torino_QRMI_IBM_QCS_IAM_ENDPOINT=https://iam.cloud.ibm.com
export ibm_torino_QRMI_IBM_QCS_IAM_APIKEY=your_apikey
export ibm_torino_QRMI_IBM_QCS_SERVICE_CRN=your_instance

../target/release/qrmi-example-quantum-compute-service  -b ibm_torino -i sampler_input.json -p sampler