quri_parts.core.sampling package¶
- MeasurementCounts¶
MeasurementCounts represents count statistics of repeated measurements of a quantum circuit. Keys are observed bit patterns encoded in integers and values are counts of observation of the corresponding bit patterns.
alias of
Mapping[int,int|float]
- Sampler¶
Sampler represents a function that samples a specified (non-parametric) circuit by a specified times and returns the count statistics. In the case of an ideal Sampler, the return value corresponds to probabilities multiplied by shot count. Implementations should name the shot count parameter
shotsso it can be passed as a keyword argument.alias of
Callable[[ImmutableQuantumCircuit,int],Mapping[int,int|float]]
- ConcurrentSampler¶
ConcurrentSampler represents a function that samples specified (non-parametric) circuits concurrently.
alias of
Callable[[Iterable[tuple[ImmutableQuantumCircuit,int]]],Iterable[Mapping[int,int|float]]]
- ParametricSampler¶
ParametricSampler represents a sampler that samples from a parametric circuit with a fixed set of circuit parameters.
alias of
Callable[[ParametricQuantumCircuitProtocol,int,Sequence[float]],Mapping[int,int|float]]
- ConcurrentParametricSampler¶
ConcurrentParametricSampler represents a sampler that samples from a parametric circuit with a (shot, circuit parameter) pairs.
alias of
Callable[[ParametricQuantumCircuitProtocol,Iterable[tuple[int,Sequence[float]]]],Iterable[Mapping[int,int|float]]]
- StateSampler¶
StateSampler representes a function that samples a specific (non-parametric) state by specified times and returns the count statistics. In the case of an ideal StateSampler, the return value corresponds to probabilities multiplied by shot count. Implementations should name the shot count parameter
shotsso it can be passed as a keyword argument.alias of
Callable[[_StateT,int],Mapping[int,int|float]]
- ConcurrentStateSampler¶
ConcurrentSampler represents a function that samples specified (non-parametric) state by specified times and returns the count statistics concurrently.
alias of
Callable[[Iterable[tuple[_StateT,int]]],Iterable[Mapping[int,int|float]]]
- ParametricStateSampler¶
ParametricStateSampler represents a state sampler that samples from a parametric state with a fixed set of circuit parameters.
alias of
Callable[[_ParametricStateT,int,Sequence[float]],Mapping[int,int|float]]
- ConcurrentParametricStateSampler¶
ConcurrentParametricStateSampler represents a state sampler that samples from a parametric state with a sequence of (shot, circuit parameter) pairs.
alias of
Callable[[_ParametricStateT,Iterable[tuple[int,Sequence[float]]]],Iterable[Mapping[int,int|float]]]
- class GeneralSampler(sampler: 'Sampler', state_sampler: 'StateSampler[_StateT]')¶
Bases:
Generic[_StateT,_ParametricStateT]- Parameters:
sampler (Sampler)
state_sampler (StateSampler[_StateT])
- sampler: Sampler¶
- state_sampler: StateSampler[_StateT]¶
- parametric_sampler: ParametricSampler¶
- parametric_state_sampler: ParametricStateSampler[_ParametricStateT]¶
- create_parametric_sampler_from_sampler(sampler)¶
Create a
ParametricSamplerfrom aSampler.- Parameters:
sampler (core.sampling.Sampler)
- Return type:
core.sampling.ParametricSampler
- create_concurrent_parametric_sampler_from_concurrent_sampler(concurrent_sampler)¶
Create a
ConcurrentParametricSamplerfrom aConcurrentSampler.- Parameters:
concurrent_sampler (core.sampling.ConcurrentSampler)
- Return type:
core.sampling.ConcurrentParametricSampler
- create_parametric_state_sampler_from_state_sampler(state_sampler)¶
Create a
ParametricStateSamplerfrom aStateSampler.- Parameters:
state_sampler (StateSampler[_StateT])
- Return type:
ParametricStateSampler[_ParametricStateT]
- create_concurrent_parametric_state_sampler_from_concurrent_state_sampler(concurrent_state_sampler)¶
Create a
ConcurrentParametricStateSamplerfrom aConcurrentStateSampler.- Parameters:
concurrent_state_sampler (ConcurrentStateSampler[_StateT])
- Return type:
ConcurrentParametricStateSampler[_ParametricStateT]
- sample_from_probability_distribution(n_sample, probability_distribution, seed=None)¶
Sample from a probibility distribution.
- Parameters:
n_sample (int)
probability_distribution (Sequence[float] | ndarray[tuple[int, ...], dtype[float64]])
seed (int | None)
- Return type:
core.sampling.MeasurementCounts
- sample_from_state_vector(state_vector, shots, seed=None)¶
Perform sampling from a state vector.
- Parameters:
state_vector (ndarray[tuple[int, ...], dtype[complex128]])
shots (int)
seed (int | None)
- Return type:
core.sampling.MeasurementCounts
- ideal_sample_from_state_vector(state_vector, shots)¶
Perform ideal sampling from a state vector.
- Parameters:
state_vector (ndarray[tuple[int, ...], dtype[complex128]])
shots (int)
- Return type:
core.sampling.MeasurementCounts
- sample_from_density_matrix(density_matrix, shots)¶
- Parameters:
density_matrix (ndarray[tuple[int, ...], dtype[complex128]])
shots (int)
- Return type:
core.sampling.MeasurementCounts
- ideal_sample_from_density_matrix(density_matrix, shots)¶
- Parameters:
density_matrix (ndarray[tuple[int, ...], dtype[complex128]])
shots (int)
- Return type:
core.sampling.MeasurementCounts
- create_sampler_from_sampling_backend(backend)¶
Create a simple
Samplerusing aSamplingBackend.- Parameters:
backend (SamplingBackend)
- Return type:
core.sampling.Sampler
- create_concurrent_sampler_from_sampling_backend(backend)¶
Create a simple
ConcurrentSamplerusing aSamplingBackend.- Parameters:
backend (SamplingBackend)
- Return type:
core.sampling.ConcurrentSampler
- create_sampler_from_concurrent_sampler(concurrent_sampler)¶
- Parameters:
concurrent_sampler (core.sampling.ConcurrentSampler)
- Return type:
core.sampling.Sampler
- create_readout_error_concurrent_sampler(concurrent_sampler, p0_to_1, p1_to_0, seed=None)¶
Wrap a
ConcurrentSamplerto add independent per-qubit readout errors to each shot.Each measured bit flips from 0 to 1 with probability
p0_to_1and from 1 to 0 with probabilityp1_to_0. This is the classical readout error model with a per-qubit confusion matrix. Wrap a noise-free sampler to simulate readout errors with a single state simulation per circuit.- Parameters:
concurrent_sampler (core.sampling.ConcurrentSampler) – Sampler whose counts receive readout errors. The counts must be integers, so ideal samplers are not supported.
p0_to_1 (float | Sequence[float]) – Probability that a measured 0 reads as 1. Either one value for all qubits, or one value per qubit.
p1_to_0 (float | Sequence[float]) – Probability that a measured 1 reads as 0. Either one value for all qubits, or one value per qubit.
seed (int | None) – Seed for the readout error random numbers.
- Returns:
A
ConcurrentSamplerreturning counts with readout errors.- Return type:
core.sampling.ConcurrentSampler
- class PauliSamplingSetting(pauli_set, n_shots)¶
Bases:
NamedTuple- Parameters:
pauli_set (core.operator.pauli.CommutablePauliSet)
n_shots (int)
- pauli_set: CommutablePauliSet¶
Alias for field number 0
- n_shots: int¶
Alias for field number 1
- PauliSamplingShotsAllocator¶
PauliSamplingShotsAllocator represents a function that distributes a given number of sampling shots to each
CommutablePauliSet.alias of
Callable[[Operator,Collection[Set[PauliLabel]],int],Collection[PauliSamplingSetting]]
- WeightedSamplingShotsAllocator¶
WeightedSamplingShotsAllocator represents a function that distributes a given number of sampling shots based on a set of weights.
alias of
Callable[[Sequence[complex],int],Sequence[int]]