System
This notebook describes the concept of system in Quara and the related classes.
Quara supports operations such as State, Gate, Povm, etc. The system in which these operations are performed is called a CompositeSystem in Quara. To perform these operations, first generate a CompositeSystem. The methods for generating a CompositeSystem includes the following:
Generate from
composite_system_typicalmoduleGenerate CompositeSystem object directly
Both generate the same CompositeSystem.
Generate from composite_system_typical module by specifying mode (“qubit” or “qutrit”) and number of qubits.
[1]:
from quara.objects.composite_system_typical import generate_composite_system
c_sys = generate_composite_system("qubit", 2)
print(f"CompositeSystem: \n{c_sys}")
CompositeSystem:
elemental_systems:
[0] 0 (system_id=2245191296776)
[1] 1 (system_id=2245191296840)
dim: 4
basis:
(<4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>)
Generate CompositeSystem object directly using classes called MatrixBasis, ElementalSystem.
[2]:
from quara.objects.composite_system import CompositeSystem
from quara.objects.elemental_system import ElementalSystem
from quara.objects.matrix_basis import get_normalized_pauli_basis
basis = get_normalized_pauli_basis(1)
e_sys0 = ElementalSystem(0, basis)
e_sys1 = ElementalSystem(1, basis)
c_sys = CompositeSystem([e_sys0, e_sys1])
print(c_sys)
elemental_systems:
[0] 0 (system_id=2245192950920)
[1] 1 (system_id=2245192951112)
dim: 4
basis:
(<4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>, <4x4 sparse matrix of type '<class 'numpy.complex128'>'
with 4 stored elements in Compressed Sparse Row format>)
Fundamental Rules
Two methods to generate objects of Quara.
The typical objects can be generated from a module called
xxx_typical. (“xxx” is a object name.)Users can also generate objects directly.
The structure of CompositeSystem is nested as follows:
CompositeSystem corresponds to a whole system.
CompositeSystem has a list of ElementalSystems sorted in ascending order by name.
ElementalSystem corresponds to the unit of operation of qubits (or qutrits, qudits).
ElementalSystem has a tuple of name (int) and MatrixBasis.
The name is recommended to be named 0, 1, 2…
MatrixBasis corresponds to the basis of the system.
MatrixBasis has a basis represented by a list of
np.ndarray.
To execute tomography in Quara, you must use MatrixBasis with the following properties:
All matrices of MatrixBasis are normalized.
All matrices of MatrixBasis are Hermitian.
The 0th matrix of MatrixBasis is a multiple of the identity matrix.
Notice
16it [00:00, 296.30it/s] like below image may be output.
CompositeSystem
The constructor of CompositeSystem rearranges the argument List[ElementalSystem] in ascending order by name.
[3]:
basis = get_normalized_pauli_basis(1)
e_sys0 = ElementalSystem(0, basis)
e_sys1 = ElementalSystem(1, basis)
c_sys = CompositeSystem([e_sys0, e_sys1])
print(c_sys.elemental_systems)
(ElementalSystem(name=0, basis=MatrixBasis(basis=[array([[0.70710678+0.j, 0. +0.j],
[0. +0.j, 0.70710678+0.j]]), array([[0. +0.j, 0.70710678+0.j],
[0.70710678+0.j, 0. +0.j]]), array([[0.+0.j , 0.-0.70710678j],
[0.+0.70710678j, 0.+0.j ]]), array([[ 0.70710678+0.j, 0. +0.j],
[ 0. +0.j, -0.70710678+0.j]])])), ElementalSystem(name=1, basis=MatrixBasis(basis=[array([[0.70710678+0.j, 0. +0.j],
[0. +0.j, 0.70710678+0.j]]), array([[0. +0.j, 0.70710678+0.j],
[0.70710678+0.j, 0. +0.j]]), array([[0.+0.j , 0.-0.70710678j],
[0.+0.70710678j, 0.+0.j ]]), array([[ 0.70710678+0.j, 0. +0.j],
[ 0. +0.j, -0.70710678+0.j]])])))
The property dim of CompositeSystem is the dimension of the matrices of MatrixBasis.
[4]:
basis = get_normalized_pauli_basis(1)
e_sys = ElementalSystem(0, basis)
c_sys = CompositeSystem([e_sys])
print(f"dim: {c_sys.dim}")
print(f"shape: {c_sys.basis()[0].shape[0]}")
dim: 2
shape: 2
CompositeSystem has properties to check properties of MatrixBasis.
[5]:
print(f"is_orthonormal_hermitian_0thprop_identity: {c_sys.is_orthonormal_hermitian_0thprop_identity}")
print(f"is_basis_hermitian: {c_sys.is_basis_hermitian}")
is_orthonormal_hermitian_0thprop_identity: True
is_basis_hermitian: True
CompositeSystem has properties for fast computation using sparsity.
basis_basisconjugate
dict_from_hs_to_choi
dict_from_choi_to_hs
basis_T_sparse,
basisconjugate_sparse
basisconjugate_basis_sparse
basis_basisconjugate_T_sparse
basis_basisconjugate_T_sparse_from_1
basishermitian_basis_T_from_1
These properties are calculated only once when accessed.
composite_system_typical module
composite_system_typical module makes it easy to generate a CompositeSystem. Call the generate_composite_system() function with mode and num to generate CompositeSystem.
mode- “qubit” or “qutrit”num- number of qubits or qutrits
To learn more about optional parameters, please see to the API reference.
[6]:
# CompositeSystem with one qubit
c_sys = generate_composite_system("qubit", 1)
# CompositeSystem with two qutrits
c_sys = generate_composite_system("qutrit", 2)
ElementalSystem
ElementalSystem has a tuple of name (int) and MatrixBasis.
[7]:
basis = get_normalized_pauli_basis(1)
e_sys = ElementalSystem(0, basis)
print(f"name: {e_sys.name}")
print(f"basis: {e_sys.basis}")
name: 0
basis: (array([[0.70710678+0.j, 0. +0.j],
[0. +0.j, 0.70710678+0.j]]), array([[0. +0.j, 0.70710678+0.j],
[0.70710678+0.j, 0. +0.j]]), array([[0.+0.j , 0.-0.70710678j],
[0.+0.70710678j, 0.+0.j ]]), array([[ 0.70710678+0.j, 0. +0.j],
[ 0. +0.j, -0.70710678+0.j]]))
The property dim of ElementalSystem is the dimension of the matrices of MatrixBasis.
[8]:
print(f"dim: {e_sys.dim}")
print(f"shape: {e_sys.basis[0].shape[0]}")
dim: 2
shape: 2
ElementalSystem has properties to check properties of MatrixBasis.
[9]:
print(f"is_orthonormal_hermitian_0thprop_identity: {e_sys.is_orthonormal_hermitian_0thprop_identity}")
print(f"is_hermitian: {e_sys.is_hermitian}")
is_orthonormal_hermitian_0thprop_identity: True
is_hermitian: True
MatrixBasis
MatrixBasis has a basis represented by a list of np.ndarray.
[10]:
basis = get_normalized_pauli_basis(1)
print(f"basis[0]: \n{basis[0]}")
print(f"basis[1]: \n{basis[1]}")
print(f"basis[2]: \n{basis[2]}")
print(f"basis[3]: \n{basis[3]}")
basis[0]:
[[0.70710678+0.j 0. +0.j]
[0. +0.j 0.70710678+0.j]]
basis[1]:
[[0. +0.j 0.70710678+0.j]
[0.70710678+0.j 0. +0.j]]
basis[2]:
[[0.+0.j 0.-0.70710678j]
[0.+0.70710678j 0.+0.j ]]
basis[3]:
[[ 0.70710678+0.j 0. +0.j]
[ 0. +0.j -0.70710678+0.j]]
The property dim of MatrixBasis is the dimension of the matrices of basis.
[11]:
print(f"dim: {basis.dim}")
print(f"shape: {basis[0].shape[0]}")
dim: 2
shape: 2
MatrixBasis has functions to check properties.
[12]:
print(f"is_orthogonal(): {basis.is_orthogonal()}")
print(f"is_normal(): {basis.is_normal()}")
print(f"is_hermitian(): {basis.is_hermitian()}")
print(f"is_0thpropI(): {basis.is_0thpropI()}")
print(f"is_trace_less(): {basis.is_trace_less()}")
print(f"size(): {basis.size()}")
is_orthogonal(): True
is_normal(): True
is_hermitian(): True
is_0thpropI(): True
is_trace_less(): True
size(): (2, 2)