quairkit.core.state.state

Common functions for the State class.

quairkit.core.state.state.to_state(data, system_dim=2, dtype=None, state_backend=None, eps=0.0001)

The function to generate a specified state instance.

Parameters:
data : Tensor | ndarray | State

a representation of the quantum state in allowable backend, or an instance of the State class.

system_dim : List[int] | int | None

(list of) dimension(s) of the systems, can be a list of integers or an integer. For example, system_dim = 2 means the systems are qubits (default setup); system_dim = [2, 3] means the first system is a qubit and the second is a qutrit.

dtype : str | None

Used to specify the data dtype of the data. Defaults to the global setup.

state_backend : str | None

The backend of the state. Specified only when the input data is an instance of the State class.

eps : float | None

The tolerance for checking the validity of the input state. Can be adjusted to None to disable the check.

Returns:

The generated quantum state.

Return type:

State

Note

When the backend is set as 'default', the backend of this state is determined by the table

single

batch

state_vector

[d], [1, d], [d, 1]

[d1, …, dn, d, 1]

density_matrix

[d, d]

[d1, …, dn, d, d]

quairkit.core.state.state.image_to_density_matrix(image_filepath)

Encode image to density matrix

Parameters:
image_filepath : str

Path to the image file.

Returns:

The density matrix obtained by encoding

Return type:

State

quairkit.core.state.state.tensor_state(state_a, state_b, *args)

calculate tensor product (kronecker product) between at least two state. This function automatically returns State instance

Parameters:
state_a : State

State

state_b : State

State

args : State

other states

Returns:

tensor product state of input states

Return type:

State

Note

Need to be careful with the backend of states; Use quairkit.linalg.NKron if the input datatype is torch.Tensor or numpy.ndarray.