quara.objects.state module
- class State(c_sys, vec, is_physicality_required=True, is_estimation_object=True, on_para_eq_constraint=True, on_algo_eq_constraint=True, on_algo_ineq_constraint=True, mode_proj_order='eq_ineq', eps_proj_physical=None, eps_truncate_imaginary_part=None)[source]
Bases:
quara.objects.qoperation.QOperationConstructor
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
vec (np.ndarray) – vec of this state.
is_physicality_required (bool, optional) –
checks whether the state is physically correct, by default True. all of the following conditions are
True, the state is physically correct:trace of density matrix equals 1.
density matrix is Hermitian.
density matrix is positive semidefinite.
If you want to ignore the above requirements and create a State object, set
is_physicality_requiredtoFalse.is_estimation_object (bool) –
on_para_eq_constraint (bool) –
on_algo_eq_constraint (bool) –
on_algo_ineq_constraint (bool) –
mode_proj_order (str) –
eps_proj_physical (float) –
eps_truncate_imaginary_part (float) –
- Raises
ValueError – vec is not one-dimensional array.
ValueError – size of vec is not square number.
ValueError – entries of vec are not real numbers.
ValueError – dim of CompositeSystem does not equal dim of vec.
ValueError –
is_physicality_requiredisTrueand the state is not physically correct.
- calc_eigenvalues()[source]
calculates eigen values of density matrix.
this function uses numpy API. see this URL for details: https://numpy.org/doc/1.18/reference/generated/numpy.linalg.eigvalsh.html
- Returns
eigen values of density matrix.
- Return type
List
- calc_gradient(var_index)[source]
calculates gradient of State.
- Parameters
var_index (int) – index of variables to calculate gradient.
- Returns
gradient of State.
- Return type
- calc_proj_eq_constraint()[source]
calculates the projection of State on equal constraint.
- Returns
the projection of State on equal constraint.
- Return type
- static calc_proj_eq_constraint_with_var(c_sys, var, on_para_eq_constraint=True)[source]
calculates the projection of State on equal constraint.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this variables.
var (np.ndarray) – variables.
on_para_eq_constraint (bool, optional) – whether this variables is on parameter equality constraint, by default True.
- Returns
the projection of State on equal constraint.
- Return type
np.ndarray
- calc_proj_ineq_constraint()[source]
calculates the projection of State on inequal constraint.
- Returns
the projection of State on inequal constraint.
- Return type
- static calc_proj_ineq_constraint_with_var(c_sys, var, on_para_eq_constraint=True, eps_truncate_imaginary_part=None)[source]
calculates the projection of State on inequal constraint.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this variables.
var (np.ndarray) – variables.
on_para_eq_constraint (bool, optional) – whether this variables is on parameter equality constraint, by default True.
eps_truncate_imaginary_part (float, optional) – threshold to truncate imaginary part, by default
get_atol()
- Returns
the projection of State on inequal constraint.
- Return type
np.ndarray
- convert_basis(other_basis)[source]
returns vector representation for
other_basis.- Parameters
other_basis (MatrixBasis) – basis.
- Returns
vector representation for
other_basis.- Return type
np.ndarray
- static convert_stacked_vector_to_var(c_sys, stacked_vector, on_para_eq_constraint=True)[source]
converts stacked vector of state to variables of state.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
stacked_vector (np.ndarray) – stacked vector of state.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
- Returns
variables of state.
- Return type
np.ndarray
- static convert_var_to_stacked_vector(c_sys, var, on_para_eq_constraint=True)[source]
converts variables of state to stacked vector of state.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
var (np.ndarray) – variables of state.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
- Returns
stacked vector of state.
- Return type
np.ndarray
- property dim
returns dim of this state.
- Returns
dim of this state.
- Return type
int
- is_hermitian(atol=None)[source]
returns whether density matrix is Hermitian.
- Parameters
atol (float, optional) – the absolute tolerance parameter, uses
get_atol()by default.- Returns
bool
True where density matrix, False otherwise.
- Return type
bool
- is_positive_semidefinite(atol=None)[source]
returns whether density matrix is positive semidifinite.
- Parameters
atol (float, optional) – the absolute tolerance parameter, uses
get_atol()by default.- Returns
True where density matrix is positive semidifinite, False otherwise.
- Return type
bool
- is_trace_one(atol=None)[source]
returns whether trace of density matrix is one.
- Parameters
atol (float, optional) – the absolute tolerance parameter, uses
get_atol()by default.- Returns
True where trace of density matrix is one, False otherwise.
- Return type
bool
- to_density_matrix_with_sparsity()[source]
returns density matrix.
this function uses the scipy.sparse module.
- Returns
density matrix.
- Return type
int
- to_stacked_vector()[source]
converts State to stacked vector.
- Returns
stacked vector representation of State.
- Return type
np.ndarray
- to_var()[source]
converts State to variables.
- Returns
variable representation of State.
- Return type
np.ndarray
- property vec
returns vec of this state.
- Returns
vec of this state.
- Return type
np.ndarray
- calc_gradient_from_state(c_sys, vec, var_index, is_estimation_object=True, on_para_eq_constraint=True, on_algo_eq_constraint=True, on_algo_ineq_constraint=True, mode_proj_order='eq_ineq', eps_proj_physical=0.0001, eps_truncate_imaginary_part=None)[source]
calculates gradient from State.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
vec (np.ndarray) – vec of state.
var_index (int) – variable index.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
is_estimation_object (bool) –
on_algo_eq_constraint (bool) –
on_algo_ineq_constraint (bool) –
mode_proj_order (str) –
eps_proj_physical (float) –
eps_truncate_imaginary_part (Optional[float]) –
- Returns
State with gradient as vec.
- Return type
- convert_state_index_to_var_index(state_index, on_para_eq_constraint=True)[source]
converts state index to variable index.
- Parameters
state_index (int) – state index.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
- Returns
variable index.
- Return type
int
- convert_var_index_to_state_index(var_index, on_para_eq_constraint=True)[source]
converts variable index to state index.
- Parameters
var_index (int) – variable index.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
- Returns
state index.
- Return type
int
- convert_var_to_state(c_sys, var, is_physicality_required=True, is_estimation_object=True, on_para_eq_constraint=True, on_algo_eq_constraint=True, on_algo_ineq_constraint=True, mode_proj_order='eq_ineq', eps_proj_physical=0.0001)[source]
converts vec of variables to state.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
var (np.ndarray) – vec of variables.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
is_physicality_required (bool) –
is_estimation_object (bool) –
on_algo_eq_constraint (bool) –
on_algo_ineq_constraint (bool) –
mode_proj_order (str) –
eps_proj_physical (float) –
- Returns
converted state.
- Return type
- convert_var_to_vec(c_sys, var, on_para_eq_constraint=True)[source]
converts variables of state to vec of state.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
var (np.ndarray) – variables of state.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
- Returns
vec of state.
- Return type
np.ndarray
- convert_vec_to_var(c_sys, vec, on_para_eq_constraint=True)[source]
converts vec of state to variables of state.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
vec (np.ndarray) – vec of state.
on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.
- Returns
variables of state.
- Return type
np.ndarray
- get_bell_2q(c_sys)[source]
returns vec of Bell state, \(\frac{1}{2} (|00\rangle + |11\rangle)(\langle00| + \langle11|)\), with the basis of
c_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
- get_x0_1q(c_sys)[source]
returns vec of state
X_0with the basis ofc_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
np.ndarray
- get_x1_1q(c_sys)[source]
returns vec of state
X_1with the basis ofc_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
np.ndarray
- get_y0_1q(c_sys)[source]
returns vec of state
Y_0with the basis ofc_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
np.ndarray
- get_y1_1q(c_sys)[source]
returns vec of state
Y_1with the basis ofc_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
np.ndarray
- get_z0_1q(c_sys)[source]
returns vec of state
Z_0with the basis ofc_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
np.ndarray
- get_z1_1q(c_sys)[source]
returns vec of state
Z_1with the basis ofc_sys.- Parameters
c_sys (CompositeSystem) – CompositeSystem containing state.
- Returns
vec of state.
- Return type
np.ndarray
- to_density_matrix_from_var(c_sys, var, on_para_eq_constraint=True)[source]
converts var to density matrix.
this function uses the scipy.sparse module.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
var (np.ndarray) – variables.
on_para_eq_constraint (bool, optional) – whether this state is on parameter equality constraint, by default True
- Returns
density matrix of this state.
- Return type
np.ndarray
- to_density_matrix_from_vec(c_sys, vec)[source]
converts vec to density matrix.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
vec (np.ndarray) – vec of state of this state.
- Returns
density matrix of this state.
- Return type
np.ndarray
- to_var_from_density_matrix(c_sys, density_matrix, on_para_eq_constraint=True)[source]
converts density matrix to variables.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
density_matrix (np.ndarray) – density matrix of this state.
on_para_eq_constraint (bool, optional) – whether this state is on parameter equality constraint, by default True
- Returns
variables.
- Return type
np.ndarray
- to_vec_from_density_matrix_with_sparsity(c_sys, density_matrix, eps_truncate_imaginary_part=None)[source]
converts density matrix to vec.
this function uses the scipy.sparse module.
- Parameters
c_sys (CompositeSystem) – CompositeSystem of this state.
density_matrix (np.ndarray) – density matrix of this state.
eps_truncate_imaginary_part (float, optional) – threshold to truncate imaginary part, by default
get_atol()
- Returns
vec of variables.
- Return type
np.ndarray