Results Classes (quanguru.classes.QRes
)#
Contains qResults, qResBase, and qResBlank classes used in storing various types of simulation results.
This is a simplified version of |
|
|
Base class for qResults implements the defaultdict attributes (used to store various quantities) and property/method to store quantities in them. |
|
Extends the |
Function Name |
Docstrings |
Unit Tests |
Tutorials |
---|---|---|---|
qResBlank |
✅ |
❌ |
❌ |
qResBase |
✅ |
❌ |
❌ |
qResults |
✅ |
❌ |
❌ |
- resKeys = ['__results', '__states', '__resultsLast', '__statesLast', '__average', '__calculated']#
- class qResBlank[source]#
Bases:
object
This is a simplified version of
qResBase
, and it is used in time evolution returns of multi-processing (pool.map()). SinceqResBase
inherits fromnamed
, they contain a dictionary withnamed
instances (incl. quantum system and protocol with large matrices), and multi-processing returns a duplicate/copy of each object in the dictionary. Introduced to save memory, this class is introduced and_copyAllResBlank()
is used in multi-process returns to write the results into qResBlank instances, which does not inherit fromnamed
(thus no duplicate of instances).# NOTE There must be a better solution, but enough for the time being
- __results#
Stores the quantities calculated at each step of the time evolution
- __average#
Stores the time averaged quantities
- __resultsLast#
Stores the last list of results when sweeping parameters
- __states#
Stores the time-evolved states
- __statesLast#
Stores the last list of time-evolved states when sweeping parameters
- __calculated#
Stores the quantities calculated by the calculate methods (see
computeBase
)
- property resultsDict#
returns the protected attribute
self._qResBlank__resultsLast
- property states#
returns the protected attribute
self._qResBlank__statesLast
- class qResBase(**kwargs)[source]#
Bases:
quanguru.classes.base.qBase
Base class for qResults implements the defaultdict attributes (used to store various quantities) and property/method to store quantities in them. Last ones store a single time trace (the very last one) and are reset in the beginning of each time evolution. At the each time trace, the Last are either moved into full dictionary or copied into a
qResBlank
depending, respectively, on single or multi-process. This class is extended byqResults
to implement the method dealing with the details of moving the Last into full.- label: str = 'qResBase'#
(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
- __results#
Stores the quantities calculated at each step of the time evolution
- __average#
Stores the time averaged quantities
- __resultsLast#
Stores the last list of results when sweeping parameters
- __states#
Stores the time-evolved states
- __statesLast#
Stores the last list of time-evolved states when sweeping parameters
- __calculated#
Stores the quantities calculated by the calculate methods (see
computeBase
)
- property calculated#
returns the protected attribute
self._qResBase__calculated
and the setter appends the given value into the defaultdict from the given (key, val) list/tuple.
- property resultsDict#
returns the protected attribute
self._qResBase__resultsLast
and the setter appends the given value into the defaultdict from the given (key, val) list/tuple. Uses the Last, so that it stores the results into proper dictionary during time evolution, and other methods in theqResults
are called at the end of time evolutions to make sure that (by equating this to the regular results dictionary) this returns the full results.
- property singleResult#
returns the protected attribute
self._qResBase__resultsLast
and the setter appends the given value into the defaultdict from the given (key, val) list/tuple. Uses the Last, so that it stores the results into proper dictionary during time evolution, and other methods in theqResults
are called at the end of time evolutions to make sure that (by equating this to the regular results dictionary) this returns the full results.
- property resAverage#
returns the protected attribute
self._qResBase__resultsLast
and the setter appends the given value into the defaultdict from the given (key, val) list/tuple. Uses the Last, so that it stores the results into proper dictionary during time evolution, and other methods in theqResults
are called at the end of time evolutions to make sure that (by equating this to the regular results dictionary) this returns the full results.
- resultsMethod(key, value, average=False)[source]#
This method also stores results and is an alternative to
results
property. It is aimed to provide enriched syntax. Might also implement average.
- property states#
returns the _qResBase__statesLast. The states are stored by the simulation objects, so there is no setter. Uses the Last, so that it stores the results into proper dictionary during time evolution, and other methods in the
qResults
are called at the end of time evolutions to make sure that (by equating this to the regular results dictionary) this returns the full results.
- class qResults(**kwargs)[source]#
Bases:
quanguru.classes.QRes.qResBase
Extends the
qResBase
and introduces methods to reset, organise, copy, etc. for the results/states/etc. The results/states/etc are stored in the correspoding Last during time evolution and are appended into a single list ,which, at the end of the simulation, is re-shaped by_reShape()
method using the sweep.indices.The time-evolution methods do not need to return anything (in single process) since every thing is stored in qResults objects. However, pool.map() need to return the relevant results out of the pickled program, and it is easier and consistent to return the objects storing the results. Due to the, named._allInstacesDict dictionary in their attributes, returning qResults out of the map causes duplication of all the named instances incl. quantum system and protocols with large matrices. Therefore, an alternative method
_copyAllResBlank()
is used to copy the dictionaries containing the results intoqResBlank
instances, and duplication of named instances is avoided (since qResBlank does not inherit from named, ie. does not contain the _allInstacesDict).- label: str = 'qResults'#
(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
- _allResults = {}#
(class attribute) dictionary to store all the qResults instances, used in several places.
- allResults#
required to properly pickle _allResults dictionary
- _copyAllResBlank()[source]#
method to copy the dictionaries of all the
qResults
instances into newqResBlank
instances, and store them into another dictionary with the name of the corresponding qResults instance. The returned dictionary mimics the _allResults dictionary of qResults and is used as the return of the pool.map(). At the end of the simulation, these dictionaries are used to write back the results into actual _allResults by_organiseMultiProcRes()
.
- _reset()[source]#
Method to empty (creates and assigned them to new defaultdicts) all the previous results/states dicts.
- _resetLast()[source]#
Method to reset the Last dictionaries only, and it is called before the time evolution to empty the Last. After the time evolution (depending on single/multi-process), these are moved to regular results by the corresponding methods below. At the end of the simulation, these are made equal to regular, so that the setter/getter properties of results/states (returning Last ones) works during and after the simulation to set/get the results.
- _organiseMultiProcRes(results, inds)[source]#
multi-processing returns are dictionaries containing
qResBlank
instances with single time trace (see_copyAllResBlank()
), this method re-writes the results into correspondingqResults
objects and re-shapes them into correct sweep and time trace structure. Calls other methods of the class for these.
- classmethod _finaliseAll(inds)[source]#
Calls the
_finalise()
method, which reshapes the results/states list using the given list of indices (ie. length of each sweep), on every qResults instances in the _allResults dictionary.
- static _organise(keyUni, valUni)[source]#
At the end of time evolution,
_organise()
creates a single list containing all the results/states for each key.
- _organiseSingleProcRes()[source]#
organising the single-process results by simply calling
_organise()
on every qResults instance in allResults dictionary. This needs to be finalised, ie. creates a single list containing every sweep, so the list has to be reshaped.