quara.objects.povm module

class Povm(c_sys, vecs, 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.QOperation

Positive Operator-Valued Measure

Constructor

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • vecs (List[np.ndarray]) – list of vec of povm elements.

  • is_physicality_required (bool, optional) –

    checks whether the POVM is physically wrong, by default True. all of the following conditions are True, the POVM is physically correct:

    • It is a set of Hermitian matrices.

    • It is a set of positive semidefinite matrices.

    • The sum the elements of is the identity matrix.

    If you want to ignore the above requirements and create a POVM object, set is_physicality_required to False.

  • 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 – entries of all vecs are not real numbers.

  • ValueError – If the dim in the c_sys does not match the dim in the vecs

  • ValueErroris_physicality_required is True and the gate is not physically correct.

calc_eigenvalues(index=None)[source]

Calculates eigenvalues.

Parameters

index (int, optional) – Index to obtain eigenvalues, by default None

Returns

eigenvalues.

Return type

Union[List[np.ndarray], np.ndarray]

calc_gradient(var_index)[source]

calculates gradient of QOperation.

this function must be implemented in the subclass.

Parameters

var_index (int) – index of variables to calculate gradient.

Returns

gradient of QOperation.

Return type

QOperation

Raises

NotImplementedError – this function does not be implemented in the subclass.

calc_proj_eq_constraint()[source]

calculates the projection of QOperation on equal constraint.

Returns

the projection of QOperation on equal constraint.

Return type

QOperation

static calc_proj_eq_constraint_with_var(c_sys, var, on_para_eq_constraint=True)[source]

calculates the projection of povm 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 povm on equal constraint.

Return type

np.ndarray

calc_proj_ineq_constraint()[source]

calculates the projection of QOperation on inequal constraint.

Returns

the projection of QOperation on inequal constraint.

Return type

QOperation

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

calc_stopping_criterion_birgin_raydan_vectors()[source]
convert_basis(other_basis)[source]

Calculate vector representation for other_basis.

Parameters

other_basis (MatrixBasis) – basis

Returns

Vector representation after conversion to other_basis .

Return type

List[np.ndarray]

static convert_stacked_vector_to_var(c_sys, stacked_vector, on_para_eq_constraint=True)[source]

converts stacked vector of povm to variables of povm.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • stacked_vector (np.ndarray) – stacked vector of povm.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

variables of povm.

Return type

np.ndarray

static convert_var_to_stacked_vector(c_sys, var, on_para_eq_constraint=True)[source]

converts variables of povm to stacked vector of povm.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • var (np.ndarray) – variables of povm.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

stacked vector of povm.

Return type

np.ndarray

property dim: int

returns dim of Povm.

Returns

dim of Povm.

Return type

int

generate_mprocess(mode_backaction=0, post_selected_states=None)[source]

generates MProcess from Povm.

Parameters
  • mode_backaction (int) –

    Specify mode_backaction. Assume \(\{|\Pi_x\rangle\rangle\}_{x=0}^{m-1}\) be vecs of Povm. The HSs of MProcess is generated by the following rules:

    • if mode_backaction = 0, \(\mathrm{HS}_x^{\mathrm{cb}} := \sqrt{\Pi_x} \otimes \overline{\sqrt{\Pi_x}}\).

    • if mode_backaction = 1 and \(\Pi_x = \sum_{i} p_{x,i} P_{x,i}\) is a spectral decomposition, \(\mathrm{HS}_x^{\mathrm{cb}} := \sum_{i} p_{x,i} P_{x,i} \otimes \overline{P_{x,i}}\).

    • if mode_backaction = 2, \(\mathrm{HS}_x := |\rho_x\rangle\rangle \langle\langle\Pi_x|\), where \(\{\rho_x\}\) = post_selected_states.

  • post_selected_states (Union[State, List[State]]) – post selected States to generate MProcess.

Returns

generated MProcess.

Return type

MProcess

Raises
  • ValueError – mode_backaction is 0 and post_selected_states is not None.

  • ValueErrorbb – mode_backaction is 1 and post_selected_states is not None.

  • ValueError – mode_backaction is 2 and post_selected_states is None.

  • ValueError – mode_backaction is not 0,1,2.

is_eq_constraint_satisfied(atol=None)[source]
Parameters

atol (Optional[float]) –

is_hermitian()[source]

Returns whether the povm is a set of Hermit matrices.

Returns

If True, the povm is a set of Hermit matrices.

Return type

bool

is_identity_sum(atol=None)[source]

Returns whether the sum of the elements _vecs is an identity matrix.

Returns

If the sum of the elements _vecs is an identity matrix, otherwise it returns False.

Return type

bool

Parameters

atol (Optional[float]) –

is_ineq_constraint_satisfied(atol=None)[source]
Parameters

atol (Optional[float]) –

is_positive_semidefinite(atol=None)[source]

Returns whether each element is positive semidifinite.

Returns

True where each element is positive semidifinite, False otherwise.

Return type

bool

Parameters

atol (Optional[float]) –

is_satisfied_stopping_criterion_birgin_raydan_qoperations()[source]
is_satisfied_stopping_criterion_birgin_raydan_vectors()[source]
matrices()[source]

returns matrices of measurements.

Returns

matrices of measurements.

Return type

List[np.ndarray]

matrices_with_sparsity()[source]

returns matrices of measurements.

this function uses the scipy.sparse module.

Returns

matrices of measurements.

Return type

List[np.ndarray]

matrix(index)[source]

returns matrix of measurement.

Parameters

index (Union[int, Tuple]) – index of vec of measurement. if type is int, then regardes it as the index for CompositeSystem. if type is Tuple, then regardes it as the indices for earch ElementalSystems.

Returns

matrix of measurement.

Return type

np.ndarray

matrix_with_sparsity(index)[source]

returns matrix of measurement.

this function uses the scipy.sparse module.

Parameters

index (Union[int, Tuple]) – index of vec of measurement. if type is int, then regardes it as the index for CompositeSystem. if type is Tuple, then regardes it as the indices for earch ElementalSystems.

Returns

matrix of measurement.

Return type

np.ndarray

property num_outcomes: int

Property to get the number of POVM elements.

Returns

the number of POVM elements.

Return type

int

property nums_local_outcomes: List[int]

Property to get the list of the number of POVM elements.

Returns

the list of the number of POVM elements.

Return type

List[int]

set_zero()[source]

sets parameters to zero.

this function must be implemented in the subclass.

Raises

NotImplementedError – this function does not be implemented in the subclass.

to_stacked_vector()[source]

converts QOperation to stacked vector.

this function must be implemented in the subclass.

Returns

stacked vector representation of QOperation.

Return type

np.ndarray

Raises

NotImplementedError – this function does not be implemented in the subclass.

to_var()[source]

converts QOperation to variables.

this function must be implemented in the subclass.

Returns

variable representation of QOperation.

Return type

np.ndarray

Raises

NotImplementedError – this function does not be implemented in the subclass.

vec(index)[source]

returns vec of measurement by index.

Parameters

index (Union[int, Tuple]) – index of vec of measurement. If type is an int, access is one-dimensional. If type is tuple, access is multi-dimensional.

Returns

vec of measurement by index.

Return type

np.ndarray

Raises
  • ValueError – length of tuple does not equal length of the list of measurements.

  • IndexError – specified index does not exist in the list of measurements.

property vecs: List[numpy.ndarray]

Property to get vecs of povm.

Returns

vecs of povm.

Return type

List[np.ndarray]

calc_gradient_from_povm(c_sys, vecs, 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=None, eps_truncate_imaginary_part=None)[source]

calculates gradient from gate.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this gate.

  • vecs (List[np.ndarray]) – list of vec of povm elements.

  • 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 (Optional[float]) –

  • eps_truncate_imaginary_part (Optional[float]) –

Returns

Povm with gradient as vecs.

Return type

Povm

convert_povm_index_to_var_index(c_sys, vecs, povm_index, on_para_eq_constraint=True)[source]

converts povm index to variable index.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this gate.

  • vecs (List[np.ndarray]) – list of vec of povm elements.

  • povm_index (Tuple[int, int]) – povm index. first value of tuple is an index of the number of measurements. second value of tuple is an index in specific measurement.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

variable index.

Return type

int

convert_var_index_to_povm_index(c_sys, vecs, var_index, on_para_eq_constraint=True)[source]

converts variable index to povm index.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this gate.

  • vecs (List[np.ndarray]) – list of vec of povm elements.

  • var_index (int) – variable index.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

povm index. first value of tuple is an index of the number of measurements. second value of tuple is an index in specific measurement.

Return type

Tuple[int, int]

convert_var_to_povm(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=None)[source]

converts vec of variables to povm.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • var (List[np.ndarray]) – list of vec of povm elements.

  • 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 (Optional[float]) –

Returns

converted povm.

Return type

Povm

convert_var_to_vecs(c_sys, var, on_para_eq_constraint=True)[source]

converts variables to vecs.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this gate.

  • var (np.ndarray) – variables of povm elements.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

list of vec of povm elements.

Return type

List[np.ndarray]

convert_vecs_to_var(c_sys, vecs, on_para_eq_constraint=True)[source]

converts hs of povm to vec of variables.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this state.

  • vecs (List[np.ndarray]) – list of vec of povm elements.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

list of vec of variables.

Return type

np.ndarray

get_x_povm(c_sys)[source]

returns POVM of X measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

X measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 1quit.

  • ValueError – dim of CompositeSystem does not equal 2

get_xx_povm(c_sys)[source]

returns POVM of XX measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

XX measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_xy_povm(c_sys)[source]

returns POVM of XY measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

XY measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_xz_povm(c_sys)[source]

returns POVM of XZ measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

XZ measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_y_povm(c_sys)[source]

returns POVM of Y measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

Y measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 1quit.

  • ValueError – dim of CompositeSystem does not equal 2

get_yx_povm(c_sys)[source]

returns POVM of YX measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

YX measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_yy_povm(c_sys)[source]

returns POVM of YY measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

YY measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_yz_povm(c_sys)[source]

returns POVM of YZ measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

YZ measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_z_povm(c_sys)[source]

returns POVM of Z measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

Z measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 1quit.

  • ValueError – dim of CompositeSystem does not equal 2

get_zx_povm(c_sys)[source]

returns POVM of ZX measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

ZX measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_zy_povm(c_sys)[source]

returns POVM of ZY measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

ZY measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

get_zz_povm(c_sys)[source]

returns POVM of ZZ measurement.

Parameters

c_sys (CompositeSystem) – CompositeSystem containing POVM.

Returns

ZZ measurement.

Return type

Povm

Raises
  • ValueError – CompositeSystem is not 2quit.

  • ValueError – dim of CompositeSystem does not equal 4

to_matrices_from_var(c_sys, var, on_para_eq_constraint=True)[source]

converts var to matrices.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • var (np.ndarray) – variables of povm elements.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

matrices of this povm.

Return type

List[np.ndarray]

to_matrices_from_vecs(c_sys, vecs)[source]

returns matrices of measurements.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • List[np.ndarray] – matrices of vec of this povm.

  • vecs (List[numpy.ndarray]) –

Returns

matrices of measurements.

Return type

List[np.ndarray]

to_var_from_matrices(c_sys, matrices, on_para_eq_constraint=True)[source]

converts matrices to var.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • matrices (List[np.ndarray]) – matrices of this povm.

  • on_para_eq_constraint (bool, optional) – uses equal constraints, by default True.

Returns

variables of povm elements.

Return type

np.ndarray

to_vec_from_matrix_with_sparsity(c_sys, matrix, eps_truncate_imaginary_part=None)[source]

converts matrix to vec.

this function uses the scipy.sparse module.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • matrix (np.ndarray) – matrix of vec of this povm.

  • eps_truncate_imaginary_part (float, optional) – threshold to truncate imaginary part, by default get_atol()

Returns

vec of variables.

Return type

np.ndarray

to_vecs_from_matrices_with_sparsity(c_sys, matrices)[source]

converts matrices to vecs.

this function uses the scipy.sparse module.

Parameters
  • c_sys (CompositeSystem) – CompositeSystem of this povm.

  • matrices (List[np.ndarray]) – matrices of this povm.

Returns

vecs of variables.

Return type

np.ndarray