StatevectorEstimator
class qiskit.primitives.StatevectorEstimator(*, default_precision=0.0, seed=None)
베이스: BaseEstimatorV2
간단한 구현 BaseEstimatorV2 를 간단하게 구현합니다.
이 클래스는 다음을 통해 구현됩니다 Statevector 를 통해 구현되며, 제공된 회로를 순수 상태 벡터로 변환합니다. 이러한 상태는 이후에 SparsePauliOp에 의해 처리되는데, 이는 현재 이 구현이 폴리 기반 옵저버와만 호환된다는 것을 의미합니다.
각 튜플은 추정기 원시 통합 블록( PUB(circuit, observables, <optional> parameter values, <optional> precision))이라 불리며, 자체적인 배열 기반 결과를 생성합니다. 해당 run() 메서드는 한 번의 호출로 실행할 펍들의 시퀀스를 전달받을 수 있습니다.
이 클래스의 결과는 회로가 단일 연산만을 포함할 경우 정확하다. 반면, 회로에 일부 하위 시스템에 대한 리셋과 같은 비유니티 연산이 포함된 경우 결과는 확률적일 수 있다. 확률적 결과는 예를 들어 를 seed설정함으로써 재현 StatevectorEstimator(seed=123)가능하게 만들 수 있다.
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.primitives import StatevectorEstimator
from qiskit.quantum_info import Pauli, SparsePauliOp
import matplotlib.pyplot as plt
import numpy as np
# Define a circuit with two parameters.
circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.ry(Parameter("a"), 0)
circuit.rz(Parameter("b"), 0)
circuit.cx(0, 1)
circuit.h(0)
# Define a sweep over parameter values, where the second axis is over
# the two parameters in the circuit.
params = np.vstack([
np.linspace(-np.pi, np.pi, 100),
np.linspace(-4 * np.pi, 4 * np.pi, 100)
]).T
# Define three observables. Many formats are supported here including
# classes such as qiskit.quantum_info.SparsePauliOp. The inner length-1
# lists cause this array of observables to have shape (3, 1), rather
# than shape (3,) if they were omitted.
observables = [
[SparsePauliOp(["XX", "IY"], [0.5, 0.5])],
[Pauli("XX")],
[Pauli("IY")]
]
# Instantiate a new statevector simulation based estimator object.
estimator = StatevectorEstimator()
# Estimate the expectation value for all 300 combinations of
# observables and parameter values, where the pub result will have
# shape (3, 100). This shape is due to our array of parameter
# bindings having shape (100,), combined with our array of observables
# having shape (3, 1)
pub = (circuit, observables, params)
job = estimator.run([pub])
# Extract the result for the 0th pub (this example only has one pub).
result = job.result()[0]
# Error-bar information is also available, but the error is 0
# for this StatevectorEstimator.
result.data.stds
# Pull out the array-based expectation value estimate data from the
# result and plot a trace for each observable.
for idx, pauli in enumerate(observables):
plt.plot(result.data.evs[idx], label=pauli)
plt.legend()
매개변수
- default_precision (float) – 실행 중에 지정하지 않은 경우 추정기의 기본 정밀도입니다.
- seed (np.random.Generator | int | None) – 난수 생성을 위한 시드 또는 생성기 객체입니다. 없음인 경우 무작위로 시드된 기본 RNG가 사용됩니다.
속성
default_precision
기본 정밀도 반환
seed
난수 생성을 위해 시드 또는 생성기 객체를 반환합니다.
메소드
run
run(pubs, *, precision=None)
제공된 각 퍼블릭(프리미티브 통합 블록)에 대한 기대치를 추정합니다.
매개변수
- pubs (Iterable[TypeAliasForwardRef('EstimatorPubLike')]) – 튜플이나
(circuit, observables)와 같은 pub과 유사한 객체들로(circuit, observables, parameter_values)구성된 반복 가능한 객체. - precision (float | None) – 자체 정밀도를 지정하지 않은 각 실행 추정기 게시물의 예상값 추정 목표 정밀도입니다. 없음인 경우 추정기의 기본 정밀도 값이 사용됩니다.
리턴
결과가 포함된 작업 개체입니다.
리턴 유형
PrimitiveJob [ PrimitiveResult [ PubResult ]]