QOperation
[1]:
import numpy as np
np.set_printoptions(linewidth=200)
QOperation
This notebook describes the concept of QOperation in Quara and the related classes.
Quara supports operations such as State, Gate, Povm, etc. These operations is called objects in Quara. Two methods to generate objects. - The typical objects can be generated from a module called xxx_typical. (“xxx” is a object name.) - Users can also generate objects directly.
QOperation is the base class of these operations and has common properties and functions.
common properties
The common properties are as follows:
is_physicality_required- If this is True, this object must satisfy the physicality.is_estimation_object- If this is True, this object is for estimation.on_para_eq_constraint- If this is True, functions and algorithms work on the assumption that the parameters of this object satisfy the equality constraint.on_algo_eq_constraint- If this is True, estimation algorithms use equality constraint.on_algo_ineq_constraint- If this is True, estimation algorithms use inequality constraint.mode_proj_order- the order in which the projection are performed, by default “eq_ineq”.“eq_ineq” - The projection are performed in the order of equality constraints, followed by inequality constraints.
“ineq_eq” - The projection are performed in the order of inequality constraints, followed by equality constraints.
eps_proj_physical- Epsiron that is projection algorithm error threshold for being physical.eps_truncate_imaginary_part- The threshold to truncate imaginary part.
[2]:
from quara.objects.composite_system_typical import generate_composite_system
from quara.objects.qoperation import QOperation
c_sys = generate_composite_system("qubit", 1)
qoperation = QOperation(c_sys)
print(f"is_physicality_required: {qoperation.is_physicality_required}")
print(f"is_estimation_object: {qoperation.is_estimation_object}")
print(f"on_para_eq_constraint: {qoperation.on_para_eq_constraint}")
print(f"on_algo_eq_constraint: {qoperation.on_algo_eq_constraint}")
print(f"on_algo_ineq_constraint: {qoperation.on_algo_ineq_constraint}")
print(f"mode_proj_order: {qoperation.mode_proj_order}")
print(f"eps_proj_physical: {qoperation.eps_proj_physical}")
print(f"eps_truncate_imaginary_part: {qoperation.eps_truncate_imaginary_part}")
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: 1e-14
eps_truncate_imaginary_part: None
functions to check constraints
QOperation has functions to check constraints.
is_eq_constraint_satisfied()- Whether the qoperation is satisfied equality constraints.is_ineq_constraint_satisfied()- Whether the qoperation is satisfied inequality constraints.is_physical()- Whether the qoperation is satisfied equality and inequality constraints.
is_eq_constraint_satisfied() and is_ineq_constraint_satisfied() are abstract functions and are implemented in a subclasses.
projection functions
QOperation has projection functions.
calc_proj_eq_constraint()- Calculates the projection of QOperation on equal constraint.calc_proj_ineq_constraint()- Calculates the projection of QOperation on inequal constraint.calc_proj_physical()- Calculates the projection of QOperation on equal and inequal constraint.calc_proj_physical_with_var()- Executes the algorithm of calc_proj_physical using variables. This functions is faster than calc_proj_physical.
calc_proj_physical() and calc_proj_physical_with_var() calculate the projection in the order specified by mode_proj_order.
functions to transform parameters
QOperation has functions to transform parameters.
to_stacked_vector()- Transforms all parameters to a one-dimensional vector (a numpy array).to_var()- Transforms parameters except for the part of the equality constraint to a one-dimensional vector (a numpy array).
These functions are abstract functions and are implemented in a subclasses.
functions to generate special objects
QOperation has functions to generate special objects.
generate_zero_obj()- Generates object with all parameters are zero.generate_origin_obj()- Generates origin object.
These functions are abstract functions and are implemented in a subclasses.
supports arithmetic operations
Quara supports arithmetic operations between same type of QOperations.
__add__()- Calculatesa + bfor Qoperation a, b.__sub__()- Calculatesa - bfor Qoperation a, b.__mul__()- Calculatesa * bfor Qoperation a and number b.__rmul__()- Calculatesa * bfor number a and Qoperation b.__truediv__()- Calculatesa / bfor Qoperation a and number b.