quara.interface.cvxpy.qtomography.standard.loss_function module

class CvxpyApproximateRelativeEntropyWithZeroProbabilityTerm[source]

Bases: quara.interface.cvxpy.qtomography.standard.loss_function.CvxpyLossFunction

Constructor

Parameters

num_var (int, optional) – number of variables, by default None

value_cvxpy(var)[source]

returns the value of the loss function in the form of Expression of CVXPY.

Parameters

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

Returns

the value of the loss function in the form of Expression of CVXPY.

Return type

CvxpyExpression

Raises

ValueError – prob_dists_data is not set.

class CvxpyLossFunction(num_var=None)[source]

Bases: quara.loss_function.loss_function.LossFunction

Constructor

Parameters

num_var (int, optional) – number of variables, by default None

calc_average_num_data()[source]

calculates average of numbers of data.

Returns

average of numbers of data.

Return type

np.float64

calc_prob_model(i, x, var)[source]

calculates probability model.

Parameters
  • i (int) – schedule index.

  • x (int) – measurement outcome index.

  • var (Union[np.ndarray, CvxpyVariable]) – Variable of CVXPY

Returns

probability model.

Return type

Union[np.float64, CvxpyExpression]

property composite_system: quara.objects.composite_system.CompositeSystem

returns CompositeSystem of type of estimate.

composite_system is set in set_standard_qtomography function.

Returns

CompositeSystem of type of estimate

Return type

CompositeSystem

dim_system()[source]

returns dimension of CompositeSystem.

dim_system is set in set_standard_qtomography function.

Returns

dimension of CompositeSystem.

Return type

int

property eps_prob_zero: numpy.float64

returns threshold to truncate probability

Returns

Threshold to truncate probability

Return type

np.float64

erase_prob_dists_data()[source]

erases probability distributions of data.

Return type

None

property num_data_ratios: List[numpy.float64]

returns ratios of data.

num_data_ratios is set in set_prob_dists_data_from_empi_dists function.

Returns

ratios of data.

Return type

List[np.float64]

property num_data_total: int

returns number of total of data(sum of data).

num_data_total is set in set_prob_dists_data_from_empi_dists function.

Returns

number of total of data.

Return type

int

num_outcomes_estimate()[source]

returns number of outcomes of estimate.

num_outcomes_estimate is set in set_standard_qtomography function.

Returns

number of outcomes of estimate.

Return type

int

Raises

ValueError – num_outcomes_estimate of StandardQTomography is neither ‘povm’ nor ‘mprocess’.

property nums_data: List[int]

returns numbers of data.

nums_data is set in set_prob_dists_data_from_empi_dists function.

Returns

numbers of data.

Return type

List[int]

property on_prob_dists_data: bool

returns whether prob_dists_data is set.

Returns

whether prob_dists_data is set.

Return type

bool

property on_value_cvxpy: bool

returns whether or not to support value_cvxpy.

Returns

whether or not to support value_cvxpy.

Return type

bool

property prob_dists_data: List[numpy.ndarray]

returns probability distributions of data.

Returns

probability distributions of data.

Return type

List[np.ndarray]

set_from_option(option)[source]

sets option from CvxpyLossFunctionOption.

Parameters

option (CvxpyLossFunctionOption) – option to set.

Return type

None

set_prob_dists_data(ps)[source]

sets probability distributions of data.

Parameters

ps (List[np.ndarray]) – probability distributions of data.

Return type

None

set_prob_dists_data_from_empi_dists(empi_dists)[source]

sets probability distributions of data from empirical distributions.

Parameters

empi_dists (List[Tuple[int, np.ndarray]]) – empirical distributions.

Return type

None

set_standard_qtomography(sqt)[source]

sets StandardQTomography for settings of loss function.

Parameters

sqt (StandardQTomography) – StandardQTomography for settings of loss function.

Raises

ValueError – on_para_eq_constraint of StandardQTomography is False.

Return type

None

property sqt: quara.protocol.qtomography.standard.standard_qtomography.StandardQTomography

returns StandardQTomography for settings of loss function.

Returns

StandardQTomography for settings of loss function.

Return type

StandardQTomography

property type_estimate: str

returns Type of QOperation. “state”, “povm”, “gate”, or “mprocess”.

type_estimate is set in set_standard_qtomography function.

Returns

Type of QOperation.

Return type

str

value(var)[source]

returns the value of the loss function.

Parameters

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

Returns

the value of the loss function.

Return type

np.float64

abstract value_cvxpy(var)[source]

returns CvxpyExpression of the loss function.

Parameters

var (CvxpyVariable) – Variable of CVXPY

Returns

CvxpyExpression of the loss function.

Return type

CvxpyExpression

Raises

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

class CvxpyLossFunctionOption(eps_prob_zero=1e-12)[source]

Bases: quara.loss_function.loss_function.LossFunctionOption

Constructor

Parameters

eps_prob_zero (np.float64, optional) – Threshold to truncate probability, by default 1e-12

property eps_prob_zero: numpy.float64

returns threshold to truncate probability

Returns

Threshold to truncate probability

Return type

np.float64

class CvxpyRelativeEntropy[source]

Bases: quara.interface.cvxpy.qtomography.standard.loss_function.CvxpyLossFunction

Constructor

is_option_sufficient()[source]

returns whether the option is sufficient.

In the default implementation, this function returns True. Override with subclasses as needed.

Returns

whether the option is sufficient.

Return type

bool

value_cvxpy(var)[source]

returns the value of the loss function in the form of Expression of CVXPY.

Parameters

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

Returns

the value of the loss function in the form of Expression of CVXPY.

Return type

CvxpyExpression

Raises

ValueError – prob_dists_data is not set.

class CvxpyUniformSquaredError[source]

Bases: quara.interface.cvxpy.qtomography.standard.loss_function.CvxpyLossFunction

Constructor

Parameters

num_var (int, optional) – number of variables, by default None

value_cvxpy(var)[source]

returns the value of the loss function in the form of Expression of CVXPY.

Parameters

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

Returns

the value of the loss function in the form of Expression of CVXPY.

Return type

CvxpyExpression

Raises

ValueError – prob_dists_data is not set.