Graph.hermitian_part(x, *, name=None)

Calculate the Hermitian part of an object. This can be an array, a tensor, or a time-dependent function in the form of a Pwc or an Stf where values have at least two dimensions. The operation is applied on the last two dimensions, which must be equal to each other.

  • x (np.ndarray or Tensor or Pwc or Stf) – The object whose Hermitian part you want to calculate, \(\mathop{x}\). Must be a matrix or a matrix-valued function. For arrays and tensors, the object is converted to a tensor and then the operation is applied. For functions of time (Pwcs and Stfs), the composition of the operation with the function is computed (that is, the operation is applied to the function values).

  • name (str, optional) – The name of the node. You can only provide a name if the object is not an Stf.


The Hermitian part of the matrix or matrix-valued function, \(\frac{1}{2}(\mathop{x}+\mathop{x}^\dagger)\). Outputs will have the same dimension as the inputs.

Return type

Tensor or Pwc or Stf

See also


Hermitian adjoint of an operator.


Create a Hamiltonian from a non-Hermitian Pwc operator.

>>> omega = graph.pwc(durations=np.array([0.5, 0.7]), values=np.array([0.2, 0.4]))
>>> sigma_m = np.array([[0, 1], [0, 0]])
>>> operator = omega * sigma_m
>>> graph.hermitian_part(operator, name="hamiltonian")
<Pwc: name="hamiltonian", operation_name="hermitian_part", value_shape=(2, 2), batch_shape=()>
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["hamiltonian"])
>>> result.output["hamiltonian"]
    {"value": array([[0.0, 0.1], [0.1, 0.0]]), "duration": 0.5},
    {"value": array([[0.0, 0.2], [0.2, 0.0]]), "duration": 0.7},

See more examples in the Simulate the dynamics of a single qubit using computational graphs tutorial.

Create a Hamiltonian from a non-Hermitian Stf operator.

>>> operator = stf_signal * np.array([[0, 1, 0], [0, 0, np.sqrt(2)], [0, 0, 0]])
>>> operator
<Stf: operation_name="multiply", value_shape=(3, 3), batch_shape=()>
>>> hamiltonian = graph.hermitian_part(operator)

Refer to the How to perform model-based optimization with user-defined basis functions user guide to find the example in context.

Create a Hermitian matrix from a non-Hermitian np.ndarray.

>>> sigma_m = np.array([[0, 1], [0, 0]])
>>> graph.hermitian_part(sigma_m, name="hamiltonian")
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["hamiltonian"])
>>> result.output["hamiltonian"]
{'value': array([[0. , 0.5], [0.5, 0. ]])}