Skip to main content
IBM Quantum Platform

StatevectorEstimator

class qiskit.primitives.StatevectorEstimator(*, default_precision=0.0, seed=None)

GitHub

ベース: BaseEstimatorV2

のシンプルな実装。 BaseEstimatorV2 を実装した。

このクラスは Statevector によって実装され、提供された回路を純粋な状態ベクトルに変える。 これらの状態はその後 SparsePauliOpによって作用される。このことは、現在のところ、この実装がパウリに基づく観測量にしか対応していないことを意味している。

各タプルは (circuit, observables, <optional> parameter values, <optional> precision)、推定器プリミティブ統一ブロック( PUB )と呼ばれ、独自の配列ベースの結果を生成する。 この run() メソッドは、1回の呼び出しで実行するパブのシーケンスを受け取ることができます。

このクラスの結果は、回路がユニタリ操作のみを含む場合に正確である。 一方、回路にサブシステムのリセットなどの非ユニタリ操作が含まれる場合、結果は確率的となる可能性がある。 確率的な結果は、例えば を 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) – 乱数生成のためのシードまたはジェネレータオブジェクト。 Noneの場合、ランダムシードされたデフォルトRNGが使用される。

属性

default_precision

デフォルトの精度を返す

seed

乱数生成用のシードまたは Generator オブジェクトを返します。


方法

run

run(pubs, *, precision=None)

GitHub

提供された各パブ(Primitive Unified Bloc)の期待値を推定する。

パラメーター

  • pubs (Iterable[TypeAliasForwardRef('EstimatorPubLike')]) – タプル (circuit, observables) やなどの、pubのようなオブジェクト (circuit, observables, parameter_values)の反復可能オブジェクト。
  • precision (float | None) – 独自の精度を指定しない各ランEstimator Pubの期待値推定値の目標精度。 None の場合、推定値のデフォルト精度が使用されます。

戻り値

結果を含むジョブ・オブジェクト。

戻りの型

プリミティブジョブ [ プリミティブリザルト [ パブリックリザルト ]]

このページは役に立ちましたか?
バグや誤字の報告、またはコンテンツの要求はGitHubで行ってください。