base classes (quanguru.classes.baseClasses)#

Contains some base classes.

updateBase(**kwargs)

Base class for _sweep and Update classes, which are used in parameter sweeps and step updates in protocols, respectively.

paramBoundBase(**kwargs)

Implements a mechanism to inform a set of objects when a (relevant) change happens on self.

computeBase(**kwargs)

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 and Update 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 in self.key) of the objects in the subSys dictionary. It can also sweep/update auxiliary dictionary by setting the aux boolean to True. The default method can be changed to anything by pointing the function attribute to any other Callable.

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.

_runUpdate(val: Any) None[source]#

a simple method to set the attribute (for the given key) of every subSys to a given value (val), if _aux bool is False. If _aux True, updates the value for the given key in aux dictionary returns None.

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,

  1. 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.

  2. 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 is False, a protocol is not going to re-create its unitary, the __paramUpdated is set to True only by an object which contain the protocol in its __paramBound dictionary and changes its __paramUpdated to True 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 their freeMat

__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 by setAttr(), 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 of self 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. given bound (have to be an paramBoundBase 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 for self 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 the delMatrices for the objects in __paramBound and subSys dictionaries. Also, calls del 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 in subSys of the other. By default []

Returns

the _exclude list, which should contain references to all the objects whose __matrix attribute is set to None

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 the self.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 default None.

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 default None.

__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 or self.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 is list(self.qRes.states.values()).