quara.objects.mprocess module

class MProcess(c_sys, hss, shape=None, mode_sampling=False, random_seed_or_generator=None, 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, eps_zero=1e-08)[source]

Bases: quara.objects.qoperation.QOperation

Constructor

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

  • is_physicality_required (bool, optional) – whether this QOperation is physicality required, by default True

  • is_estimation_object (bool, optional) – whether this QOperation is estimation object, by default True

  • on_para_eq_constraint (bool, optional) – whether this QOperation is on parameter equality constraint, by default True

  • on_algo_eq_constraint (bool, optional) – whether this QOperation is on algorithm equality constraint, by default True

  • on_algo_ineq_constraint (bool, optional) – whether this QOperation is on algorithm inequality constraint, by default True

  • mode_proj_order (str, optional) – the order in which the projections are performed, by default “eq_ineq”

  • eps_proj_physical (float, optional) – epsiron that is projection algorithm error threshold for being physical, by default get_atol() / 10.0

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

  • hss (List[numpy.ndarray]) –

  • shape (Tuple[int]) –

  • mode_sampling (bool) –

  • random_seed_or_generator (Union[int, numpy.random._generator.Generator]) –

  • eps_zero (Union[float, numpy.float64]) –

Raises

ValueErroreps_proj_physical is negative.

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]
Parameters
Return type

numpy.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]
Parameters
Return type

numpy.ndarray

convert_basis(other_basis)[source]

returns list of HS representations for other_basis. :param other_basis: basis. :type other_basis: MatrixBasis

Returns

list of HS representations for other_basis.

Return type

List[np.ndarray]

Parameters

other_basis (quara.objects.matrix_basis.SparseMatrixBasis) –

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

converts stacked vector of MProcess to variables of MProcess.

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

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

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

Returns

variables of MProcess.

Return type

np.ndarray

convert_to_comp_basis(mode='row_major')[source]

returns list of HS representations for computational basis. :param mode: specify whether the order of basis is “row_major” or “column_major”, by default “row_major”. :type mode: str, optional

Returns

list of HS representations for computational basis.

Return type

List[np.ndarray]

Parameters

mode (str) –

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

converts variables of MProcess to stacked vector of MProcess.

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

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

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

Returns

stacked vector of MProcess.

Return type

np.ndarray

copy()[source]

returns copy of MProcess.

Returns

copy of MProcess.

Return type

MProcess

property dim

returns dim of gate.

Returns

dim of gate.

Return type

int

property eps_zero
generate_from_var(var, is_physicality_required=None, is_estimation_object=None, on_para_eq_constraint=None, on_algo_eq_constraint=None, on_algo_ineq_constraint=None, mode_proj_order='eq_ineq', eps_proj_physical=None, eps_truncate_imaginary_part=None)[source]

generates QOperation from variables.

Parameters
  • var (np.ndarray) – variables.

  • is_physicality_required (bool, optional) – whether this QOperation is physicality required, by default None. if this parameter is None, the value of this instance is set.

  • is_estimation_object (bool, optional) – whether this QOperation is estimation object, by default None. if this parameter is None, the value of this instance is set.

  • on_para_eq_constraint (bool, optional) – whether this QOperation is on parameter equality constraint, by default None. if this parameter is None, the value of this instance is set.

  • on_algo_eq_constraint (bool, optional) – whether this QOperation is on algorithm equality constraint, by default None. if this parameter is None, the value of this instance is set.

  • on_algo_ineq_constraint (bool, optional) – whether this QOperation is on algorithm inequality constraint, by default None. if this parameter is None, the value of this instance is set.

  • mode_proj_order (str, optional) – the order in which the projections are performed, by default “eq_ineq”.

  • eps_proj_physical (float, optional) – epsiron that is projection algorithm error threshold for being physical, by default None. if this parameter is None, the value of this instance is set.

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

Returns

generated QOperation.

Return type

QOperation

generate_origin_obj()[source]

returns origin object of MProcess.

Returns

origin object of MProcess.

Return type

MProcess

generate_zero_obj()[source]

returns zero object of QOperation.

Returns

zero object of QOperation.

Return type

QOperation

get_basis()[source]

returns MatrixBasis of gate. :returns: MatrixBasis of gate. :rtype: MatrixBasis

Return type

quara.objects.matrix_basis.SparseMatrixBasis

hs(index)[source]

returns HS representations of MProcess by index.

Parameters

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

Returns

HS of MProcess by index.

Return type

np.ndarray

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

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

property hss

returns HS representations of MProcess.

Returns

HS representations of MProcess.

Return type

np.ndarray

is_cp(atol=None)[source]
Parameters

atol (Optional[float]) –

Return type

bool

is_eq_constraint_satisfied(atol=None)[source]
Parameters

atol (Optional[float]) –

Return type

bool

is_ineq_constraint_satisfied(atol=None)[source]
Parameters

atol (Optional[float]) –

Return type

bool

is_sum_tp(atol=None)[source]
Parameters

atol (Optional[float]) –

Return type

bool

property mode_sampling: bool

returns the mode of sampling.

if mode_sampling is True, samples to determine one HS.

Returns

the mode of sampling.

Return type

bool

property num_outcomes: int

Property to get the number of HSs.

Returns

the number of HSs.

Return type

int

property random_seed_or_generator: Union[int, numpy.random._generator.Generator]

returns the random seed or state to sample HS.

Returns

the random seed or state to sample HS.

Return type

Union[int, np.random.Generator]

property random_state: numpy.random._generator.Generator

returns the random state to sample HS.

Returns

the random state to sample HS.

Return type

np.random.Generator

set_mode_sampling(mode_sampling, random_seed_or_generator=None)[source]
Parameters
  • mode_sampling (bool) –

  • random_seed_or_generator (Optional[Union[int, numpy.random._generator.Generator]]) –

Return type

None

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.

property shape: Tuple[int]

returns shape.

Returns

the shape of MProcess.

Return type

Tuple[int]

to_choi_matrix(outcome)[source]

returns Choi matrix of gate.

Parameters

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

Returns

Choi matrix of gate.

Return type

np.ndarray

to_choi_matrix_with_dict(outcome)[source]

returns Choi matrix of gate.

Parameters

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

Returns

Choi matrix of gate.

Return type

np.ndarray

to_choi_matrix_with_sparsity(outcome)[source]

returns Choi matrix of gate.

Parameters

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

Returns

Choi matrix of gate.

Return type

np.ndarray

to_kraus_matrices(outcome)[source]

returns Kraus matrices of gate.

this function returns Kraus matrices as list of np.ndarray with dtype=np.complex128. the list is sorted large eigenvalue order. if HS of gate is not CP, then returns empty list because Kraus matrices does not exist.

Parameters

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

Returns

Kraus matrices of gate.

Return type

List[np.ndarray]

to_povm()[source]
Return type

quara.objects.povm.Povm

to_process_matrix(outcome)[source]

returns process matrix of gate.

Parameters

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

Returns

process matrix of gate.

Return type

np.ndarray

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.

calc_gradient_from_mprocess(c_sys, hss, var_index, shape=None, mode_sampling=False, random_seed_or_generator=None, 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 MProcess.

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

  • hss (List[np.ndarray]) – list of HS representation of this MProcess.

  • var_index (int) – variable index.

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

  • shape (Optional[Tuple[int]]) –

  • mode_sampling (bool) –

  • random_seed_or_generator (Optional[Union[int, numpy.random._generator.Generator]]) –

  • 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

MProcess with gradient as hss.

Return type

MProcess

convert_hss_to_var(c_sys, hss, on_para_eq_constraint=True)[source]

converts hss of MProcess to variables.

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

  • hss (List[np.ndarray]) – list of HS representation of this MProcess.

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

Returns

variables.

Return type

np.ndarray

convert_mprocess_index_to_var_index(c_sys, mprocess_index, hss, on_para_eq_constraint=True)[source]

converts MProcess index to variable index.

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

  • mprocess_index (Tuple[int, int, int]) – MProcess index. first value of tuple is index of list of HS representation of this MProcess. second value of tuple is row number of HS representation of this MProcess. third value of tuple is column number of HS representation of this MProcess.

  • hss (List[np.ndarray]) – list of HS representation.

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

Returns

variable index.

Return type

int

convert_var_index_to_mprocess_index(c_sys, hss, var_index, on_para_eq_constraint=True)[source]

converts variable index to MProcess index.

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

  • hss (List[np.ndarray]) – list of HS representation.

  • var_index (int) – variable index.

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

Returns

MProcess index. first value of tuple is index of list of HS representation of this MProcess. second value of tuple is row number of HS representation of this MProcess. third value of tuple is column number of HS representation of this MProcess.

Return type

Tuple[int, int, int]

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

converts variables of MProcess to list of HS representation.

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

  • var (np.ndarrayd@y) – variables of gate.

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

Returns

list of HS representation of this MProcess.

Return type

List[np.ndarray]