iqm.cirq_iqm.iqm_sampler.IQMSampler#

class iqm.cirq_iqm.iqm_sampler.IQMSampler(url: str, *, device: IQMDevice | None = None, calibration_set_id: UUID | None = None, run_sweep_timeout: int | None = None, compiler_options: CircuitCompilationOptions | None = None, **user_auth_args)#

Bases: Sampler

Circuit sampler for executing quantum circuits on IQM quantum computers.

IQMSampler connects to a quantum computer through an IQM server. If the server requires user authentication, you can provide it either using environment variables, or as keyword arguments to IQMSampler. The user authentication kwargs are passed through to IQMClient as is, and are documented there.

Parameters:
  • url (str) – URL of the IQM server. Has to start with http or https.

  • device (Optional[IQMDevice]) – Device to execute the circuits on. If None, the device will be created based on the calibration-specific dynamic quantum architecture obtained from IQMClient.

  • calibration_set_id (Optional[UUID]) – ID of the calibration set to use. If None, use the default one.

  • run_sweep_timeout (Optional[int]) – Timeout for polling sweep results, in seconds. If None, use the client default value.

  • compiler_options (Optional[CircuitCompilationOptions]) – The compilation options to use for the circuits, as defined by IQM Client.

Attributes

device

Returns the device used by the sampler.

Methods

_resolve_parameters(program, params)

_send_circuits(circuits[, repetitions])

Sends a batch of circuits to be executed and retrieves the results.

close_client()

Close IQMClient's session with the user authentication server.

create_run_request(programs, *[, params, ...])

Creates a run request without submitting it for execution.

run_iqm_batch(programs[, repetitions])

Sends a batch of circuits to be executed.

run_sweep(program, params[, repetitions])

Samples from the given Circuit.

run_sweep_async(program, params[, repetitions])

Asynchronously samples from the given Circuit.

property device: IQMDevice#

Returns the device used by the sampler.

close_client()#

Close IQMClient’s session with the user authentication server. Discard the client.

run_sweep(program: Circuit, params: ParamResolver | Mapping[str | Expr, complex | float | Complex | Expr] | None | Sweep | _Sweepable, repetitions: int = 1) list[IQMResult]#

Samples from the given Circuit.

This allows for sweeping over different parameter values, unlike the run method. The params argument will provide a mapping from sympy.Symbol`s used within the circuit to a set of values. Unlike the `run method, which specifies a single mapping from symbol to value, this method allows a “sweep” of values. This allows a user to specify execution of a family of related circuits efficiently.

Parameters:
  • program (Circuit) – The circuit to sample from.

  • params (ParamResolver | Mapping[str | Expr, complex | float | Complex | Expr] | None | Sweep | _Sweepable) – Parameters to run with the program.

  • repetitions (int) – The number of times to sample.

Returns:

Result list for this run; one for each possible parameter resolver.

Return type:

list[IQMResult]

run_iqm_batch(programs: list[Circuit], repetitions: int = 1) list[IQMResult]#

Sends a batch of circuits to be executed.

Running circuits in a batch is more efficient and hence completes quicker than running the circuits individually. Circuits run in a batch must all measure the same qubits.

Parameters:
  • programs (list[Circuit]) – quantum circuits to execute

  • repetitions (int) – number of times the circuits are sampled

Returns:

results of the execution

Raises:
  • ValueError – circuits are not valid for execution

  • CircuitExecutionError – something went wrong on the server

  • APITimeoutError – server did not return the results in the allocated time

  • RuntimeError – IQM client session has been closed

Return type:

list[IQMResult]

create_run_request(programs: Circuit | list[Circuit], *, params: ParamResolver | Mapping[str | Expr, complex | float | Complex | Expr] | None | Sweep | _Sweepable = None, repetitions: int = 1) RunRequest#

Creates a run request without submitting it for execution.

This takes the same parameters as run() and run_iqm_batch(), and can be used to check the run request that would be sent when calling those functions.

Parameters:
  • programs (Circuit | list[Circuit]) – quantum circuit(s) that would be executed when submitting the run request

  • params (ParamResolver | Mapping[str | Expr, complex | float | Complex | Expr] | None | Sweep | _Sweepable) – same as params for run(), used only if programs is not a list

  • repetitions (int) – number of times the circuits are sampled

Returns:

the created run request

Return type:

RunRequest

run_sweep_async(program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1) Sequence[cirq.Result]#

Asynchronously samples from the given Circuit.

By default, this method invokes run_sweep synchronously and simply exposes its result is an awaitable. Child classes that are capable of true asynchronous sampling should override it to use other strategies.

Parameters:
  • program (cirq.AbstractCircuit) – The circuit to sample from.

  • params (cirq.Sweepable) – Parameters to run with the program.

  • repetitions (int) – The number of times to sample.

Returns:

Result list for this run; one for each possible parameter resolver.

Return type:

Sequence[cirq.Result]