qiskit.algorithms.optimizers.QNSPSA.get_fidelity¶
- static QNSPSA.get_fidelity(circuit, backend=None, expectation=None, *, sampler=None)[source]¶
Get a function to compute the fidelity of
circuit
with itself.Note
Using this function with a backend and expectation converter is pending deprecation, instead pass a Qiskit Primitive sampler, such as
Sampler
. The sampler can be passed as keyword argument or, positionally, as second argument.Let
circuit
be a parameterized quantum circuit performing the operation \(U(\theta)\) given a set of parameters \(\theta\). Then this method returns a function to evaluate\[F(\theta, \phi) = \big|\langle 0 | U^\dagger(\theta) U(\phi) |0\rangle \big|^2.\]The output of this function can be used as input for the
fidelity
to theQNSPSA
optimizer.Deprecated since version 0.24.0:
qiskit.algorithms.optimizers.qnspsa.QNSPSA.get_fidelity()
’s argumentexpectation
is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. See https://qisk.it/algo_migration for a migration guide.Deprecated since version 0.24.0:
qiskit.algorithms.optimizers.qnspsa.QNSPSA.get_fidelity()
’s argumentbackend
is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. See https://qisk.it/algo_migration for a migration guide.- Parameters
circuit (QuantumCircuit) – The circuit preparing the parameterized ansatz.
backend (Backend | QuantumInstance | None) – Deprecated. A backend of quantum instance to evaluate the circuits. If None, plain matrix multiplication will be used.
expectation (ExpectationBase | None) – Deprecated. An expectation converter to specify how the expected value is computed. If a shot-based readout is used this should be set to
PauliExpectation
.sampler (BaseSampler | None) – A sampler primitive to sample from a quantum state.
- Returns
A handle to the function \(F\).
- Return type
Callable[[np.ndarray, np.ndarray], float]