iqm.qdmi.offloader

Offload Qiskit workloads (sampling and estimation) using Slurm.

Module Contents

normalize_counts(raw_counts: object) dict[str, int][source]

Convert backend count payloads into a plain typed dictionary.

Returns:

A normalized mapping from bitstrings to integer counts.

extract_counts(pub_result: PubResult) dict[str, int][source]

Extract counts from the first classical register exposed by a primitive result.

Returns:

A normalized mapping from measured bitstrings to shot counts.

Raises:

RuntimeError – If no classical register with counts is present in the result.

sample(qc: qiskit.QuantumCircuit, shots: int = 1024, *, local: bool = False, simulator: bool = False, timeout: float | None = None, qc_id: str | None = None, qc_alias: str | None = None, licenses: str | None = None, partition: str | None = None, nodes: int = _DEFAULT_NODES) dict[str, int][source]

Sample from a quantum circuit.

When local=False (default), serializes the given circuit to QPY format and submits it to the Slurm workload manager using the srun command. After completion, the counts are parsed and returned as a dictionary.

When local=True, runs the circuit locally using the MQT Core DDSIM simulator backend.

Parameters:
  • qc – The quantum circuit to run.

  • shots – The number of shots to run. Default is 1024.

  • local – If True, run the job locally using the built-in QDMI simulator backend. If False (default), offload to Slurm.

  • simulator – If True, run the job on the simulator instead of the quantum computer. Only used when local=False.

  • timeout – How long to wait for the Slurm job to complete, in seconds, before giving up. Only used when local=False.

  • qc_id – If given, passed as –iqm-qc-id to srun, which the QDMI-on-IQM SPANK plugin resolves into the IQM_QC_ID job environment variable. Only used when local=False.

  • qc_alias – If given, passed as –iqm-qc-alias to srun, which the QDMI-on-IQM SPANK plugin resolves into the IQM_QC_ALIAS job environment variable. Only used when local=False.

  • licenses – If given, passed as –licenses to srun, requesting the named Slurm license(s) (Slurm’s own name[:count][,name[:count] …] syntax) that a site administrator may have configured to cap concurrent jobs against a QC – e.g. required by the SPANK plugin’s iqm_require_license option. Only used when local=False.

  • partition – The Slurm partition to submit to, passed as –partition to srun. Defaults to the IQM_SLURM_PARTITION environment variable, and to quantum when that is unset. Only used when local=False.

  • nodes – The number of nodes to allocate, passed as –nodes to srun. The worker always runs as a single task (–ntasks=1), so this only sizes the allocation for sites whose partition demands more than one node. Default is 1. Only used when local=False.

Returns:

A dictionary of measurement counts.

Raises:
  • ImportError – If Qiskit or the QDMI backend plugins are not installed.

  • RuntimeError – If there is an error while submitting the job to Slurm or parsing the output.

estimate(ansatz: qiskit.QuantumCircuit, operator: SparsePauliOp, maxiter: int = 80, *, local: bool = False, simulator: bool = False, timeout: float | None = None, qc_id: str | None = None, qc_alias: str | None = None, licenses: str | None = None, partition: str | None = None, nodes: int = _DEFAULT_NODES) qiskit_algorithms.VQEResult[source]

Estimate the optimal parameters for a given ansatz circuit and operator.

When local=False (default), serializes the given ansatz and operator to QPY/pickle format and submits them to the Slurm workload manager using the srun command. After completion, the VQE result is parsed and returned.

When local=True, runs the VQE algorithm locally using either the MQT Core DDSIM simulator backend or the packaged IQM backend.

The returned result has the same semantics as calling VQE(…).compute_minimum_eigenvalue(…) directly against the regular (non-offloaded) estimator.

Parameters:
  • ansatz – The ansatz circuit to run.

  • operator – The operator to run.

  • maxiter – The maximum number of iterations for the optimization. Default is 80.

  • local – If True, run the job locally using the built-in QDMI simulator backend. If False (default), offload to Slurm.

  • simulator – If True, run the job on the simulator instead of the quantum computer. Only used when local=False.

  • timeout – How long to wait for the Slurm job to complete, in seconds, before giving up. Only used when local=False.

  • qc_id – If given, passed as –iqm-qc-id to srun, which the QDMI-on-IQM SPANK plugin resolves into the IQM_QC_ID job environment variable. Only used when local=False.

  • qc_alias – If given, passed as –iqm-qc-alias to srun, which the QDMI-on-IQM SPANK plugin resolves into the IQM_QC_ALIAS job environment variable. Only used when local=False.

  • licenses – If given, passed as –licenses to srun, requesting the named Slurm license(s) (Slurm’s own name[:count][,name[:count] …] syntax) that a site administrator may have configured to cap concurrent jobs against a QC – e.g. required by the SPANK plugin’s iqm_require_license option. Only used when local=False.

  • partition – The Slurm partition to submit to, passed as –partition to srun. Defaults to the IQM_SLURM_PARTITION environment variable, and to quantum when that is unset. Only used when local=False.

  • nodes – The number of nodes to allocate, passed as –nodes to srun. The worker always runs as a single task (–ntasks=1), so this only sizes the allocation for sites whose partition demands more than one node. Default is 1. Only used when local=False.

Returns:

The VQE result, including the optimal parameters and eigenvalue.

Raises:
  • ImportError – If Qiskit or the QDMI backend plugins are not installed.

  • RuntimeError – If there is an error while submitting the job to Slurm or parsing the output.