Simulation classes (quanguru.classes.QSimBase
)#
Contains the _parameter class and the parent classes of the Simulation object.
|
_parameter instances can be bound to each other to implement a (value) dependency between them. |
|
Contains attributes and methods for |
|
Implements 3 basic time information, namely total time of simulation ( |
Function Name |
Docstrings |
Unit Tests |
Tutorials |
---|---|---|---|
_parameter |
✅ |
✅ |
❌ |
stateBase |
✅ |
✅ |
❌ |
timeBase |
✅ |
✅ |
❌ |
- setAttr(obj: quanguru.classes.baseClasses.paramBoundBase, attrStr: str, val: Any) None [source]#
a customized setattr that changes the value (and _paramUpdated) if the new value is different than the old/existing. Especially useful for multi parameter sweeps (see
_sweep
).
- setAttrParam(obj: quanguru.classes.baseClasses.paramBoundBase, attrStr: str, val: Any) None [source]#
a customized setattr that changes the value stored as the
value
attribute of a _parameter object. The value (and _paramUpdated) is changed, if the new value is different than the old/existing. In any case, it breaks existing timeBase bounds (bound betweenSimulation
instances). Especially useful for multi parameter sweeps (see_sweep
).
- class _parameter(value: Optional[Any] = None, _bound: Optional[quanguru.classes.QSimBase._parameter] = None)[source]#
Bases:
object
_parameter instances can be bound to each other to implement a (value) dependency between them.
There are two types of parametric bounds/relations/dependencies 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.
This class wraps (composition) the value of a parameter (an attribute) to create a hierarchical dependency required for the first case. The second case is covered by
paramBoundBase
.It is intended to be used with private attributes and the corresponding properties returns the
value
of that attribute (which is a _parameter object).If a
_parameter
is given another_parameter
as its_bound
, it returns thevalue
of its_bound
, while keeping its_value
unchanged (which is mostly left to beNone
). This is the same for the bound one, which means a chain of dependency is achieved by bounding each object to another.bounds can be broken by explicitly setting the
value
.TODO update this list and add cross-references. Used in
stepSize
,totalTime
,stepCount
,initialState
etc. The goal of having such dependency is that, for example, when simulating a quantum system simultaneously using more than 1 protocol, we can assign aninitialState
for the quantum system, and all the protocolsinitialState
will by default be_bound
to quantum systemsinitialState
and get their value from it. If we explicitly assign aninitialState
to any protocol, the_bound
will break for that particular protocol, which will have its owninitialState
, but not the others, unless they are also explicitly given aninitialState
. These sort of dependencies are implemented in the library and are not meant for external modifications.This class can be replaced by a proxy class. However, this is intended to be used completely internally (private attributes + properties), this simple option should suffice.
- _value: Any#
the value to be wrapped
- _bound: quanguru.classes.QSimBase._parameter#
bounded _parameter object, self is not bounded to anything when this is None or any other object that does not have a
value
attribute. Assigned to False when a bound is broken (by updating the value).
- property value: Any#
Property to get the
_value
of self, ifbound
does not havevalue
as an attribute, else returns thevalue
of the_bound
, which should be an instance of_parameter
object but can be any other object with an_value
&/_bound
attribute.Setter assigns the
_value
to a given input and_bound
toFalse
(meaning the bound to any other object is broken, and value is different than the default, which is None)
- class stateBase(**kwargs)[source]#
Bases:
quanguru.classes.baseClasses.computeBase
Contains attributes and methods for
initialState
and a boolean to determine whether to store or discard time-evolved states. Since, we can usecompute
to compute quantities of interest at the run-time of simulation, we don’t need to keep the states and can discard them to save memory.NOTE : This class branches the inheritance started by
paramBoundBase
and extends toSimulation
.NOTE : All three attributes of this class (and all 4 of timeBase) are instances of
_parameter
, so they have a corresponding property.- label: str = 'stateBase'#
(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
- __initialState#
This attribute is a
_parameter
and value stores theinitialState
matrix
- __initialStateInput#
Input used in the creation of the
initialState
, there are various ways to createinitialState
, so its value changes depending on the case. This information is kept so that it can be used in cases where a new reconstruction ofinitialState
is required, e.g. when system dimension is swept or changed.
- __delStates#
This boolean determines if we delete/discard (
True
) time-evolved states (to save memory) and keep only theinitialState
andcurrentState
of the system. By default, it isFalse
and states will be stored in the corresponding protocolsqRes.states
.
- _initialStateSystem#
This system will be used in the initial state creation, i.e. input will be passed to this systems createState function. If this is None, it fallbacks to self.superSys, and raises error if self.superSys is also None.
- _maxInput#
Stores the maximum of the basis numbers passed to initial state input.
- property initialStateSystem#
- property initialState#
The initialState property
returns _stateBase__initialState.value
if it is notNone
. Otherwise, uses first element in itssubSys
dictionary values to create and assign its value. This assumes that, to be able to assign a state to a Simulation, it needs at least one quantum system in itssubSys
dictionary, and the subSys have method to create the state (_createState
). This requirement, by default, is satisfied by the internally created Simulation objects that are attributes of quantum systems and protocols.Setter sets
_stateBase__initialState.value
matrix forself
by using the first element ofsubSys
dictionary values.
- property _initialStateInput#
getter and setter of _stateBase__initialStateInput.value
.
- getResultByNameOrAlias(name)[source]#
This method exists to enrich the terminology, it just
returns super().getByNameOrAlias(name)
, which returns the object with the given name. SeegetByNameOrAlias
for details.
- property delStates#
gets and sets
_stateBase__delStates.value
boolean
- class timeBase(**kwargs)[source]#
Bases:
quanguru.classes.QSimBase.stateBase
Implements 3 basic time information, namely total time of simulation (
totalTime
), step size for each unitary (stepSize
), and number of steps (stepCount = totalTime/stepSize
). Additionally, one more parameter, namely, number of samples (samples
) is introduced to be used with time-dependent Hamiltonian, where a continuous parameter is discretely changed at everystepSize
and more than onesamples
are desired during thestepSize
.These 4 attributes are all
_parameter
instances and protected attributes, meaning they are modified by the corresponding properties. One other functionality of property is to create flexible use of these attributes. For example, not all 3 ofstepSize
,totalTime
, andstepCount
are need to be explicitly defined, any of these two would be sufficient, since the 3rd can be calculated using the two. So, property setters&getters also covers such cases. Another flexibility ensured by the properties is when_bound
are broken.- label: str = 'timeBase'#
(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
- __totalTime#
_parameter storing the total time of simulation
- __stepSize#
_parameter storing the step size of simulation
- __samples#
_parameter storing number of samples in each step, by default 1.
- __stepCount#
_parameter storing the number of steps, i.e totalTime/stepSize.
- __bound#
if bound to another object, meaning the _parameters of this gets their value from the others _parameters, this attribute is a reference to another. Else None.
- property totalTime#
gets and sets
_timeBase__totalTime.value
, and also sets the_timeBase__stepCount.value
conditioned on thatstepSize
is notNone
. It also sets_paramUpdated
toTrue
. Additionally to these, it sets_timeBase__stepSize._value
to_timeBase__stepSize._bound._value
, if_timeBase__stepSize._bound
is notNone or False
. This is introduced to provide a flexible use of these parameters, such as not forcing to define at least 2 of 3 timeBase parameters, if it already has a_bound
and can obtain the second one from the_bound
.
- property stepCount#
gets and sets
_timeBase__stepCount.value
. getter also try seting thetotalTime
if it isNone
. Setter also sets_timeBase__stepSize.value
conditioned on thattotalTime
is notNone
. It also sets_paramUpdated
toTrue
. Additionally to these, it sets_timeBase__totalTime._value
to_timeBase__totalTime._bound._value
, if_timeBase__totalTime._bound
is notNone or False
. This is introduced to provide a flexible use of these parameters, such as not forcing to define at least 2 of 3 timeBase parameters, if it already has a_bound
and can obtain the second one from the_bound
.
- property stepSize#
gets and sets
_timeBase__stepSize.value
, and also_timeBase__stepCount.value
conditioned on thattotalTime
is notNone
. It also sets_paramUpdated
toTrue
. Additionally to these, it sets_timeBase__totalTime._value
to_timeBase__totalTime._bound._value
, if_timeBase__totalTime._bound
is notNone or False
. This is introduced to provide a flexible use of these parameters, such as not forcing to define at least 2 of 3 timeBase parameters, if it already has a_bound
and can obtain the second one from the_bound
.
- property samples#
gets and sets
_timeBase__samples.value
and also sets_paramUpdated
toTrue
.
- _copyVals(other, keys)[source]#
Method to copy the values for given attributes (as keys) from
other
toself
.
- static _boundTree(osys, tree=None)[source]#
Creates a tree of bound instances starting from the given
osys
. A primitive method used in debugging and to be improved.
- _bound(other, params=['_stateBase__delStates', '_stateBase__initialState', '_stateBase__initialStateInput'], re=False)[source]#
This method is used internally at appropriate places to create bound between different simulation instances in the intended hierarchical order. For example, when a
quantum system
is added tosubSys
of explicitly createdSimulation
, The parameters of anyprotocol.simulation
for that system will be bound to(quantum system).simulation
which will be bound to explicitly created Simulation. This method creates such a bound between twoSimulation
objects, and it is used in appropriate places of the library. Such a bound is broken or not created at all, if a parameter is explicitly assigned for a protocol or system.if self _parameter attributes have bound False (meaning set a value before)
copies the value from other, if value in other is not None.
is any self _parameter bound is None, and the same value in other is not, sets it and breaks the loop
tries bounding if bound is None
NOTE : This method is intended purely for internal uses!
- Parameters
other (Simulation) – The other Simulation (or timeBase) class to bound the parameters of self
re (bool, optional) – This boolean used (internally) to re-bound a simulation object to another one, by default False. So, re-calling this method to bound a simulation object to another will not work unless
re=True
.param (List[str]) – This is a list of strings for attributes (which are also _parameter objects) other than time parameters, for which the same bound will be created. The difference between
param
andtimeBase
parameters is that the latter ones has a functional dependency to each other, meaning a break in one of them should appropriately be reflected to the others.