mimiqcircuits.backends.remote

Concrete RemoteBackend for the MIMIQ cloud service.

MimiqRemoteBackend wraps a mimiqcircuits.remote.RemoteConnection so cloud execution looks like every other backend: it advertises a capability set, accepts the same seed / rng / passes arguments as the local simulators, and returns the same mimiqcircuits.QCSResults. Submit-level options like bonddim / mpscutoff are forwarded to MimiqRemoteBackend.submit().

Classes

MimiqRemoteBackend(connection, *[, ...])

Backend that runs circuits on the MIMIQ cloud service.

class MimiqRemoteBackend(connection, *, algorithm='auto', label=None, poll_interval=1.0)[source]

Bases: RemoteBackend

Backend that runs circuits on the MIMIQ cloud service.

It wraps a MimiqConnection (or another mimiqcircuits.remote.RemoteConnection) so that cloud execution takes the same seed, rng and passes arguments as a local backend and returns the same QCSResults. The simulator algorithm is fixed at construction; the other server options (bonddim, entdim, mpscutoff, mpsmethod, mpotraversal, timelimit, noisemodel) are given to execute() or submit().

Parameters:
  • connection – An authenticated connection, or any object with callable submit(...) and get_results(...) methods. The constructor does not log in, so call connection.connect() first.

  • algorithm (str) – "auto", "mps" or "statevector". It also sets capabilities() and limits().

  • label (Optional[str]) – Label of the jobs on the service. Defaults to "pyapi_remote_backend".

  • poll_interval (float) – Seconds between two checks of a running job.

Raises:

TypeError – If connection lacks submit or get_results.

Notes

  1. The capabilities are decided on the client, since the service does not report them: a fixed set, plus "bond_dim" and "schmidt_rank" when algorithm is "auto" or "mps".

  2. "pass_order_honored" is not declared, because the service takes a flat set of options (remove_swaps, fuse, …), not an ordered pipeline. A non-empty passes with the default strict_pass_order=True raises RemotePassOrderError. With strict_pass_order=False the passes the service knows are translated into options, and the others are dropped with one UserWarning.

  3. param_grid raises NotImplementedError. Evaluate the circuit for each point and execute the results instead.

  4. noisemodel= together with a pass named "apply_noise_model" in passes raises ValueError.

  5. seed and rng are mutually exclusive. The seed sent to the service is derived from them through an RNGs bundle, so it is not the integer passed in.

  6. A single circuit returns a single QCSResults; a list returns a list of the same length. A list of more than one circuit needs algorithm set to "mps" or "statevector"; with "auto" it raises ValueError.

  7. With algorithm="statevector", a noisemodel fails on the service, and the MPS options (bonddim, entdim, mpscutoff, mpsmethod, mpotraversal) have no effect. They are still sent; the backend does not reject them for this algorithm.

  8. execute() waits for the job without a time limit. For a bounded wait, call submit() and then job.wait(timeout=seconds), which raises TimeoutError.

Examples

>>> from mimiqcircuits import *
>>> from mimiqcircuits.backends import MimiqRemoteBackend

Log in once, then wrap the connection in a backend that uses the MPS simulator.

>>> conn = MimiqConnection()
>>> conn.connect()  
>>> backend = MimiqRemoteBackend(conn, algorithm="mps")

Run a Bell circuit; bonddim is an option of the service.

>>> c = Circuit().push(GateH(), 0).push(GateCX(), 0, 1)
>>> c.push(Measure(), range(2), range(2))  
2-qubit, 2-bit circuit with 4 instructions:
...
>>> res = backend.execute(c, nsamples=1000, seed=42, bonddim=64)  
>>> res.histogram()  
property name: str

"Mimiq".

property version: str

The version of the mimiqcircuits package.

capabilities()[source]

Return the capabilities, decided on the client.

"bond_dim" and "schmidt_rank" are included only when algorithm is "auto" or "mps".

limits()[source]

Return the limits known to the client.

max_samples is the largest number of shots the client sends; max_bond_dim is set only when algorithm is "auto" or "mps".

topology()[source]

Return AllToAll.

submit(circuits, nsamples=1000, *, rngs=None, passes=None, callback=None, param_grid=None, strict_pass_order=True, fuse=None, reorderqubits=None, canonicaldecompose=None, remove_swaps=None, reorderqubits_seed=None, bonddim=None, entdim=None, mpscutoff=None, mpsmethod=None, mpotraversal=None, timelimit=None, noisemodel=None, **kwargs)[source]

Submit circuits to the service without waiting.

execute() calls it; call it directly to wait with a time limit.

Parameters:
  • circuits – A circuit or a list of circuits.

  • nsamples (int) – Number of shots.

  • rngs – An RNGs bundle or an integer seed, folded into the single seed sent to the service; None draws a random seed.

  • passes (PassPipeline | None) – A PassPipeline. See the class notes for how it is handled.

  • callback – Accepted for compatibility with RemoteBackend.submit(); not used.

  • param_grid (list[dict] | None) – Must be empty or None.

  • strict_pass_order (bool) – See Backend.execute().

  • fuse (bool | None) – Server-side gate fusion; None lets the service choose.

  • reorderqubits – Server-side qubit reordering, as a bool or a method name.

  • canonicaldecompose (bool | None) – Server-side decomposition into the canonical gate set.

  • remove_swaps (bool | None) – Server-side SWAP removal.

  • reorderqubits_seed (int | None) – Seed of the server-side reordering.

  • bonddim (int | None) – Bond dimension of the MPS simulator.

  • entdim (int | None) – Entanglement dimension of the MPS simulator.

  • mpscutoff (float | None) – Singular-value cutoff of the MPS simulator.

  • mpsmethod (str | None) – MPO application method of the MPS simulator.

  • mpotraversal (str | None) – MPO compression traversal of the MPS simulator.

  • timelimit (int | None) – Time limit of the job, in minutes.

  • noisemodel – A NoiseModel applied to each circuit before it is uploaded.

  • **kwargs – Only simplify and mapping, which must be falsy: the service runs neither, and its topology is AllToAll.

Returns:

A job handle. Its request_id is the service’s job id, and its wait(timeout=None) blocks until the job is done and returns the list of QCSResults, with their fidelities converted to Fidelity types (exact for the state-vector simulator, a truncation lower bound for MPS, unknown otherwise). With a timeout in seconds it raises TimeoutError instead of waiting longer.

Raises:
Return type:

_MimiqJob

execute(circuit, *, nsamples=1000, seed=None, rng=None, passes=None, callback=None, param_grid=None, strict_pass_order=True, **kwargs)[source]

Submit circuit to the service and wait for the results.

To request specific amplitudes, push Amplitude instructions into circuit and read results.zstates.

Parameters:
  • circuit – A circuit or a list of circuits.

  • nsamples (int) – Number of shots.

  • seed (int | None) – Integer seed. Mutually exclusive with rng; with neither, a fresh seed is drawn.

  • rng – A random.Random to draw the seed from.

  • passes (PassPipeline | None) – See the class notes.

  • callback – Not used.

  • param_grid (list[dict] | None) – Must be empty or None.

  • strict_pass_order (bool) – See Backend.execute().

  • **kwargs – Preparation flags and service options, passed to submit(): fuse, reorderqubits, canonicaldecompose, remove_swaps, reorderqubits_seed, mapping, bonddim, entdim, mpscutoff, mpsmethod, mpotraversal, timelimit, noisemodel.

Returns:

A QCSResults for a single circuit, or a list of them for a list of circuits.

Raises:
optimize(experiment, initparams=None, *, return_history=False, seed=None, rng=None, **kwargs)[source]

Run optimization experiments on the service and wait for the results.

Takes the same experiment arguments as LocalBackend.optimize(): an OptimizationExperiment, a list of them, or a circuit with its initial values and the experiment fields (optimizer, maxiters, zregister, label) as keywords. The service runs the optimizer with the backend’s algorithm.

Parameters:
  • experiment – An OptimizationExperiment, a list of them, or a symbolic circuit.

  • initparams – Initial values when experiment is a circuit.

  • return_history (bool) – Also return every evaluated run.

  • seed (int | None) – Integer seed. Mutually exclusive with rng.

  • rng – A random.Random to draw the seed from.

  • **kwargs – Experiment fields (with a circuit only), and options of the connection’s optimize: nsamples, timelimit, bonddim, entdim, mpscutoff, fuse, reorderqubits, reorderqubits_seed, canonicaldecompose, remove_swaps, mpsmethod, mpotraversal, streaming.

Returns:

An OptimizationResults, or a list of them for a list of experiments.

Raises:
  • TypeError – If the connection has no optimize method, or both seed and rng are given.

  • ValueError – For more than one experiment with algorithm="auto"; use "mps" or "statevector".

Examples

>>> from mimiqcircuits import *
>>> from mimiqcircuits.backends import MimiqRemoteBackend
>>> from symengine import symbols
>>> theta = symbols("theta")
>>> c = Circuit().push(GateRY(theta), 0)
>>> c.push(ExpectationValue(GateZ()), 0, 0)  
1-qubit, 1-zvar circuit with 2 instructions:
...
>>> conn = MimiqConnection()
>>> conn.connect()  
>>> backend = MimiqRemoteBackend(conn, algorithm="statevector")
>>> res = backend.optimize(c, {theta: 0.1}, optimizer="COBYLA")  
>>> res.get_best().cost