# iqm.qdmi.offloader

Offload Qiskit workloads (sampling and estimation) using Slurm.

## Module Contents

### extract_counts(primitive_result: qiskit.primitives.containers.PrimitiveResult[qiskit.primitives.containers.SamplerPubResult]) → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [int](https://docs.python.org/3/builtins/functions.html#int)]

Extract joint counts from the native sampler’s single submitted circuit.

* **Returns:**
  Joint bitstrings in Qiskit’s register order, mapped to shot counts.
* **Raises:**
  [**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError) – If the result is empty or has no classical registers with counts.

### sample(qc: qiskit.QuantumCircuit, shots: [int](https://docs.python.org/3/builtins/functions.html#int) = 1024, , local: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, simulator: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, qc_id: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, qc_alias: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, licenses: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, partition: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, nodes: [int](https://docs.python.org/3/builtins/functions.html#int) = \_DEFAULT_NODES) → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [int](https://docs.python.org/3/builtins/functions.html#int)]

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 in this process on the selected backend.

* **Parameters:**
  * **qc** – The quantum circuit to run.
  * **shots** – The number of shots to run. Default is 1024.
  * **local** – If True, run the job in this process on the selected backend.
    If False (default), offload to Slurm.
  * **simulator** – If True, run the job on the simulator instead of the quantum computer.
  * **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**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If Qiskit or the QDMI backend plugins are not installed.
  * [**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError) – Propagated from job submission or result decoding.

### estimate(ansatz: qiskit.QuantumCircuit, operator: [SparsePauliOp](https://quantum.cloud.ibm.com/docs/api/qiskit/qiskit.quantum_info.SparsePauliOp), maxiter: [int](https://docs.python.org/3/builtins/functions.html#int) = 80, , local: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, simulator: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, qc_id: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, qc_alias: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, licenses: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, partition: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, nodes: [int](https://docs.python.org/3/builtins/functions.html#int) = \_DEFAULT_NODES) → qiskit_algorithms.VQEResult

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 in this process on the selected backend.
    If False (default), offload to Slurm.
  * **simulator** – If True, run the job on the simulator instead of the quantum computer.
  * **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**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If Qiskit or the QDMI backend plugins are not installed.
  * [**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError) – If there is an error while submitting the job to Slurm or parsing the output.
