StatevectorSampler
class qiskit.primitives.StatevectorSampler(*, default_shots=1024, seed=None)
베이스: BaseSamplerV2
간단한 구현 BaseSamplerV2 을 간단하게 구현합니다.
이 클래스는 다음을 통해 구현됩니다 Statevector 를 통해 구현되며, 제공된 회로를 순수 상태 벡터로 변환하므로 중간 회로 측정과 호환되지 않습니다(다른 구현은 가능하지만).
아래 예시에서 볼 수 있듯이 이 샘플러는 단일 회로에 바인딩할 파라미터 값 세트의 배열을 제공하는 기능을 지원합니다.
샘플러 프리미티브 통합 블록( PUB )이라고 하는 (circuit, <optional> parameter values, <optional> shots) 의 각 튜플은 자체 배열 값 결과를 생성합니다. 메서드 run() 메서드는 한 번에 여러 개의 퍼브를 지정할 수 있습니다.
from qiskit.circuit import (
Parameter, QuantumCircuit, ClassicalRegister, QuantumRegister
)
from qiskit.primitives import StatevectorSampler
import matplotlib.pyplot as plt
import numpy as np
# Define our circuit registers, including classical registers
# called 'alpha' and 'beta'.
qreg = QuantumRegister(3)
alpha = ClassicalRegister(2, "alpha")
beta = ClassicalRegister(1, "beta")
# Define a quantum circuit with two parameters.
circuit = QuantumCircuit(qreg, alpha, beta)
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(1, 2)
circuit.ry(Parameter("a"), 0)
circuit.rz(Parameter("b"), 0)
circuit.cx(1, 2)
circuit.cx(0, 1)
circuit.h(0)
circuit.measure([0, 1], alpha)
circuit.measure([2], beta)
# 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
# Instantiate a new statevector simulation based sampler object.
sampler = StatevectorSampler()
# Start a job that will return shots for all 100 parameter value sets.
pub = (circuit, params)
job = sampler.run([pub], shots=256)
# Extract the result for the 0th pub (this example only has one pub).
result = job.result()[0]
# There is one BitArray object for each ClassicalRegister in the
# circuit. Here, we can see that the BitArray for alpha contains data
# for all 100 sweep points, and that it is indeed storing data for 2
# bits over 256 shots.
assert result.data.alpha.shape == (100,)
assert result.data.alpha.num_bits == 2
assert result.data.alpha.num_shots == 256
# We can work directly with a binary array in performant applications.
raw = result.data.alpha.array
# For small registers where it is anticipated to have many counts
# associated with the same bitstrings, we can turn the data from,
# for example, the 22nd sweep index into a dictionary of counts.
counts = result.data.alpha.get_counts(22)
# Or, convert into a list of bitstrings that preserve shot order.
bitstrings = result.data.alpha.get_bitstrings(22)
print(bitstrings)매개변수
- default_shots (int) – 실행 중에 지정하지 않은 경우 샘플러의 기본 샷입니다.
- seed (np.random.Generator | int | None) – 난수 생성을 위한 시드 또는 생성기 객체입니다. 없음인 경우 무작위로 시드된 기본 RNG가 사용됩니다.
속성
default_shots
기본 샷 반환
seed
난수 생성을 위해 시드 또는 생성기 객체를 반환합니다.
메소드
run
run(pubs, *, shots=None)
각 펍에서 샘플을 실행하고 수집합니다.
매개변수
- pubs (Iterable[TypeAliasForwardRef('SamplerPubLike')]) – 펍과 유사한 객체들의 반복 가능 객체. 예를 들어, 회로 목록이나 튜플 목록
(circuit, parameter_values). - shots (int | None) – 자체 샷을 지정하지 않은 각 샘플러 펍에 대해 샘플링할 총 샷 수입니다.
None인 경우 프리미티브의 기본 샷 값이 사용되며, 구현에 따라 다를 수 있습니다.
리턴
샘플러 결과의 작업 객체입니다.
리턴 유형
이 페이지가 도움이 되었습니까?
GitHub에서 버그, 오타를 보고하거나 컨텐츠를 요청하십시오.