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
|
Backend that runs circuits on the MIMIQ cloud service. |
- class MimiqRemoteBackend(connection, *, algorithm='auto', label=None, poll_interval=1.0)[source]¶
Bases:
RemoteBackendBackend that runs circuits on the MIMIQ cloud service.
It wraps a
MimiqConnection(or anothermimiqcircuits.remote.RemoteConnection) so that cloud execution takes the sameseed,rngandpassesarguments as a local backend and returns the sameQCSResults. The simulator algorithm is fixed at construction; the other server options (bonddim,entdim,mpscutoff,mpsmethod,mpotraversal,timelimit,noisemodel) are given toexecute()orsubmit().- Parameters:
connection – An authenticated connection, or any object with callable
submit(...)andget_results(...)methods. The constructor does not log in, so callconnection.connect()first.algorithm (str) –
"auto","mps"or"statevector". It also setscapabilities()andlimits().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
connectionlackssubmitorget_results.
Notes
The capabilities are decided on the client, since the service does not report them: a fixed set, plus
"bond_dim"and"schmidt_rank"whenalgorithmis"auto"or"mps"."pass_order_honored"is not declared, because the service takes a flat set of options (remove_swaps,fuse, …), not an ordered pipeline. A non-emptypasseswith the defaultstrict_pass_order=TrueraisesRemotePassOrderError. Withstrict_pass_order=Falsethe passes the service knows are translated into options, and the others are dropped with oneUserWarning.param_gridraisesNotImplementedError. Evaluate the circuit for each point and execute the results instead.noisemodel=together with a pass named"apply_noise_model"inpassesraisesValueError.seedandrngare mutually exclusive. The seed sent to the service is derived from them through anRNGsbundle, so it is not the integer passed in.A single circuit returns a single
QCSResults; a list returns a list of the same length. A list of more than one circuit needsalgorithmset to"mps"or"statevector"; with"auto"it raisesValueError.With
algorithm="statevector", anoisemodelfails 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.execute()waits for the job without a time limit. For a bounded wait, callsubmit()and thenjob.wait(timeout=seconds), which raisesTimeoutError.
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;
bonddimis 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()
- capabilities()[source]¶
Return the capabilities, decided on the client.
"bond_dim"and"schmidt_rank"are included only whenalgorithmis"auto"or"mps".
- limits()[source]¶
Return the limits known to the client.
max_samplesis the largest number of shots the client sends;max_bond_dimis set only whenalgorithmis"auto"or"mps".
- 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
circuitsto 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
RNGsbundle or an integer seed, folded into the single seed sent to the service;Nonedraws 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.strict_pass_order (bool) – See
Backend.execute().fuse (bool | None) – Server-side gate fusion;
Nonelets 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
NoiseModelapplied to each circuit before it is uploaded.**kwargs – Only
simplifyandmapping, which must be falsy: the service runs neither, and its topology isAllToAll.
- Returns:
A job handle. Its
request_idis the service’s job id, and itswait(timeout=None)blocks until the job is done and returns the list ofQCSResults, with their fidelities converted toFidelitytypes (exact for the state-vector simulator, a truncation lower bound for MPS, unknown otherwise). With atimeoutin seconds it raisesTimeoutErrorinstead of waiting longer.- Raises:
ValueError – If a preparation flag is given with a non-empty
passes, ornoisemodelwith a pass named"apply_noise_model".NotImplementedError – If
param_gridis not empty, orsimplifyis set.ValueError – If
mappingis set.RemotePassOrderError – See
strict_pass_order.TypeError – For an unknown keyword.
- 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
circuitto the service and wait for the results.To request specific amplitudes, push
Amplitudeinstructions intocircuitand readresults.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.Randomto draw the seed from.passes (PassPipeline | None) – See the class notes.
callback – Not used.
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
QCSResultsfor a single circuit, or a list of them for a list of circuits.- Raises:
TypeError – If both
seedandrngare given, or for an unknown keyword.ValueError – See
submit().NotImplementedError – See
submit().RemotePassOrderError – See
strict_pass_order.
- 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(): anOptimizationExperiment, 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’salgorithm.- Parameters:
experiment – An
OptimizationExperiment, a list of them, or a symbolic circuit.initparams – Initial values when
experimentis a circuit.return_history (bool) – Also return every evaluated run.
seed (int | None) – Integer seed. Mutually exclusive with
rng.rng – A
random.Randomto 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
optimizemethod, or bothseedandrngare 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