# estimated_krylov_subspace_dimension_lanczos

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

```python
Graph.estimated_krylov_subspace_dimension_lanczos(spectral_range, duration, maximum_segment_duration, error_tolerance=1e-06, *, name=None)
```

Calculate an appropriate Krylov subspace dimension ($k$) to use in the Lanczos
integrator while keeping the total error in the evolution below a given error tolerance.

Note that you can provide your own estimation of the Hamiltonian spectral range or use the
spectral_range operation to perform that calculation.

### Parameters
* **spectral_range** (*float* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)) – Estimated order of magnitude of Hamiltonian spectral range (difference
  between largest and smallest eigenvalues).
* **duration** (*float*) – The total evolution time.
* **maximum_segment_duration** (*float*) – The maximum duration of the piecewise-constant Hamiltonian segments.
* **error_tolerance** (*float* *,* *optional*) – Tolerance for the error in the integration, defined as the Frobenius norm of
  the vectorial difference between the exact state and the estimated state.
  Defaults to 1e-6.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
Recommended value of $k$ to use in a Lanczos integration with a Hamiltonian with a
similar spectral range to the one passed.
### Return type
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)

### SEE ALSO
[`Graph.spectral_range`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/spectral_range.md#boulderopal.graph.Graph.spectral_range)
: Range of the eigenvalues of a Hermitian operator.

[`Graph.state_evolution_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/state_evolution_pwc.md#boulderopal.graph.Graph.state_evolution_pwc)
: Evolve a quantum state.

## Notes

To provide the recommended $k$ parameter, this function uses the bound
in the error for the Lanczos algorithm <sup>[1](#id3)</sup> <sup>[2](#id4)</sup> as an estimate for the error.
For a single time step this gives

$$
\mathrm{error} \leq 12 \exp \left( - \frac{(w\tau)^2}{16 k} \right)
\left (\frac{e w \tau}{ 4 k}  \right )^{k}
$$

where $\tau$ is the time step and $w$ is the spectral range of the Hamiltonian.

As this bound overestimates the error, the actual resulting errors
with the recommended parameter are expected to be (a few orders of magnitude)
smaller than the requested tolerance.

## References

* <a id='id3'>**[1]**</a> [N. Del Buono and L. Lopez, Lect. Notes Comput. Sci. 2658, 111 (2003).](https://doi.org/10.1007/3-540-44862-4_13)
* <a id='id4'>**[2]**</a> [M. Hochbruck and C. Lubich, SIAM J. Numer. Anal. 34, 1911 (1997).](https://doi.org/10.1137/S0036142995280572)

## Examples

```pycon
>>> graph.estimated_krylov_subspace_dimension_lanczos(
...     spectral_range=30.0,
...     duration=5e-7,
...     maximum_segment_duration=2.5e-8,
...     error_tolerance=1e-5,
...     name="dim",
... )
<Tensor: name="dim", operation_name="estimated_krylov_subspace_dimension_lanczos", shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="dim")
>>> result["output"]["dim"]["value"]
2
```

See more examples in the [How to optimize controls on large sparse Hamiltonians](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-optimize-controls-on-large-sparse-hamiltonians) user guide.
