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:
qBaseBase class for
_sweepandUpdateclasses, 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 (strof the attribute name is stored inself.key) of the objects in thesubSysdictionary. It can also sweep/update auxiliary dictionary by setting theauxboolean toTrue. The default method can be changed to anything by pointing thefunctionattribute 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
subSysdictionary, 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: List | named#
system property wraps
subSysdictionary 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
addSubSysmethod.
- _runUpdate(val: Any) None[source]#
a simple method to set the attribute (for the given key) of every
subSysto a given value (val), if _aux bool is False. If _aux True, updates the value for the given key in aux dictionary returnsNone.
- __firstlineno__ = 34#
- __static_attributes__ = ('__function', '__key', '_aux', '_updateBase__key')#
- class paramBoundBase(**kwargs)[source]#
Bases:
qBaseImplements 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
__paramUpdatedisFalse, a protocol is not going to re-create its unitary, the__paramUpdatedis set toTrueonly by an object which contain the protocol in its__paramBounddictionary and changes its__paramUpdatedtoTrueby calling_paramUpdatedproperty. 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
__matrixstore their unitary, single quantum systems use it for theirfreeMat
- __matrixHc#
This attribute stores the Hermitian conjugate of the
__matrixattribute
- __paramUpdated#
Signals that a parameter is updated. This is set to
Truewhen 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
_paramUpdatedboolean value needs to be updated, if_paramUpdatedofselfis updated (but not the other way around and, unlike_parametersetting ones value does not break the relation).
- property _hc#
- property _paramBound: Dict#
returns
_paramBoundBase__paramBounddictionary. 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: paramBoundBase, **kwargs) paramBoundBase[source]#
creates a bound to
self, ie. givenbound(have to be anparamBoundBaseinstance) objects __paramUpdated boolean is updated whenever self updates its.
- _breakParamBound(bound: paramBoundBase, _exclude=[]) None[source]#
This method removes the given object from the
__paramBounddictionary.
- property _paramUpdated: bool#
Gets
_paramBoundBase__paramUpdatedboolean, and sets it forselfand all the other objects in__paramBounddictionary.
- delMatrices(_exclude: List = []) List[source]#
This method deletes (sets to
None) the__matrixvalue for self and calls thedelMatricesfor the objects in__paramBoundandsubSysdictionaries. Also, callsdelon 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 insubSysof the other. By default []- Returns:
the _exclude list, which should contain references to all the objects whose
__matrixattribute is set toNone
- __firstlineno__ = 104#
- __static_attributes__ = ('__matrix', '__matrixHc', '__paramBound', '__paramUpdated', '_paramBoundBase__matrix', '_paramBoundBase__matrixHc', '_paramBoundBase__paramUpdated')#
- class computeBase(**kwargs)[source]#
Bases:
paramBoundBaseImplements 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.
- __firstlineno__ = 238#
- __static_attributes__ = ('compute', 'postCompute', 'preCompute', 'qRes')#
- __compute(states, *args, **kwargs) None#
This is the actual compute function that is called in the time-evolution, it calls
self.computeif 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.preComputeorself.postComputedepending 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()).