Graph.infidelity_pwc(hamiltonian, target, noise_operators=None, *, name=None)

Create the total infidelity of the given piecewise-constant system.

Use this function to compute the sum of the operational infidelity (which measures how effectively the system achieves a target gate) and filter function values (which measure how robust the system evolution is to various perturbative noise processes). This total infidelity value provides a cost that measures how effectively and robustly a set of controls achieves a target operation.

Note that the total infidelity returned by this function is at least zero, but might be larger than one (for example if the system is highly sensitive to one of the noise processes).


  • hamiltonian (Pwc) – The control Hamiltonian Hc(t)H_{\mathrm c}(t)
  • target (Target) – The object describing the target gate UtargetU_\mathrm{target} and (optionally) the filter function projector PP
  • noise_operators (list [ np.ndarray or Tensor or Pwc ] or None , optional) – The perturbative noise operators {Nj(t)}\{N_j(t)\}
  • name (str or None , optional) – The name of the node.


The total infidelity (operational infidelity plus filter function values) of the given system, with respect to the given target gate. 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



The Hessian matrix cannot currently be calculated for a graph which includes an infidelity_pwc node if the hamiltonian has degenerate eigenvalues at any segment.


Graph.infidelity_stf : Corresponding operation for Stf Hamiltonians. : Define the target operation of the time evolution.

Graph.time_evolution_operators_pwc : Unitary time evolution operators for quantum systems with Pwc Hamiltonians.


The total system Hamiltonian is

Hc(t)+jβj(t)Nj(t), H_{\mathrm c}(t) + \sum_j \beta_j(t) N_j(t),

where {βj(t)}\{\beta_j(t)\}

The total infidelity, as represented by this node, is the sum of the operational infidelity I\mathcal{I} and the filter functions {Fj(0)}\{F_j(0)\}

The operational infidelity is

I=1Tr(UtargetU(t))Tr(UtargetUtarget)2, \mathcal{I} = 1-\left| \frac{\mathrm{Tr} \left(U_\mathrm{target}^\dagger U(t)\right)} {\mathrm{Tr} \left(U_\mathrm{target}^\dagger U_\mathrm{target}\right)} \right|^2,

where U(t)U(t) is the unitary time evolution operator due to Hc(t)H_{\mathrm c}(t)

The filter function for the noise operator Nj(t)N_j(t) is a measure of robustness, defined at frequency ff

F_j(f) = \frac{1}{\mathrm{Tr}(P)} \mathrm{Tr} \left( P \mathcal{F} \left\\{ \tilde N_j^\prime(t) \right\\} \left[ \mathcal{F} \left\\{ \tilde N^\prime (t) \right\\} \right]^\dagger P \right),

where F\mathcal{F} is the Fourier transform, N~j(t)Uc(t)Nj(t)Uc(t)\tilde N_j(t) \equiv U_c^\dagger(t) N_j(t) U_c(t) is the toggling-frame noise operator, and N~j(t)N~j(t)Tr(PN~j(t)P)Tr(P)I\tilde N_j^\prime(t)\equiv \tilde N_j(t)- \frac{\mathrm{Tr}(P\tilde N_j(t)P)}{\mathrm{Tr}(P)} \mathbb{I} differs from N~j(t)\tilde N_j(t)


Calculate infidelity of the identity gate for a noiseless single qubit.

>>> sigma_z = np.array([[1, 0], [0, -1]])
>>> hamiltonian =
...     durations=np.array([0.1, 0.1]), values=np.array([sigma_z, -sigma_z])
... )
>>> target =
>>> infidelity = graph.infidelity_pwc(
...     hamiltonian=hamiltonian, target=target, name="infidelity"
... )
>>> result = bo.execute_graph(graph=graph, output_node_names="infidelity")
>>> result["output"]["infidelity"]["value"]

See more examples in the How to optimize controls with non-linear dependencies user guide.

Was this useful?