quri_parts.core.estimator.sampling package#

quri_parts.core.estimator.sampling.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]

quri_parts.core.estimator.sampling.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]

quri_parts.core.estimator.sampling.general_pauli_expectation_estimator(counts: Mapping[int, int | float], pauli: PauliLabel, reconstructor_factory: Callable[[PauliLabel], Callable[[int], int]]) float#

An implementation of PauliExpectationEstimator for a given PauliReconstructorFactory.

quri_parts.core.estimator.sampling.general_pauli_sum_expectation_estimator(counts: Mapping[int, int | float], pauli_set: Set[PauliLabel], coefs: Mapping[PauliLabel, complex], reconstructor_factory: Callable[[PauliLabel], Callable[[int], int]]) complex#

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.

quri_parts.core.estimator.sampling.general_pauli_covariance_estimator(counts: Mapping[int, int | float], pauli1: PauliLabel, pauli2: PauliLabel, reconstructor_factory: Callable[[PauliLabel], Callable[[int], int]]) float#

An implementation of PauliCovarianceEstimator for a given PauliReconstructorFactory.

quri_parts.core.estimator.sampling.general_pauli_sum_sample_variance(counts: Mapping[int, int | float], pauli_set: Set[PauliLabel], coefs: Mapping[PauliLabel, complex], reconstructor_factory: Callable[[PauliLabel], Callable[[int], int]]) float#

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.

quri_parts.core.estimator.sampling.trivial_pauli_expectation_estimator(counts: Mapping[int, int | float], pauli: PauliLabel) float#

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.

quri_parts.core.estimator.sampling.trivial_pauli_covariance_estimator(counts: Mapping[int, int | float], pauli1: PauliLabel, pauli2: PauliLabel) float#

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.

quri_parts.core.estimator.sampling.sampling_estimate(op: Operator | PauliLabel, state: CircuitQuantumState, total_shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]], measurement_factory: Callable[[Operator | Iterable[PauliLabel]], Iterable[CommutablePauliSetMeasurement]], shots_allocator: Callable[[Operator, Collection[Set[PauliLabel]], int], Collection[PauliSamplingSetting]]) Estimate[complex]#

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 – An operator of which expectation value is estimated.

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

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

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

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

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

Returns:

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

of estimation (can be accessed with error).

quri_parts.core.estimator.sampling.create_sampling_estimator(total_shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]], measurement_factory: Callable[[Operator | Iterable[PauliLabel]], Iterable[CommutablePauliSetMeasurement]], shots_allocator: Callable[[Operator, Collection[Set[PauliLabel]], int], Collection[PauliSamplingSetting]]) Callable[[Operator | PauliLabel, CircuitQuantumState], Estimate[complex]]#

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

The sampling measurements are configured with arguments as follows.

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

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

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

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

quri_parts.core.estimator.sampling.concurrent_sampling_estimate(operators: Collection[Operator | PauliLabel], states: Collection[CircuitQuantumState], total_shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]], measurement_factory: Callable[[Operator | Iterable[PauliLabel]], Iterable[CommutablePauliSetMeasurement]], shots_allocator: Callable[[Operator, Collection[Set[PauliLabel]], int], Collection[PauliSamplingSetting]]) Iterable[Estimate[complex]]#

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

The sampling measurements are configured with arguments as follows.

Parameters:
  • operators – Operators of which expectation value is estimated.

  • states – Quantum states on which the operator expectation is evaluated.

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

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

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

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

Returns:

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

of estimation (can be accessed with error).

quri_parts.core.estimator.sampling.create_sampling_concurrent_estimator(total_shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]], measurement_factory: Callable[[Operator | Iterable[PauliLabel]], Iterable[CommutablePauliSetMeasurement]], shots_allocator: Callable[[Operator, Collection[Set[PauliLabel]], int], Collection[PauliSamplingSetting]]) Callable[[Sequence[Operator | PauliLabel], Sequence[CircuitQuantumState]], Iterable[Estimate[complex]]]#

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

The sampling measurements are configured with arguments as follows.

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

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

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

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

quri_parts.core.estimator.sampling.sampling_overlap_estimate(ket: CircuitQuantumState, bra: CircuitQuantumState, shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]]) Estimate[float]#

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 – The state whose direct circuit is used

  • bra – The state whose inverse circuit is used

Returns:

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

of estimation (can be accessed with error).

quri_parts.core.estimator.sampling.create_sampling_overlap_estimator(shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]]) Callable[[CircuitQuantumState, CircuitQuantumState], Estimate[float]]#

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 – Number of shots available for sampling measurements.

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

quri_parts.core.estimator.sampling.sampling_overlap_weighted_sum_estimate(kets: Sequence[CircuitQuantumState], bras: Sequence[CircuitQuantumState], weights: Sequence[complex], total_shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]], shots_allocator: Callable[[Sequence[complex], int], Sequence[int]]) Estimate[complex]#

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 – The states whose direct circuit is used

  • bras – The states whose inverse circuit is used

  • weights – Weights used in summing the overlaps

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

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

  • shots_allocator – 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).

quri_parts.core.estimator.sampling.create_sampling_overlap_weighted_sum_estimator(total_shots: int, sampler: Callable[[Iterable[tuple[NonParametricQuantumCircuit, int]]], Iterable[Mapping[int, int | float]]], shots_allocator: Callable[[Sequence[complex], int], Sequence[int]]) Callable[[Sequence[CircuitQuantumState], Sequence[CircuitQuantumState], Sequence[complex]], Estimate[complex]]#

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 – Total number of shots available for sampling measurements.

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

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

Submodules#