quara.objects.qoperation module

class QOperation(c_sys, 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: object

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()

Raises

ValueErroreps_proj_physical is negative.

abstract 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.

abstract calc_proj_eq_constraint()[source]

calculates the projection of QOperation on equal constraint.

Returns

the projection of QOperation on equal constraint.

Return type

QOperation

abstract calc_proj_ineq_constraint()[source]

calculates the projection of QOperation on inequal constraint.

Returns

the projection of QOperation on inequal constraint.

Return type

QOperation

calc_proj_physical(max_iteration=1000, is_iteration_history=False)[source]

calculates the projection of QOperation with physically correctness.

Parameters
  • max_iteration (int, optional) – maximun number of iterations, by default 1000.

  • is_iteration_history (bool, optional) – whether this function returns iteration history, by default False.

Returns

if is_iteration_history is True, returns the projection of QOperation with physically correctness and iteration history. otherwise, returns only the projection of QOperation with physically correctness.

iteration history forms the following dict:

{
“p”: list of opject p,
”q”: list of opject q,
”x”: list of opject x,
”y”: list of opject y,
”error_value”: list of opject error_value,
}

When step=0, “y” and “error_value” are not calculated, so None is set.

Return type

Union[“QOperation”, Tuple[“QOperation”, Dict]]

calc_proj_physical_with_var(var, on_para_eq_constraint=True, max_iteration=1000, is_iteration_history=False)[source]

calculates the projection of variables with physically correctness.

Parameters
  • var (np.ndarray) – variables.

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

  • max_iteration (int, optional) – maximun number of iterations, by default 1000.

  • is_iteration_history (bool, optional) – whether this function returns iteration history, by default False.

Returns

if is_iteration_history is True, returns the projection of variables with physically correctness and iteration history. otherwise, returns only the projection of variables with physically correctness.

iteration history forms the following dict:

{
“p”: list of opject p,
”q”: list of opject q,
”x”: list of opject x,
”y”: list of opject y,
”error_value”: list of opject error_value,
}

When step=0, “y” and “error_value” are not calculated, so None is set.

Return type

Union[np.ndarray, Tuple[np.ndarray, Dict]]

property composite_system: quara.objects.composite_system.CompositeSystem

Property to get composite system.

Returns

composite system.

Return type

CompositeSystem

copy()[source]

returns copy of QOperation.

Returns

copy of QOperation.

Return type

QOperation

static embed_qoperation_from_qutrits_to_qubits(qoperation, e_syss)[source]

embeds qoperation from qutrits to qubits.

Parameters
  • qoperation (QOperation) – QOperation to embed from qutrits.

  • e_syss (List[ElementalSystem]) – list of ElementalSystem to embed to qubits.

Returns

qoperation embeded to qubits.

Return type

QOperation

Raises

ValueError – 2x num_qutrits and len(e_syss) are not equal.

property eps_proj_physical: float

returns epsiron that is projection algorithm error threshold for being physical.

Returns

epsiron that is projection algorithm error threshold for being physical.

Return type

float

property eps_truncate_imaginary_part: float

returns threshold to truncate imaginary part, by default get_atol()

Returns

threshold to truncate imaginary part.

Return type

float

abstract estimation_object_type()[source]

returns type of estimation object.

Returns

type of estimation object.

Return type

type

Raises

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

func_calc_proj_eq_constraint(on_para_eq_constraint=None)[source]
Parameters

on_para_eq_constraint (Optional[bool]) –

Return type

Callable[[numpy.ndarray], numpy.ndarray]

func_calc_proj_eq_constraint_with_var(on_para_eq_constraint=None)[source]
Parameters

on_para_eq_constraint (Optional[bool]) –

Return type

Callable[[numpy.ndarray], numpy.ndarray]

func_calc_proj_ineq_constraint(on_para_eq_constraint=None)[source]
Parameters

on_para_eq_constraint (Optional[bool]) –

Return type

Callable[[numpy.ndarray], numpy.ndarray]

func_calc_proj_ineq_constraint_with_var(on_para_eq_constraint=None)[source]
Parameters

on_para_eq_constraint (Optional[bool]) –

Return type

Callable[[numpy.ndarray], numpy.ndarray]

func_calc_proj_physical(on_para_eq_constraint=None, mode_proj_order='eq_ineq', max_iteration=1000, is_iteration_history=False)[source]
Parameters
  • on_para_eq_constraint (Optional[bool]) –

  • mode_proj_order (str) –

  • max_iteration (int) –

  • is_iteration_history (bool) –

Return type

Callable[[numpy.ndarray], numpy.ndarray]

func_calc_proj_physical_with_var(on_para_eq_constraint=None, mode_proj_order='eq_ineq', max_iteration=1000)[source]
Parameters
  • on_para_eq_constraint (Optional[bool]) –

  • mode_proj_order (str) –

  • max_iteration (int) –

Return type

Callable[[numpy.ndarray], numpy.ndarray]

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)[source]

generates QOperation from variables.

Parameters
  • var (np.ndarray) –

  • 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.

Returns

generated QOperation.

Return type

QOperation

generate_origin_obj()[source]

returns origin object of QOperation.

Returns

origin object of QOperation.

Return type

QOperation

generate_zero_obj()[source]

returns zero object of QOperation.

Returns

zero object of QOperation.

Return type

QOperation

abstract is_eq_constraint_satisfied(atol=None)[source]
Parameters

atol (Optional[float]) –

property is_estimation_object: bool

returns whether this QOperation is estimation object.

Returns

whether this QOperation is estimation object.

Return type

bool

abstract is_ineq_constraint_satisfied(atol=None)[source]
Parameters

atol (Optional[float]) –

abstract is_physical(atol_eq_const=None, atol_ineq_const=None)[source]

returns whether the qoperation is physically correct.

Parameters
  • atol_eq_const (float, optional) – Error tolerance used to determine if the equality constraint is satisfied. The absolute tolerance parameter, uses get_atol() by default.

  • atol_ineq_const (float, optional) – Error tolerance used to determine if the inequality constraint is satisfied. The absolute tolerance parameter, uses get_atol() by default.

Returns

whether the qoperation is physically correct.

Return type

bool

property is_physicality_required: bool

returns whether this QOperation is physicality required.

Returns

whether this QOperation is physicality required.

Return type

bool

property mode_proj_order: str

returns the order in which the projections are performed.

Returns

the order in which the projections are performed.

Return type

str

property on_algo_eq_constraint: bool

returns whether this QOperation is on algorithm equality constraint.

Returns

whether this QOperation is on algorithm equality constraint.

Return type

bool

property on_algo_ineq_constraint: bool

returns whether this QOperation is on algorithm inequality constraint.

Returns

whether this QOperation is on algorithm inequality constraint.

Return type

bool

property on_para_eq_constraint: bool

returns whether this QOperation is on parameter equality constraint.

Returns

whether this QOperation is on parameter equality constraint.

Return type

bool

set_mode_proj_order(mode_proj_order)[source]

sets the order in which the projections are performed.

Parameters
  • str – the order in which the projections are performed.

  • mode_proj_order (str) –

Return type

None

abstract 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.

abstract 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.

abstract 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.