# hermitian_part

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

```python
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.

### Parameters
* **x** (*np.ndarray* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) *or* [*Pwc*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc) *or* [*Stf*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.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* *or* *None* *,* *optional*) – The name of the node. You can only provide a name if the object is not an Stf.
### Returns
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](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) or [Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc) or [Stf](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf)

### SEE ALSO
[`Graph.adjoint`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/adjoint.md#boulderopal.graph.Graph.adjoint)
: Hermitian adjoint of an operator.

## Examples

Create a Hamiltonian from a non-Hermitian Pwc operator.

```pycon
>>> 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 = bo.execute_graph(graph=graph, output_node_names="hamiltonian")
>>> result["output"]["hamiltonian"]
{
    'durations': array([0.5, 0.7]),
    'values': array([
        [[0. , 0.1], [0.1, 0. ]],
        [[0. , 0.2], [0.2, 0. ]]
        ]),
    'time_dimension': 0
}
```

See more examples in the [Simulate the dynamics of a single qubit using computational graphs](https://docs.q-ctrl.com/boulder-opal/tutorials/simulate-the-dynamics-of-a-single-qubit-using-computational-graphs) tutorial.

Create a Hamiltonian from a non-Hermitian Stf operator.

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

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

```pycon
>>> sigma_m = np.array([[0, 1], [0, 0]])
>>> graph.hermitian_part(sigma_m, name="hamiltonian")
<Tensor: name="hamiltonian", operation_name="hermitian_part", shape=(2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="hamiltonian")
>>> result["output"]["hamiltonian"]
{'value': array([[0. , 0.5], [0.5, 0. ]])}
```
