quara.interface.cvxpy.conversion module

choi_from_var(c_sys, var)[source]

Converts from Variable of quara or cvxpy to Choi matrix.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

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

Returns

Choi matrix

Return type

Union[np.ndarray, CvxpyVariable]

choi_from_var_with_sparsity(c_sys, var)[source]

Converts from Variable of quara or cvxpy to Choi matrix with sparsity.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

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

Returns

Choi matrix

Return type

Union[np.ndarray, CvxpyVariable]

convert_cvxpy_variable_to_gate(c_sys, var)[source]

Converts from Variable of CVXPY to gate.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • var (CvxpyVariable) – Variable of CVXPY

Returns

gate

Return type

Gate

convert_cvxpy_variable_to_gate_hs(dim, var)[source]

Converts from Variable of CVXPY to HS matrix of gate.

Parameters
  • dim (int) – Dimension of the system

  • var (CvxpyVariable) – Variable of CVXPY

Returns

HS matrix of gate

Return type

np.ndarray

convert_cvxpy_variable_to_mprocess(c_sys, num_outcomes, var)[source]

Converts from Variable of CVXPY to mprocess.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • var (CvxpyVariable) – Variable of CVXPY

Returns

mprocess

Return type

MProcess

convert_cvxpy_variable_to_mprocess_hss(dim, num_outcomes, var)[source]

Converts from Variable of CVXPY to HS matrices of mprocess.

Parameters
  • dim (int) – Dimension of the system

  • num_outcomes (int) – Number of outcomes

  • var (CvxpyVariable) – Variable of CVXPY

Returns

HS matrices of mprocess

Return type

List[np.ndarray]

convert_cvxpy_variable_to_povm(c_sys, num_outcomes, var)[source]

Converts from Variable of CVXPY to povm.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • var (CvxpyVariable) – Variable of CVXPY

Returns

povm

Return type

Povm

convert_cvxpy_variable_to_qoperation(t, c_sys, var, num_outcomes=None)[source]

Converts from Variable of CVXPY to QOperation.

Parameters
  • t (str) – Type of estimate, “state”, “povm”, “gate”, or “mprocess”.

  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • var (CvxpyVariable) – Variable of CVXPY

  • num_outcoms (int, optional) – Number of outcomes for t = “povm” or “mprocess”, by default None

  • num_outcomes (Optional[int]) –

Returns

QOperation

Return type

QOperation

Raises

ValueError – Unsupported type of QOperation is specified.

convert_cvxpy_variable_to_state(c_sys, var)[source]

Converts from Variable of CVXPY to state.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • var (CvxpyVariable) – Variable of CVXPY

Returns

state

Return type

State

convert_cxvpy_variable_to_povm_vecs(dim, num_outcomes, var)[source]

Converts from Variable of CVXPY to vecs of povm.

Parameters
  • dim (int) – Dimension of the system

  • num_outcomes (int) – Number of outcomes

  • var (CvxpyVariable) – Variable of CVXPY

Returns

vecs of povm

Return type

np.ndarray

convert_cxvpy_variable_to_state_vec(dim, var)[source]

Converts from Variable of CVXPY to vec of state.

Parameters
  • dim (int) – Dimension of the system

  • var (CvxpyVariable) – Variable of CVXPY

Returns

vec of state

Return type

np.ndarray

convert_quara_variable_to_gate(c_sys, var)[source]

Converts from Variable in quara to gate.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • var ([type]) – Variable in quara

Returns

gate

Return type

Gate

convert_quara_variable_to_gate_hs(dim, var)[source]

Converts from Variable in quara to HS matrix of gate.

Parameters
  • dim (int) – Dimension of the system

  • var (np.ndarray) – Variable in quara

Returns

HS matrix of gate

Return type

np.ndarray

convert_quara_variable_to_mprocess(c_sys, num_outcomes, var)[source]

Converts from Variable in quara to mprocess.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • var (np.ndarray) – Variable in quara

Returns

mprocess

Return type

MProcess

convert_quara_variable_to_mprocess_hss(dim, num_outcomes, var)[source]

Converts from Variable in quara to HS matrices of mprocess.

Parameters
  • dim (int) – Dimension of the system

  • num_outcomes (int) – Number of outcomes

  • var (np.ndarray) – Variable in quara

Returns

HS matrices of mprocess

Return type

List[np.ndarray]

convert_quara_variable_to_povm(c_sys, num_outcomes, var)[source]

Converts from Variable in quara to povm.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • var (np.ndarray) – Variable in quara

Returns

povm

Return type

Povm

convert_quara_variable_to_povm_vecs(dim, num_outcomes, var)[source]

Converts from Variable in quara to vecs of povm.

Parameters
  • dim (int) – Dimension of the system

  • num_outcomes (int) – Number of outcomes

  • var (np.ndarray) – Variable in quara

Returns

vecs of povm

Return type

List[np.ndarray]

convert_quara_variable_to_qoperation(t, c_sys, var, num_outcomes=None)[source]

Converts from Variable in quara to QOperation.

Parameters
  • t (str) – Type of QOperation. “state”, “povm”, “gate”, or “mprocess”

  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • var (np.ndarray) – Variable in quara

  • num_outcomes (int, optional) – Number of outcomes for t = “povm” or “mprocess”, by default None

Returns

QOperation

Return type

QOperation

Raises

ValueError – Unsupported type of QOperation is specified.

convert_quara_variable_to_state(c_sys, var)[source]

Converts from Variable in quara to state.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • var (np.ndarray) – Variable in quara

Returns

state

Return type

State

convert_quara_variable_to_state_vec(dim, var)[source]

Converts from Variable in quara to vec of state.

Parameters
  • dim (int) – Dimension of the system

  • var (np.ndarray) – Variable in quara

Returns

vec of state.

Return type

np.ndarray

dmat_from_var(c_sys, var)[source]

Converts from Variable of quara or cvxpy to density matrix.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

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

Returns

Density matrix

Return type

Union[np.ndarray, CvxpyVariable]

dmat_from_var_with_sparsity(c_sys, var)[source]

Converts from Variable of quara or cvxpy to density matrix with sparsity.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

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

Returns

Density matrix

Return type

Union[np.ndarray, CvxpyVariable]

generate_cvxpy_constraints_from_cvxpy_variable(c_sys, t, var, num_outcomes=None)[source]

Returns Constraint of CVXPY

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • t (str) – Type of QOperation. “state”, “povm”, “gate”, or “mprocess”

  • var (CvxpyVariable) – Variable of CVXPY

  • num_outcoms (int, optional) – Number of outcomes for t = “povm” or “mprocess”, by default None

  • num_outcomes (Optional[int]) –

Returns

Constraint of CVXPY

Return type

CvxpyConstraint

Raises

ValueError – Unsupported type of QOperation is specified.

generate_cvxpy_constraints_from_cvxpy_variable_with_sparsity(c_sys, t, var, num_outcomes=None)[source]

Returns list of Constraint of CVXPY

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • t (str) – Type of QOperation. “state”, “povm”, “gate”, or “mprocess”

  • var (CvxpyVariable) – Variable of CVXPY

  • num_outcomes (int, optional) – Number of outcomes for t = “povm” or “mprocess”, by default None

Returns

List of Constraint of CVXPY

Return type

List[CvxpyConstraint]

Raises

ValueError – Unsupported type of QOperation is specified.

generate_cvxpy_variable(t, dim, num_outcomes=None)[source]

Returns number of optimization variable

Parameters
  • t (str) – Type of QOperation. “state”, “povm”, “gate”, or “mprocess”

  • dim (int) – Dimension of the system

  • num_outcoms (int, optional) – Number of outcomes for t = “povm” or “mprocess”, by default None

  • num_outcomes (Optional[int]) –

Returns

Variable of CVXPY

Return type

CvxpyVariable

get_valid_qopeartion_type()[source]

Returns the list of valid QOperation types.

Returns

the list of valid QOperation types.

Return type

List[str]

mprocess_element_choi_from_var(c_sys, num_outcomes, x, var)[source]

Converts from Variable of quara or cvxpy to mprocess element.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • x (int) – Index of mprocess element

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

Returns

mprocess element

Return type

Union[np.ndarray, CvxpyVariable]

mprocess_element_choi_from_var_with_sparsity(c_sys, num_outcomes, x, var)[source]

Converts from Variable of quara or cvxpy to mprocess element with sparsity.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • x (int) – Index of mprocess element

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

Returns

mprocess element

Return type

Union[np.ndarray, CvxpyVariable]

num_cvxpy_variable(t, dim, num_outcomes=None)[source]

Returns number of optimization variable

Parameters
  • t (str) – Type of QOperation. “state”, “povm”, “gate”, or “mprocess”

  • dim (int) – Dimension of the system

  • num_outcoms (int, optional) – Number of outcomes for t = “povm” or “mprocess”, by default None

  • num_outcomes (Optional[int]) –

Returns

Number of optimization variable

Return type

int

Raises
  • ValueError – Unsupported type of QOperation is specified.

  • ValueError – dim is not a posivite number.

  • ValueError – Type of QOperation is povm, but num_outcomes is not specified.

  • ValueError – Type of QOperation is mprocess, but num_outcomes is not specified.

povm_element_from_var(c_sys, num_outcomes, x, var)[source]

Converts from Variable of quara or cvxpy to povm element.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

  • num_outcomes (int) – Number of outcomes

  • x (int) – Index of povm element

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

Returns

povm element

Return type

Union[np.ndarray, CvxpyVariable]

povm_matrices_from_var_with_sparsity(c_sys, var)[source]

Converts from Variable of quara or cvxpy to povm matrices with sparsity.

Parameters
  • c_sys (CompositeSystem) – Composite system that the QOperation acts on

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

Returns

List of povm matrices

Return type

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