Primitives#
See Primitives for how they are used. Each primitive’s run() hands
back a job, the job’s result() a result with one entry per input circuit.
Estimator#
- class QCut.CutEstimator(backend)[source]#
Bases:
objectExpectation values of cut circuits, run on any backend or sampler.
Shaped like FiQCI-EMS’s estimator: made once for a backend, then
run()with the cut circuits and the observables to estimate on them. A cut circuit comes fromQCut.get_locations_and_subcircuits()orQCut.find_cuts(), and is run with the options it was made with.The estimator does not transpile, much as qiskit’s primitives take circuits already written for their target. For a backend with a coupling map, transpile each cut circuit for that same backend with
QCut.transpile_subcircuits()first.- Parameters:
backend – the backend or V2 sampler to run on. A sampler, like a backend without a coupling map, takes the circuits as they are.
- run(circuits: CutCircuit | list[CutCircuit], observables: str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | _NestedSequence[complex | bytes | str] | list[str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | _NestedSequence[complex | bytes | str]], shots: int = 4096, max_batch_size: int = 100, parameter_values: dict | list[dict] | None = None, **run_options) CutEstimatorJob[source]#
Submit the circuits and return without waiting for their results.
- Parameters:
circuits – a cut circuit or a list of them.
observables – what to estimate, taken as qiskit’s estimator takes them – a label, a
Pauli, aSparsePauliOp, aSparseObservable, a{label: coefficient}mapping, or a nested sequence of those. One circuit takes them as given. With a list of circuits, give a list with one entry per circuit, or one observable for every circuit.shots (int) – shots per experiment circuit, as in
QCut.submit_experiments().max_batch_size (int) – the most circuits submitted in one
runcall. Each input circuit is submitted in batches of its own.parameter_values –
{parameter or name: value}to bind into the circuit, paired with the circuits the wayobservablesis. For a sweep, list the same circuit once per set of values.**run_options – passed on to every
runcall on the backend.
- Returns:
a handle on every circuit’s experiment, whose
result()gives the expectation values.- Return type:
- Raises:
QCutError – something other than a cut circuit was given, one is not transpiled for this backend although it has a coupling map, or one has parameters left unbound.
ValueError – the observables or parameter values do not have one entry per circuit, or the observables do not fit their circuit.
- estimate(circuits: CutCircuit | list[CutCircuit], observables: str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | _NestedSequence[complex | bytes | str] | list[str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | _NestedSequence[complex | bytes | str]], shots: int = 4096, max_batch_size: int = 100, parameter_values: dict | list[dict] | None = None) CutRunEstimate[source]#
Work out what
run()will cost with the same arguments, submitting nothing.- Returns:
the jobs, circuits and shots of the whole run, and indexed by circuit, each circuit’s own share.
- Return type:
- class QCut.primitives.CutEstimatorJob(jobs: list[QCutJob])[source]#
Bases:
QCutPrimitiveJob[CutEstimatorResult]A
CutEstimatorrun, whoseresult()is aCutEstimatorResult.
- class QCut.primitives.CutEstimatorResult(entries: list)[source]#
Bases:
SequenceWhat a
CutEstimatorrun gives back: one entry per input circuit.
- class QCut.primitives.CutEstimatorEntry(expectation_values: ndarray, standard_errors: ndarray, raw: RawResult)[source]#
Bases:
objectThe expectation values of one input circuit.
- expectation_values: ndarray#
One value per observable, shaped like the observables given for the circuit. A single observable gives a zero-dimensional array.
- standard_errors: ndarray#
An upper bound on each value’s shot noise, shaped the same. See
QCut.estimate_standard_errors().
Sampler#
- class QCut.CutQuasiSampler(backend)[source]#
Bases:
objectQuasi-probability distributions of cut circuits, run on any backend or sampler.
Shaped like FiQCI-EMS’s sampler, but what comes back is reconstructed rather than counted: a quasi-probability distribution over the measured bits, which can dip below zero by the estimate’s noise. The qubits are the ones the circuit measured at its end before it was cut, and the bitstrings follow qiskit’s convention, classical bit zero rightmost.
A cut circuit comes from
QCut.get_locations_and_subcircuits()orQCut.find_cuts(), and is run with the options it was made with. The sampler does not transpile: for a backend with a coupling map, transpile each cut circuit for that same backend withQCut.transpile_subcircuits()first.- Parameters:
backend – the backend or V2 sampler to run on. A sampler, like a backend without a coupling map, takes the circuits as they are.
- run(circuits: CutCircuit | list[CutCircuit], shots: int = 4096, max_batch_size: int = 100, parameter_values: dict | list[dict] | None = None, **run_options) CutQuasiSamplerJob[source]#
Submit the circuits and return without waiting for their results.
- Parameters:
circuits – a cut circuit or a list of them, each split from a circuit that ended in the measurements whose distribution is wanted, measuring into every classical bit exactly once.
shots (int) – shots per experiment circuit, as in
QCut.submit_experiments().max_batch_size (int) – the most circuits submitted in one
runcall. Each input circuit is submitted in batches of its own.parameter_values –
{parameter or name: value}to bind into the circuit. With a list of circuits, a list with one entry per circuit, or one for every circuit. For a sweep, list the same circuit once per set of values.**run_options – passed on to every
runcall on the backend.
- Returns:
a handle on every circuit’s experiment, whose
result()gives the distributions.- Return type:
- Raises:
QCutError – something other than a cut circuit was given, one is not transpiled for this backend although it has a coupling map, has parameters left unbound, or its final measurements do not fill its classical bits once each.
ValueError – the parameter values do not have one entry per circuit.
- estimate(circuits: CutCircuit | list[CutCircuit], shots: int = 4096, max_batch_size: int = 100, parameter_values: dict | list[dict] | None = None) CutRunEstimate[source]#
Work out what
run()will cost with the same arguments, submitting nothing.- Returns:
the jobs, circuits and shots of the whole run, and indexed by circuit, each circuit’s own share.
- Return type:
- class QCut.primitives.CutQuasiSamplerJob(jobs: list[QCutJob])[source]#
Bases:
QCutPrimitiveJob[CutQuasiSamplerResult]A
CutQuasiSamplerrun.result()gives aCutQuasiSamplerResult.- quasi_probabilities(index: int | None = None) list[QuasiProbabilities] | QuasiProbabilities[source]#
Wait for the run and return the distributions.
- Parameters:
index (int) – the input circuit to return it for, or
Nonefor every circuit’s, in the order the circuits were given.
- class QCut.primitives.CutQuasiSamplerResult(entries: list)[source]#
Bases:
SequenceWhat a
CutQuasiSamplerrun gives back: one entry per input circuit.- quasi_probabilities() list[QuasiProbabilities][source]#
Every circuit’s distribution, in the order the circuits were given.
- quasi_dists(top: int | None = None) list[QuasiDistribution][source]#
Every circuit’s distribution as a qiskit
QuasiDistribution.- Parameters:
top (int) – as in
CutQuasiSamplerEntry.quasi_dist().
- class QCut.primitives.CutQuasiSamplerEntry(quasi_probabilities: QuasiProbabilities, raw: RawResult)[source]#
Bases:
objectThe reconstructed distribution of one input circuit.
- quasi_probabilities: QuasiProbabilities#
The distribution over the measured bits, built lazily.
- property standard_error: float | None#
An upper bound on each quasi-probability’s shot noise, the same for all.
- quasi_dist(top: int | None = None) QuasiDistribution[source]#
The distribution as a qiskit
QuasiDistribution.- Parameters:
top (int) – keep only this many of the most likely outcomes.
None, the default, keeps all2**nof them, which for many measured bits is expensive;quasi_probabilitiesanswers without expanding.
- __init__(quasi_probabilities: QuasiProbabilities, raw: RawResult) None#