# infidelity_stf

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/infidelity_stf

```python
Graph.infidelity_stf(sample_times, hamiltonian, target, noise_operators=None, *, name=None)
```

Create the total infidelity of a given system with a sampleable Hamiltonian.

See [`infidelity_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/infidelity_pwc.md#boulderopal.graph.Graph.infidelity_pwc) for information about the total infidelity
created by this function.

### Parameters
* **sample_times** (*np.ndarray* *(* *1D* *,* *real* *)*) – The times at which the Hamiltonian and noise operators (if present) should be sampled
  for the integration. Must start with 0, be ordered, and contain at least one element.
* **hamiltonian** ([*Stf*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf)) – The control Hamiltonian $H_{\mathrm c}(t)$. You can provide
  either a single Hamiltonian or a batch of them.
* **target** ([*Target*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Target.md#boulderopal.graph.Target)) – The object describing the target gate $U_\mathrm{target}$ and
  (optionally) the filter function projector $P$. If you
  provide a batch of Hamiltonians, the function uses the same target
  for all the elements in the batch.
* **noise_operators** (*list* *[* *np.ndarray* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) *or* [*Stf*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf) *] or* *None* *,* *optional*) – The perturbative noise operators $\{N_j(t)\}$. The operators
  in the list can either be single operators or batches of them. If
  any of the noise operators or the Hamiltonian are batches, the batch
  shapes must all be broadcastable. You can omit this list if there are
  no noises.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
The total infidelity (operational infidelity plus filter function
values) of the given system, with respect to the given target gate,
at the last time in sample_times.
If you provide a batch of Hamiltonians or noise operators, the
function returns a batch of infidelities containing one infidelity
for each Hamiltonian and list of noise operators in the input batches.
### Return type
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)

### SEE ALSO
[`Graph.infidelity_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/infidelity_pwc.md#boulderopal.graph.Graph.infidelity_pwc)
: Corresponding operation for Pwc Hamiltonians.

[`Graph.target`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/target.md#boulderopal.graph.Graph.target)
: Define the target operation of the time evolution.

[`Graph.time_evolution_operators_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/time_evolution_operators_stf.md#boulderopal.graph.Graph.time_evolution_operators_stf)
: Unitary time evolution operators for quantum systems with Stf Hamiltonians.

## Examples

Calculate the infidelity of the Pauli $X$ gate for a noiseless qubit.

```pycon
>>> sigma_x = np.array([[0, 1], [1, 0]])
>>> hamiltonian = graph.constant_stf_operator(np.pi * sigma_x / 2)
>>> target = graph.target(sigma_x)
>>> infidelity = graph.infidelity_stf(
...     sample_times=np.linspace(0, 0.5, 100),
...     hamiltonian=hamiltonian,
...     target=target,
...     name="infidelity",
... )
>>> result = bo.execute_graph(graph=graph, output_node_names="infidelity")
>>> result["output"]["infidelity"]["value"]
0.5000000000260991
```
