Simulation classes (quanguru.classes.QSim)#

Contains Simulation and _poolMemory classes.

Simulation([system])

Simulation class collects all the pieces together to run a simulation.

_poolMemory()

handles creation and closing of pools for multi-processing (mp), some other small mp settings (such as setting set_start_method to fork etc.), and also calls runSimulation: method inside its only method :meth:`~run().

Function Name

Docstrings

Unit Tests

Tutorials

Simulation

      ✅

    ❌

    ❌

_poolMemory

      ✅

    ❌

    ❌

class Simulation(system=None, **kwargs)[source]#

Bases: quanguru.classes.QSimBase.timeBase

Simulation class collects all the pieces together to run a simulation. Its subSys dictionary contains protocols, quantum systems as key:value, respectively. It has two sweeps, meaning 2 of its attributes are Sweep objects. Its run method, after running some preparations, runs the actual function/s that run Sweeps and evolve the system by calling evolFunc attribute of Simulation object, which is a function that, by default, calls .unitary method on protocols, which by default creates the unitary by matrix exponentiation, and evolves the system by a matrix multiplication of the .unitary with the .initial state.

Avaliable methods of solution in the libray are going to be increased in time, and different methods will be used by re-assigning the evolFunc. Additionally, this will be used for interfacing the library with other tools. The sweeps just change the value for some system/simulation parameters, which are just object attributes, so they are generic and general enough to be independent of evolFunc, and, with this, it is aimed to increase scope of sweeps.

There are 3 cases in addProtocol() that raises a TypeError. TODO : errors are not properly implemented yet.

label: str = 'Simulation'#

(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

_evolFuncDefault()#

default evolution method. You can always assign a different evolution method for an instance of Simulation class, but by re-assigning this class attribute, you can change the evolution method for all the future instances

Sweep#

sweep object that contains information about the systems and their parameters to be swept. TODO create tutorial This is used to run the simulation for several parameter sets, i.e. sweeping some parameters. This is an instance of Sweep. The use of this attribute in runSimulation function is independent of evolFunc or time-dependent part of the simulation. This is simply to sweep multiple parameters.

timeDependency#

sweep object that contains information for parameters that will be changed as a function of time. Note that this is not the only way to make time-dependent parameters. Actually, the alternative in timeDependency in term objects is much better solution than this. TODO create tutorial This is used to define temporal change of some parameters, i.e. used for time-dependent cases. This attribute is used when default evolFunc is used with the default createUnitary method of protocols, and it can be avoided in other cases. This is required in digital simulations, where time dependency is discrete.

__index#

this is counter for the number of steps in the time evolution, so this counter times the step size gives the current time in evolution. this is intended purely for internal use.

evolFunc#

default function that implements the actual time evolution in each step. TODO Create tutorial. This is the default evolution method, which calls .unitary attribute on protocols and matrix multiply the resultant unitary with the .initialState. It is possible to use this with other solution methods where the evolution is obtained by matrix multiplication of state by the unitary, which is not necessarily obtained by matrix exponentiation or the time-dependency is not incorporated by timeDependency.

property _currentTime#

Returns the current time in time evolution, which is equal to the current number of steps in the evolution times the step size.

property timeList#

Returns a list of the time points of the time evolution.

property protocols#

Returns a list of protocols (keys in subSys) contained in this simulation.

_freeEvol()[source]#

This function is meant purely for internal use. When a quantum system is added to a Simulation without providing a protocol, the key in subSys dictionary will be the default case inherited from qBase, i.e. name of the quantum system object. This method is called inside the run() method to ensure that the key is switched to a freeEvolution. By this we ensure that the default evolution is just a free evolution under the given systems Hamiltonian and explicit creation of a freeEvolution object is not required. These are achieved by replacing the str key by the freeEvolution object that, by default, exists as a parameter for every quantum system. The reason for not doing it right away after the meth:addQSystems is to create a flexible use, i.e. when a addProtocol() is called to replace the freeEvolution, there is no need to try reaching internally created object but just using the system.name for protocolRemove argument of addProtocol().

property qSystems#

Returns a list of quantum systems (values in subSys) contained in this simulation.

property qEvolutions#

The qEvolutions property returns actual protocols rather than simply returning (keys in subSys), which can be the system name before running the simulation, as in protocols() property.

addQSystems(subS, Protocol=None, **kwargs)[source]#

Quantum systems and the corresponding protocols are, respectively, stored as the values and keys of subSys dictionary, so this method extends addSubSys method by an additional argument, i.e. Protocol to be used as the key, and also by creating the hierarchical

Parameters
  • subS ([type]) – [description]

  • Protocol ([type], optional) – [description], by default None

Returns

[description]

Return type

[type]

createQSystems(subSysClass, Protocol=None, **kwargs)[source]#

Create a quantum system of given subSysClass class and (optional) add a Protocol for it. kwargs here are used for setting the parameters of newly created quantum system.

removeQSystems(subS)[source]#

Remove a quantum system and corresponding sweeps from the simulation.

removeSweep(system)[source]#

Remove a sweep from the simulation.

removeProtocol(Protocol)[source]#

Remove a protocoal and corresponding sweeps from the simulation.

addProtocol(protocol=None, system=None, protocolRemove=None)[source]#

Add a protocol for the (optional) system and (optional) remove an existing protocol protocolRemove.

addSubSys(subS, Protocol=None, **kwargs)[source]#

Add a quantum system subS to the simulation and a (optional) protocol for it. kwargs can be used for setting parameters for the quantum system.

createSubSys(subSysClass, Protocol=None, **kwargs)[source]#

Create and add a quantum system of a given class subSysClass and a (optional) protocol for it. kwargs can be used for setting parameters for the quantum system.

_removeSubSysExc(subSys, _exclude=[])[source]#

Remove a quantum system from the simulation.

__compute()#

Internal compute method that passes the states to all the other compute functions of computeBase instances.

run(p=None, coreCount=None, resetRes=True)[source]#

Call this function to run the simulation. It runs certain other preparation before running the simulation.

Parameters
  • p (Boolean) – If True uses multiprocessing to run sweeps

  • coreCount (int) – Number of cores used for multiprocessing, uses `` (avaliable number of cores) - 1`` as default.

  • resetRes (Boolean) – If False, does not delete the results from the previous run of the simulation. True by default.

class _poolMemory[source]#

Bases: object

handles creation and closing of pools for multi-processing (mp), some other small mp settings (such as setting set_start_method to fork etc.), and also calls runSimulation: method inside its only method :meth:`~run(). This class is introduced to make life a bit easier for user (ie. do not need to import multiprocessing or create&close pools) but also to avoid bunch of bugs due to pickling etc.

coreCount = None#

stores the number of cores used in multiprocessing

reRun = False#

boolean to ensure that the library does not try setting set_start_method to fork when a simulation is re-run.

classmethod run(qSim, p, coreCount)[source]#

This is the only method in the class, and it carries the tasks described in the class description.