# state_evolution_pwc

`Graph.state_evolution_pwc(initial_state, hamiltonian, krylov_subspace_dimension, sample_times=None, *, name=None)`

Calculate the time evolution of a state generated by a piecewise-constant Hamiltonian by using the Lanczos method.

### Parameters

**initial_state**(*Tensor**or**np.ndarray*) – The initial state as a Tensor or np.ndarray of shape`(D,)`

.**hamiltonian**(*Pwc**or**SparsePwc*) – The control Hamiltonian. Uses sparse matrix multiplication if of type SparsePwc, which can be more efficient for large operators that are relatively sparse (contain mostly zeros).**krylov_subspace_dimension**(*Tensor**or**int*) – The dimension of the Krylov subspace k for the Lanczos method.**sample_times**(*np.ndarray**(**1D**,**real**) or**None**,**optional*) – The N times at which you want to sample the state. Must be ordered and contain at least one element. If omitted only the evolved state at the final time of the control Hamiltonian is returned.**name**(*str**or**None**,**optional*) – The name of the node.

### Returns

Tensor of shape `(N, D)`

or `(D,)`

if sample_times is omitted
representing the state evolution. The n-th element (along the first
dimension) represents the state at `sample_times[n]`

evolved from
the initial state.

### Return type

### WARNING

This calculation can be relatively inefficient for small systems (very roughly speaking, when the dimension of your Hilbert space is less than around 100; the exact cutoff depends on the specifics of your problem though). You should generally first try using time_evolution_operators_pwc to get the full time evolution operators (and evolve your state using those), and only switch to this method if that approach proves too slow or memory intensive. See the How to simulate quantum dynamics for noiseless systems using graphs user guide for an example of calculating state evolution with time_evolution_operators_pwc.

### SEE ALSO

`Graph.density_matrix_evolution_pwc`

: Corresponding operation for open systems.

`Graph.discretize_stf`

: Discretize an Stf into a Pwc.

`Graph.estimated_krylov_subspace_dimension_lanczos`

: Obtain a Krylov subspace dimension to use with this integrator.

`Graph.sparse_pwc_operator`

: Create SparsePwc operators.

`Graph.time_evolution_operators_pwc`

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

## Notes

The Lanczos algorithm calculates the unitary evolution of a state in the Krylov subspace. This subspace is spanned by the states resulting from applying the first k powers of the Hamiltonian on the input state, with k being the subspace dimension, much smaller that the full Hilbert space dimension. This allows for an efficient state propagation in high-dimensional systems compared to calculating the full unitary operator.

Moreover, this function uses sparse matrix multiplication when the Hamiltonian is passed as a SparsePwc. This can lead to more efficient calculations when they involve large operators that are relatively sparse (contain mostly zeros). In this case, the initial state is still a densely represented array or tensor.

Note that increasing the density of sample_times does not affect the accuracy of the integration. However, increasing the Krylov subspace dimension or subdividing the Hamiltonian into shorter piecewise-constant segments can reduce the integration error, at the expense of longer computation times.

## Examples

See example in the How to optimize controls on large sparse Hamiltonians user guide.