quri_parts.core.estimator.sampling package#

PauliExpectationEstimator#

PauliExpectationEstimator represents a function that receives a MeasurementCounts obtained from a sampling measurement and a PauliLabel, and returns an estimate of the expectation value (sample mean) of the pauli string.

alias of Callable[[Mapping[int, Union[int, float]], PauliLabel], float]

PauliCovarianceEstimator#

PauliCovarianceEstimator represents a function that receives a MeasurementCounts obtained from a sampling measurement and two PauliLabel’s, and returns an estimate of the covariance (sample covariance) of the two pauli strings. It is assumed that the two PauliLabel’s commute.

alias of Callable[[Mapping[int, Union[int, float]], PauliLabel, PauliLabel], float]

general_pauli_expectation_estimator(counts, pauli, reconstructor_factory)#

An implementation of PauliExpectationEstimator for a given PauliReconstructorFactory.

Parameters:
  • counts (core.sampling.MeasurementCounts) –

  • pauli (PauliLabel) –

  • reconstructor_factory (core.measurement.interface.PauliReconstructorFactory) –

Return type:

float

general_pauli_sum_expectation_estimator(counts, pauli_set, coefs, reconstructor_factory)#

Estimate expectation value of a weighted sum of commutable Pauli operators from measurement counts and Pauli reconstructor.

Note that this function calculates the sum for only Pauli operators contained in both of pauli_set and coefs.

Parameters:
  • counts (core.sampling.MeasurementCounts) –

  • pauli_set (core.operator.pauli.CommutablePauliSet) –

  • coefs (Mapping[PauliLabel, complex]) –

  • reconstructor_factory (core.measurement.interface.PauliReconstructorFactory) –

Return type:

complex

general_pauli_covariance_estimator(counts, pauli1, pauli2, reconstructor_factory)#

An implementation of PauliCovarianceEstimator for a given PauliReconstructorFactory.

Parameters:
  • counts (core.sampling.MeasurementCounts) –

  • pauli1 (PauliLabel) –

  • pauli2 (PauliLabel) –

  • reconstructor_factory (core.measurement.interface.PauliReconstructorFactory) –

Return type:

float

general_pauli_sum_sample_variance(counts, pauli_set, coefs, reconstructor_factory)#

Calculate sample variance of a weighted sum of commutable Pauli operators from measurement counts and Pauli reconstructor.

Note that this function calculates the variance of sum for only Pauli operators contained in both of pauli_set and coefs.

Parameters:
  • counts (core.sampling.MeasurementCounts) –

  • pauli_set (core.operator.pauli.CommutablePauliSet) –

  • coefs (Mapping[PauliLabel, complex]) –

  • reconstructor_factory (core.measurement.interface.PauliReconstructorFactory) –

Return type:

float

get_estimate_from_sampling_result(op, measurement_groups, const, sampling_counts)#

Converts sampling counts into the estimation of the operator’s expectation value.

Parameters:
Return type:

Estimate[complex]

trivial_pauli_expectation_estimator(counts, pauli)#

An implementation of PauliExpectationEstimator, which assumes a “trivial” measurement of the Pauli string.

The “trivial” measurement of a Pauli string refers to a measurement in computational basis preceded by single qubit rotations to map each Pauli matrix on each qubit to \(Z\). For example, if the Pauli string contains \(X\) (\(Y\)) at a qubit index \(i\), then (an \(S^\dagger\) gate and) an Hadamard gate is applied on the qubit \(i\) before performing the \(Z\) measurements on all qubits.

Parameters:
  • counts (core.sampling.MeasurementCounts) –

  • pauli (PauliLabel) –

Return type:

float

trivial_pauli_covariance_estimator(counts, pauli1, pauli2)#

An implementation of PauliCovarianceEstimator, which assumes a “trivial” measurement of the Pauli string.

The “trivial” measurement of a Pauli string refers to a measurement in computational basis preceded by single qubit rotations to map each Pauli matrix on each qubit to \(Z\). For example, if the Pauli string contains \(X\) (\(Y\)) at a qubit index \(i\), then (an \(S^\dagger\) gate and) an Hadamard gate is applied on the qubit \(i\) before performing the \(Z\) measurements on all qubits.

Parameters:
Return type:

float

sampling_estimate(op, state, total_shots, sampler, measurement_factory, shots_allocator, circuit_shot_pair_prep_fn=<function get_sampling_circuits_and_shots>)#

Estimate expectation value of a given operator with a given state by sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • op (core.estimator.Estimatable) – An operator of which expectation value is estimated.

  • state (CircuitQuantumState) – A quantum state on which the operator expectation is evaluated.

  • total_shots (int) – Total number of shots available for sampling measurements.

  • sampler (core.sampling.ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • measurement_factory (core.measurement.interface.CommutablePauliSetMeasurementFactory) – A function that performs Pauli grouping and returns a measurement scheme for Pauli operators constituting the original operator.

  • shots_allocator (core.sampling.PauliSamplingShotsAllocator) – A function that allocates the total shots to Pauli groups to be measured.

  • circuit_shot_pair_prep_fn (core.estimator.sampling.estimator_helpers.CircuitShotPairPreparationFunction) – A CircuitShotPairPreparationFunction that prepares the set of circuits to perform measurement with. It is default to a function that concatenates the measurement circuits after the state preparation circuit.

Returns:

The estimated value (can be accessed with value) with standard error

of estimation (can be accessed with error).

Return type:

Estimate[complex]

create_sampling_estimator(total_shots, sampler, measurement_factory, shots_allocator)#

Create a QuantumEstimator that estimates operator expectation value by sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • total_shots (int) – Total number of shots available for sampling measurements.

  • sampler (ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • measurement_factory (CommutablePauliSetMeasurementFactory) – A function that performs Pauli grouping and returns a measurement scheme for Pauli operators constituting the original operator.

  • shots_allocator (PauliSamplingShotsAllocator) – A function that allocates the total shots to Pauli groups to be measured.

Return type:

QuantumEstimator[CircuitQuantumState]

concurrent_sampling_estimate(operators, states, total_shots, sampler, measurement_factory, shots_allocator, circuit_shot_pair_prep_fn=<function get_sampling_circuits_and_shots>)#

Estimate expectation value of given operators with given states by sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • operators (Collection[core.estimator.Estimatable]) – Operators of which expectation value is estimated.

  • states (Collection[CircuitQuantumState]) – Quantum states on which the operator expectation is evaluated.

  • total_shots (int) – Total number of shots available for sampling measurements.

  • sampler (core.sampling.ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • measurement_factory (core.measurement.interface.CommutablePauliSetMeasurementFactory) – A function that performs Pauli grouping and returns a measurement scheme for Pauli operators constituting the original operator.

  • shots_allocator (core.sampling.PauliSamplingShotsAllocator) – A function that allocates the total shots to Pauli groups to be measured.

  • circuit_shot_pair_prep_fn (core.estimator.sampling.estimator_helpers.CircuitShotPairPreparationFunction) – A CircuitShotPairPreparationFunction that prepares the set of circuits to perform measurement with. It is default to a function that concatenates the measurement circuits after the state preparation circuit.

Returns:

The estimated values (can be accessed with value) with standard errors

of estimation (can be accessed with error).

Return type:

Iterable[Estimate[complex]]

create_sampling_concurrent_estimator(total_shots, sampler, measurement_factory, shots_allocator)#

Create a ConcurrentQuantumEstimator that estimates operator expectation value by sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • total_shots (int) – Total number of shots available for sampling measurements.

  • sampler (ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • measurement_factory (CommutablePauliSetMeasurementFactory) – A function that performs Pauli grouping and returns a measurement scheme for Pauli operators constituting the original operator.

  • shots_allocator (PauliSamplingShotsAllocator) – A function that allocates the total shots to Pauli groups to be measured.

Return type:

ConcurrentQuantumEstimator[CircuitQuantumState]

sampling_overlap_estimate(ket, bra, shots, sampler)#

Estimate the magnitude squared overlap of a pair of quantum states by sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • ket (CircuitQuantumState) – The state whose direct circuit is used

  • bra (CircuitQuantumState) – The state whose inverse circuit is used

  • shots (int) –

  • sampler (core.sampling.ConcurrentSampler) –

Returns:

The estimated value (can be accessed with value) with standard error

of estimation (can be accessed with error).

Return type:

Estimate[float]

create_sampling_overlap_estimator(shots, sampler)#

Create a OverlapEstimator that estimates the squared magnitude of the overlap of a pair of wavefunctions by sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • shots (int) – Number of shots available for sampling measurements.

  • sampler (ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

Return type:

OverlapEstimator[CircuitQuantumState]

sampling_overlap_weighted_sum_estimate(kets, bras, weights, total_shots, sampler, shots_allocator)#

Estimate the weighted sum of magnitude squared overlaps of pairs of quantum states by a sampling measurement.

The sampling measurements are configured with arguments as follows.

Parameters:
  • kets (Sequence[CircuitQuantumState]) – The states whose direct circuit is used

  • bras (Sequence[CircuitQuantumState]) – The states whose inverse circuit is used

  • weights (Sequence[complex]) – Weights used in summing the overlaps

  • total_shots (int) – Total number of shots used for sampling measurements.

  • sampler (core.sampling.ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • shots_allocator (core.sampling.WeightedSamplingShotsAllocator) – shot allocator which takes weights as an argument.

Returns:

The estimated value (can be accessed with value) with standard error

of estimation (can be accessed with error).

Return type:

Estimate[complex]

create_sampling_overlap_weighted_sum_estimator(total_shots, sampler, shots_allocator)#

Create a OverlapWeightedSumEstimator that estimates the squared magnitude of the overlap of pairs of wavefunctions by sampling measurement and returns a weighted sum.

The sampling measurements are configured with arguments as follows.

Parameters:
  • total_shots (int) – Total number of shots available for sampling measurements.

  • sampler (ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • shots_allocator (WeightedSamplingShotsAllocator) – shot allocator which takes weights as an argument.

Return type:

OverlapWeightedSumEstimator[CircuitQuantumState]

get_sampling_circuits_and_shots(state, measurement_groups, shots_map)#

Sets up the (circuit, shot) pairs for performing sampling estimation. The circuit is given by the measurement circuit concatenated after the circuit held inside the state.

Parameters:
  • state (CircuitQuantumState) – The state on which the expectation value is estimated.

  • measurement_groups (Iterable[CommutablePauliSetMeasurement]) – Sequence of CommutablePauliSetMeasurement that corresponds to the grouping result of the operator.

  • shots_map (dict[core.operator.pauli.CommutablePauliSet, int]) – A dictionary whose key is the commuting pauli set and the value is the shot count assigned to the commuting pauli set.

Return type:

Iterable[tuple[NonParametricQuantumCircuit, int]]

distribute_shots_among_pauli_sets(operator, measurement_groups, shots_allocator, total_shots)#

Distribute shots to each commuting pauli sets.

Parameters:
  • operator (Operator) – The operator to be measured.

  • measurement_groups (Iterable[CommutablePauliSetMeasurement]) – Sequence of CommutablePauliSetMeasurement that corresponds to the grouping result of the operator.

  • shot_allocator – A function that allocates the total shots to Pauli groups to be measured.

  • total_shots (int) – Total number of shots available for sampling measurements.

  • shots_allocator (core.sampling.PauliSamplingShotsAllocator) –

Return type:

dict[core.operator.pauli.CommutablePauliSet, int]

create_general_sampling_estimator(total_shots, sampler, measurement_factory, shots_allocator)#

Creates a GeneralQuantumEstimator that performs sampling estimation.

Parameters:
  • total_shots (int) – Total number of shots available for sampling measurements.

  • sampler (core.sampling.ConcurrentSampler) – A Sampler that actually performs the sampling measurements.

  • measurement_factory (core.measurement.interface.CommutablePauliSetMeasurementFactory) – A function that performs Pauli grouping and returns a measurement scheme for Pauli operators constituting the original operator.

  • shots_allocator (core.sampling.PauliSamplingShotsAllocator) – A function that allocates the total shots to Pauli groups to be measured.

Return type:

GeneralQuantumEstimator[CircuitQuantumState, ParametricCircuitQuantumState]

Submodules#