# 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 the :class:~qiskit.algorithms.optimizers.QNSPSA optimizer.

Paramètres
• circuit (QuantumCircuit) – The circuit preparing the parameterized ansatz.

• backend (Backend | QuantumInstance | None) – Pending deprecation. A backend of quantum instance to evaluate the circuits. If None, plain matrix multiplication will be used.

• expectation (ExpectationBase | None) – Pending deprecation. 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.

Type renvoyé

Callable[[np.ndarray, np.ndarray], float]

Renvoie

A handle to the function $$F$$.