[1]:
import quanguru as qg
qBase
#
qBase
class is the parent class for most of the classes in quanGuru
, and it has superSys
and subSys
attributes that are used to implement various functionalities. Understanding the purpose of these functionalities will be more evident later when we will consider its child classes.
[2]:
# let's create an instance of qBase class
q1 = qg.base.qBase()
# qBase inherits from the `named` class, and has
# similar naming functionalities as its base class.
# its name consists of class label and the number of instantiation.
q1.name
[2]:
'qBase1'
superSys
attribute of the qBase class is used to refer to other object. This may be required in some cases when the object needs to point to other single object for its main functionality. Let’s create an Qubit object to show how this attribute works.
[3]:
# create a Qubit object
qub1 = qg.Qubit(frequency = 3)
# superSys attribute points to the created qub1 object
q1.superSys = qub1
[4]:
# Now, the superSys contains this qubit, and the name attribute
# of the superSys shows the name of the created qubit.
q1.superSys.name
[4]:
'Qubit1'
subSys
attribute is a dictionary that stores a set of objects. In order to show how this attribute is useful, let’s consider a compQSystem
class (a class to simulate composite quantum systems) which is a child class of qBase.
[5]:
# let us create an instances of Cavity class
cav = qg.Cavity(frequency = 5, dimension = 20)
# by adding this cavity to our qubit we create a composite system
JCsystem = qub1 + cav
[6]:
# the subSys attribue shows all the systems stored in the composite system.
# It stores them into aliasDict object, where the keys are the names of the objects.
JCsystem.subSys
[6]:
{'Qubit1': <quanguru.classes.QSys.Qubit at 0x1e043662930>,
'Cavity1': <quanguru.classes.QSys.Cavity at 0x1e043662860>}
[7]:
# let's create various qubits
qub2 = qg.Qubit(frequency = 3)
qub3 = qg.Qubit(frequency = 1)
qub4 = qg.Qubit(frequency = 1)
qub4.alias = "quba"
# we can add a qubit in the following way
JCsystem.addSubSys(qub2)
# now the dictionary contains second qubit too
JCsystem.subSys
[7]:
{'Qubit1': <quanguru.classes.QSys.Qubit at 0x1e043662930>,
'Cavity1': <quanguru.classes.QSys.Cavity at 0x1e043662860>,
'Qubit2': <quanguru.classes.QSys.Qubit at 0x1e043662a00>}
[8]:
# we can also use the name of the qubit to add it to subSys
JCsystem.addSubSys("Qubit3")
# alias of objects can be passed as well
JCsystem.addSubSys("quba")
# the subSys dictionary contains two more qubits now
JCsystem.subSys
[8]:
{'Qubit1': <quanguru.classes.QSys.Qubit at 0x1e043662930>,
'Cavity1': <quanguru.classes.QSys.Cavity at 0x1e043662860>,
'Qubit2': <quanguru.classes.QSys.Qubit at 0x1e043662a00>,
'Qubit3': <quanguru.classes.QSys.Qubit at 0x1e043662ad0>,
'Qubit4': <quanguru.classes.QSys.Qubit at 0x1e043662ba0>}
[9]:
# if we want to remove a particular object
JCsystem.removeSubSys("quba")
JCsystem.subSys
[9]:
{'Qubit1': <quanguru.classes.QSys.Qubit at 0x1e043662930>,
'Cavity1': <quanguru.classes.QSys.Cavity at 0x1e043662860>,
'Qubit2': <quanguru.classes.QSys.Qubit at 0x1e043662a00>,
'Qubit3': <quanguru.classes.QSys.Qubit at 0x1e043662ad0>}
[10]:
# if for some reason we need to clear subSys from its stored objects
# we just employ the following method
JCsystem.resetSubSys()
# and now it shows an empty dictionary
JCsystem.subSys
[10]:
{}
Sometimes we may need to store some auxiliary information in our simulations. We can achieve this in two ways. The auxDict
attribute stores the auxiliary information using a dictionary, whereas auxObj
in the form of an object. Choosing one of them is a matter of preference, as both of them actually do the same thing.
[11]:
# Let's say we want to store a cavity into auxDict dictionary
# We can store it like a regular dictionary
q1.auxDict["cav"] = cav
# we check its name attribute
q1.auxDict["cav"].name
[11]:
'Cavity1'
[12]:
# if one prefers to store auxiliary information as an object
# one can store it as an attribute of the auxObj
q1.auxObj.operator = cav
# the stored operator now becomes the cavity
q1.auxObj.operator.name
[12]:
'Cavity1'