base classes (quanguru.classes.baseClasses
)#
Contains some base classes.
|
Base class for |
|
Implements a mechanism to inform a set of objects when a (relevant) change happens on self. |
|
Implements 3 attributes (and mechanisms) relevant to run-time calculations/computations and result storage. |
Function Name |
Docstrings |
Unit Tests |
Tutorials |
---|---|---|---|
updateBase |
✅ |
✅ |
✅ |
paramBoundBase |
✅ |
✅ |
❌ |
computeBase |
✅ |
✅ |
❌ |
- class updateBase(**kwargs)[source]#
Bases:
quanguru.classes.base.qBase
Base class for
_sweep
andUpdate
classes, which are used in parameter sweeps and step updates in protocols, respectively. This class implements a default method to change the value of an attribute (str
of the attribute name is stored inself.key
) of the objects in thesubSys
dictionary. It can also sweep/update auxiliary dictionary by setting theaux
boolean toTrue
. The default method can be changed to anything by pointing thefunction
attribute to any otherCallable
.- label: str = 'updateBase'#
(class attribute) class label used in default naming
- _internalInstances: int = 0#
(class attribute) number of instances created internally by the library
- _externalInstances: int = 0#
(class attribute) number of instances created explicitly by the user
- _instances: int = 0#
(class attribute) number of total instances = _internalInstances + _externalInstances
- __key: str#
string for an attribute of the objects in
subSys
dictionary, used in getattr().
- __function: Callable#
attribute for custom sweep/update methods. Assigned to some default methods in child, and sweep/update methods can be customized by re-assigning this.
- _aux: bool#
boolean to switch from subSys attribute sweep/update (False) to auxiliary dictionary key sweep/update (True)
- property key: str#
Gets and sets the _updateBase__key protected attribute
- property system: Union[List, quanguru.classes.base.named]#
system property wraps
subSys
dictionary to create a new terminology, it basically:gets subSys[0] if there is only one item in it, else list(subSys.values()) setter works exactly as
addSubSys
method.
- class paramBoundBase(**kwargs)[source]#
Bases:
quanguru.classes.base.qBase
Implements a mechanism to inform a set of objects when a (relevant) change happens on self.
There are two types of parametric bounds/relations in this library,
Value of an attribute in an instance is bound to the value of the same attribute in another instance, meaning it gets its value from its bound.
Not the value of the attribute itself, but any change in its value is important for another object.
First case is covered by the
_parameter
, and the second is by this class.Such bound, for example, is used to make sure that a protocol does not re-create (re-exponentiate) its unitary matrix, unless a relevant parameter is changed. If the
__paramUpdated
isFalse
, a protocol is not going to re-create its unitary, the__paramUpdated
is set toTrue
only by an object which contain the protocol in its__paramBound
dictionary and changes its__paramUpdated
toTrue
by calling_paramUpdated
property. These sort of dependencies are implemented in the library and are not meant for external modifications by a user.- label: str = 'paramBoundBase'#
(class attribute) class label used in default naming
- _internalInstances: int = 0#
(class attribute) number of instances created internally by the library
- _externalInstances: int = 0#
(class attribute) number of instances created explicitly by the user
- _instances: int = 0#
(class attribute) number of total instances = _internalInstances + _externalInstances
- __matrix#
This stores a matrix in some sub-classes, e.g. protocols
__matrix
store their unitary, single quantum systems use it for theirfreeMat
- __matrixHc#
This attribute stores the Hermitian conjugate of the
__matrix
attribute
- __paramUpdated#
Signals that a parameter is updated. This is set to
True
when a parameter is updated bysetAttr()
,setAttrParam()
methods, or True/False by another object, if this object is in another paramBound.
- __paramBound#
a dictionary of objects whose
_paramUpdated
boolean value needs to be updated, if_paramUpdated
ofself
is updated (but not the other way around and, unlike_parameter
setting ones value does not break the relation).
- property _hc#
- property _paramBound: Dict#
returns
_paramBoundBase__paramBound
dictionary. Since the bound mechanism is meant for internal use, this provide an information of the bound structure, but does not have a setter. Creating/breaking a bound has their specific methods.
- _createParamBound(bound: quanguru.classes.baseClasses.paramBoundBase, **kwargs) quanguru.classes.baseClasses.paramBoundBase [source]#
creates a bound to
self
, ie. givenbound
(have to be anparamBoundBase
instance) objects __paramUpdated boolean is updated whenever self updates its.
- _breakParamBound(bound: quanguru.classes.baseClasses.paramBoundBase, _exclude=[]) None [source]#
This method removes the given object from the
__paramBound
dictionary.
- property _paramUpdated: bool#
Gets
_paramBoundBase__paramUpdated
boolean, and sets it forself
and all the other objects in__paramBound
dictionary.
- delMatrices(_exclude: List = []) List [source]#
This method deletes (sets to
None
) the__matrix
value for self and calls thedelMatrices
for the objects in__paramBound
andsubSys
dictionaries. Also, callsdel
on the old value of__matrix
.- Parameters
_exclude (list, optional) – This is used internally to avoid infinite loops in the cases when an object has another in its
__paramBound
, while it is insubSys
of the other. By default []- Returns
the _exclude list, which should contain references to all the objects whose
__matrix
attribute is set toNone
- class computeBase(**kwargs)[source]#
Bases:
quanguru.classes.baseClasses.paramBoundBase
Implements 3 attributes (and mechanisms) relevant to run-time calculations/computations and result storage.
- label: str = 'computeBase'#
(class attribute) class label used in default naming
- _internalInstances: int = 0#
(class attribute) number of instances created internally by the library
- _externalInstances: int = 0#
(class attribute) number of instances created explicitly by the user
- _instances: int = 0#
(class attribute) number of total instances = _internalInstances + _externalInstances
- qRes: qResults#
This attribute is an instance of
qResults
, which is used to store simulation results and states.
- compute: Callable#
Function to call at each step of the time evolution, by default
None
. It needs to be written in the appropriate form TODO create examples/tutorial and link here. It is intended to perform computations on the current state of the system and store the results in theself.qRes.resultsDict
.
- preCompute: Callable#
Function to call at the beginning of time-evolution (or simulation) to perform some calculations, which might be needed in the compute, and store them in the
self.qRes.calculated
. This is by defaultNone
.
- postCompute: Callable#
Function to call at the end of time-evolution (or simulation) to perform some calculations, which might be needed in the compute, and store them in the
self.qRes.calculated
. This is by defaultNone
.
- __compute(states, *args, **kwargs) None #
This is the actual compute function that is called in the time-evolution, it calls
self.compute
if it is a callable and does nothing otherwise.
- __calculate(where: str, *args, **kwargs) None #
This is the actual calculate function that is called in the time-evolution, it calls (if callable, does nothing otherwise)
self.preCompute
orself.postCompute
depending on the given string where.
- property alias: List#
alias property gets the list of aliases.
Sets (adds/extends into the list) alias (single/list of alias). Does not allow duplicate alias.
- property resultsDict: Dict#
returns
self.qRes.resultsDict
.
- property states: Dict#
returns
stateList if len(list(self.qRes.states.values())) > 1 else stateList[0]
where stateList islist(self.qRes.states.values())
.