StatevectorSampler
class qiskit.primitives.StatevectorSampler(*, default_shots=1024, seed=None)
ベース: BaseSamplerV2
完全な状態ベクトル・シミュレーションを使った BaseSamplerV2 完全な状態ベクトルシミュレーションを使用した
このクラスは Statevector によって実装され、提供された回路を純粋なステート・ベクターに変える。
以下の例に見られるように、このサンプラーは、1つの回路に対してバインドするパラメータ値セットの配列を提供することをサポートしている。
サンプラープリミティブ統一ブロック( 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) – 乱数生成のためのシードまたはジェネレータオブジェクト。 Noneの場合、ランダムシードされたデフォルトRNGが使用される。
属性
default_shots
デフォルトショットを返す
seed
乱数生成用のシードまたは Generator オブジェクトを返します。
方法
run
run(pubs, *, shots=None)
各パブからサンプルを採取する。
パラメーター
- pubs (Iterable[TypeAliasForwardRef('SamplerPubLike')]) – パブのようなオブジェクトの反復可能オブジェクト。 例えば、回路やタプルのリストなど
(circuit, parameter_values)。 - shots (int | None) – 独自のショットを指定しないサンプラーパブごとにサンプリングする合計ショット数。
Noneの場合、プリミティブのデフォルトのショット値が使用される。
戻り値
サンプラーの結果のジョブオブジェクト。
戻りの型
プリミティブジョブ [ プリミティブリザルト [ サンプリングパブリズルト ]]
このページは役に立ちましたか?
バグや誤字の報告、またはコンテンツの要求はGitHubで行ってください。