---
title: objective (latest version)
description: API reference for qiskit_addon_aqc_tensor.objective in the latest version of qiskit-addon-aqc-tensor
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit-addon-aqc-tensor/objective
---

# Objective function(s)

`qiskit_addon_aqc_tensor.objective`

Code for building and evaluating objective functions used for AQC parameter optimization.

Currently, this module provides the simplest possible objective function, [`MaximizeStateFidelity`](#qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity "qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity").

### MaximizeStateFidelity

*class* `MaximizeStateFidelity(target, ansatz, settings)`

[GitHub](https://github.com/Qiskit/qiskit-addon-aqc-tensor/tree/stable/0.3/qiskit_addon_aqc_tensor/objective.py#L33-L103)

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

Simplest possible objective function for use with AQC-Tensor.

Its definition is given by Eq. (7) in [arXiv:2301.08609v6](https://arxiv.org/abs/2301.08609v6):

$$
C = 1 - \left| \langle 0 | V^{\dagger}(\vec\theta) | \psi_\mathrm{target} \rangle \right|^2 .
$$

Minimizing this function is equivalent to maximizing the pure-state fidelity between the state prepared by the ansatz circuit at the current parameter point, $V(\vec\theta) |0\rangle$, and the target state, $| \psi_\mathrm{target} \rangle$.

When called with an [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) of parameters, this object will return `(objective_value, gradient)` as a `tuple[float, numpy.ndarray]`.

Initialize the objective function.

**Parameters**

- **ansatz** ([`QuantumCircuit`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit)) – Parametrized ansatz circuit.
- **target** ([`TensorNetworkState`](/docs/api/qiskit-addon-aqc-tensor/simulation#qiskit_addon_aqc_tensor.simulation.TensorNetworkState "qiskit_addon_aqc_tensor.simulation.abstract.TensorNetworkState")) – Target state in tensor-network representation.
- **settings** ([`TensorNetworkSimulationSettings`](/docs/api/qiskit-addon-aqc-tensor/simulation#qiskit_addon_aqc_tensor.simulation.TensorNetworkSimulationSettings "qiskit_addon_aqc_tensor.simulation.abstract.TensorNetworkSimulationSettings")) – Tensor network simulation settings.

#### loss\_function

`loss_function(x)`

[GitHub](https://github.com/Qiskit/qiskit-addon-aqc-tensor/tree/stable/0.3/qiskit_addon_aqc_tensor/objective.py#L92-L98)

Evaluate `(objective_value, gradient)` of function at point `x`.

**Return type**

[`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple)\[[`float`](https://docs.python.org/3/library/functions.html#float), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)]

**Parameters**

**x** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray))

#### target

Type: `TensorNetworkState`

Target tensor network.

### OneMinusFidelity

*class* `OneMinusFidelity(target, ansatz, settings)`

[GitHub](https://github.com/Qiskit/qiskit-addon-aqc-tensor/tree/stable/0.3/qiskit_addon_aqc_tensor/objective.py#L106-L131)

Bases: [`MaximizeStateFidelity`](#qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity "qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity")

DEPRECATED objective function, equivalent to [`MaximizeStateFidelity`](#qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity "qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity").

Initialize the objective function.

The [`OneMinusFidelity`](#qiskit_addon_aqc_tensor.objective.OneMinusFidelity "qiskit_addon_aqc_tensor.objective.OneMinusFidelity") class is DEPRECATED since v0.2. Please migrate to [`MaximizeStateFidelity`](#qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity "qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity") as soon as possible.

> **Deprecated since version 0.2.0**
>
> The class `qiskit_addon_aqc_tensor.objective.OneMinusFidelity` is deprecated as of qiskit-addon-aqc-tensor 0.2.0. It will be removed no earlier than v0.4.0. This class has been renamed to `MaximizeStateFidelity`.

**Parameters**

- **ansatz** ([`QuantumCircuit`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit)) – Parametrized ansatz circuit.
- **target** ([`TensorNetworkState`](/docs/api/qiskit-addon-aqc-tensor/simulation#qiskit_addon_aqc_tensor.simulation.TensorNetworkState "qiskit_addon_aqc_tensor.simulation.abstract.TensorNetworkState")) – Target state in tensor-network representation.
- **settings** ([`TensorNetworkSimulationSettings`](/docs/api/qiskit-addon-aqc-tensor/simulation#qiskit_addon_aqc_tensor.simulation.TensorNetworkSimulationSettings "qiskit_addon_aqc_tensor.simulation.abstract.TensorNetworkSimulationSettings")) – Tensor network simulation settings.

#### \_\_call\_\_

`__call__(x)`

[GitHub](https://github.com/Qiskit/qiskit-addon-aqc-tensor/tree/stable/0.3/qiskit_addon_aqc_tensor/objective.py#L75-L90)

Evaluate `(objective_value, gradient)` of function at point `x`.

This method is DEPRECATED since v0.2. The [`loss_function()`](#qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity.loss_function "qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity.loss_function") method should be called instead.

**Return type**

[`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple)\[[`float`](https://docs.python.org/3/library/functions.html#float), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)]

**Parameters**

**x** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray))

> **Deprecated since version 0.2.0**
>
> The method `qiskit_addon_aqc_tensor.objective.MaximizeStateFidelity.__call__()` is deprecated as of qiskit-addon-aqc-tensor 0.2.0. It will be removed no earlier than v0.4.0. Going forward, the `loss_function` method should be called instead of calling the instance directly.

#### loss\_function

`loss_function(x)`

[GitHub](https://github.com/Qiskit/qiskit-addon-aqc-tensor/tree/stable/0.3/qiskit_addon_aqc_tensor/objective.py#L92-L98)

Evaluate `(objective_value, gradient)` of function at point `x`.

**Return type**

[`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple)\[[`float`](https://docs.python.org/3/library/functions.html#float), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)]

**Parameters**

**x** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray))

#### target

Type: `TensorNetworkState`

Target tensor network.
