Quantum system classes (quanguru.classes.QSystem)#

Contains the QuantumSystem class used for quantum systems

QuantumSystem(**kwargs)

Class for quantum systems, both for single and composite systems, which can also be nested.

Function Name

Docstrings

Unit Tests

Tutorials

QuantumSystem

      ✅

    ✅

    ✅

_initStDec(_createInitialState)[source]#

Decorater to handle different inputs for initial state creation.

class QuantumSystem(**kwargs)[source]#

Bases: quanguru.classes.QSimComp.QSimComp

Class for quantum systems, both for single and composite systems, which can also be nested.

label: str = 'QuantumSystem'#

(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

__firstTerm#

First term is also stored in __firstTerm attribute

__terms#

dictionary of the terms

__dimension#

dimension of Hilbert space of the quantum system

__compSys#

boolean flag for composite/single systems

__dimsBefore#

Total dimension of the other quantum systems before self in a composite system. It is 1, when self` is the first system in the composite system or self is not in a composite system.

__dimsAfter#

Total dimension of the other quantum systems after self in a composite system. It is 1, when self is the last system in the composite system.

_inpCoef#

boolean to determine whether initialState inputs contains complex coefficients (the probability amplitudes) or the populations

__compOpers#

a dictionary to store arbitrary composite operators that are shaped and updated internally

__unitary#

an internal freeEvolution protocol, this is the default evolution when a simulation is run.

property _compositeOperator#

A property to store a function pointer (for operator) as key of a dictionary where the value is the internally created composite operator.

_constructMatrices()[source]#

The matrices for operators constructed and de-constructed whenever they should be, and this method is used internally in various places when the matrices are needed to be constructed.

_timeDependency(time=None)[source]#

An internal method used to pass down the current time in evolution to all the subSys and terms. The term objects timeDependency functions are used for updating relevant parameters as a function of time.

_createInitialState(inp=None, _maxInput=1)[source]#
_createState(inp=None, _maxInput=1)#
property initialState#

Getter for the simulation initial state, equivalent to self.simulation.initialState. This works by assuming that its setter/s makes sure that _stateBase__initialState.value is not None for single systems (if its state is set).

property _subSysHamiltonian#

returns the sum of sub-system Hamiltonian

property totalHamiltonian#

returns the total Hamiltonian of self including the coupling terms.

property _termHamiltonian#

returns the sum of term Hamiltonian

property _totalDim#

QuantumSystem.dimension returns the dimension of a quantum system itself, meaning it does not contain dimensions of the other systems if self is in a composite system, _totalDim returns the total dimension by also taking the dimensions before and after self in a composte system.

_hasConsistentDimensionTerm(dim)[source]#
property dimension#

Property to get the dimension of any quantum system and also to set the dimension of single quantum systems. It calculates the dimension of a composite system on every call. For composite systems, setter raises a warning. For single system, setter also calls _updateDimension on its superSys (if there is one).

property subSysDimensions#

Returns a (nested) list of dimensions of the quantum systems contained in self, if self is composite, else returns self.dimension.

_updateDimension(subSys, newDim, oldDim)[source]#

Internal method to update dimension before/after information of the sub-systems when the dimension of a sub-system is updated. It is called in the dimension setter.

Parameters
  • subSys – The sub-system whose dimension is being updated.

  • newDim (int) – The new dimension of the subSys

  • oldDim (int) – The old dimension of the subSys

__dimsABUpdate(attrName, val)#

Common parts of the dimsBefore/After setters are combined in this method.

Parameters
  • attrName (str) – _dimsBefore/After as a string to be used with setAttr&setattr

  • val (int) – new value of _dimsBefore/After

property _dimsBefore#

Property to set and get the __dimsBefore. Getter can be used to get information, but the setter is intended purely for internal use.

property _dimsAfter#

Property to set and get the __dimsAfter. Getter can be used to get information, but the setter is intended purely for internal use.

property _isComposite#

Used internally to set _QuantumSystem__compSys boolean, never query this before _QuantumSystem__compSys is set by some internal call. Otherwise, this will always return False (because subSys dict is always empty initially)

_hasInSubs(other)[source]#

Returns True if the given system is in self.subSys or in any other subSys nested inside the self.subSys

property ind#

If self is in a composite quantum system, this return an index representing the position of self in the composite system, else it returns 0. Also, the first system in a composite quantum system is at index 0. This is mainly used for _updateDimension where we compare the position of a sub-system against the others to determine whether _dimsBefore/After needs to be updated.

__addSub(subSys)#

internal method used to update relevant information (such as dimension before/after) for the existing and newly added sub-systems. This is purely for internal use.

addSubSys(subSys, **kwargs)[source]#

Extends the addSubSys method for composite quantum systems to set the __compSys boolean (to True, if None), update the dimsBefore/After of the sub-systems, set self as superSys of the sub-system, and set _paramUpdated to True, or it raises a TypeError if __compSys is already set to False. Also, it places self into the _paramBoundBase__paramBound dictionary of the sub-system, so that parameter updates of the sub-system also sets the _paramUpdated of self to True. Note that composite systems can contain other composite systems as sub-systems.

delMatrices(_exclude=[])[source]#

This method extends delMatrices of QSimComp to also call delMatrices on terms.

__add__(other)[source]#

overload the + operator to create a composite quantum system between self and the other quantum system.

__sub__(other)[source]#

overload the - operator to remove the other from self, which should be the composite quantum system containing/connected-to the other.

_removeSubSysExc(subSys: Any, _exclude=[]) None[source]#

Method to remove a given subSys (which might be a single or composite system) from a composite system, which might be self or any other composite system in the nested-system structure. This method traverses through the nested-structure to find the subSys (that will be removed) and uses _exclude to avoid infinite loops, that, for example, might be created when a system calls _removeSubSysExc on its superSys which calls _removeSubSysExc on its subSys, by calling _removeSubSysExc on self if self is not in _exclude. Since _exclude needs to be empty in each call, this method should not be called directly, removeSubSys is a wrapper around this and always calls this with an empty _exclude. Raises an error if removeSubSys is called on a single system. This method also updates the dimsBefore/After of the remaining sub-systems (and the removed system), deletes the existing matrices so that they are re-created with the proper dimensions. When removing a single system, it sets the dimension of the single system to 1, so that all the dimsBefore/After information are updated by the dimensionUpdate method. However, we might still need the removed system, so its dimension is stored (in oldDim) and set back again (into _QuantumSystem__dimension) after its removed. When removing a composite system, it makes _removeSubSysExc to each sub-system of the removed composite system, and these nested calls sets the dimensions of all the single systems below the removed composite to 1 so that the dimsBefore/After information are again updated by the dimensionUpdate method. However, the removed composite system might still be needed, and we might not want these dimensions to be 1 or these single systems to be removed from the removed composite system. These are avoided by storing&setting the dimensions back to their original values for single systems and adding the removed sub-systems of removed composite systems back in.

property _freeEvol#

Property to get the default internal freeEvolution proptocol.

unitary()[source]#

Returns the unitary evolution operator for self.

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

adds the given protocol into self.simulation and uses self as system if it is not given. It also can removed a protocol (protocolRemove) at the same time.

createTerm(operator, frequency=None, qSystem=None, order=None, superSys=None, **kwargs)[source]#

Method to create a new term with the given parameters and also set the given kwargs to the new term.

Parameters
  • operator (Callable or List[Callable]) – operator/s of the term

  • frequency – frequency of the term, by default None

  • qSystem (QuantumSystem) – quantum system/s for the given operator/s, and it is self if no system is given

  • order – order/s of the operator/s, it is set to 1 by default if no order value is given

Returns

Newly created QTerm object

Return type

QTerm

addTerms(trm, **kwargs)[source]#

Method to add an existing term to self and also optionally set some of the term parameters through the kwargs.

_removeTermExc(termObj, _exclude=[])[source]#

The method to find and remove the term from a quantum system.

removeTerm(termObj)[source]#

Method to remove the given term from the quantum system. This can be called on any system in a composite system to remove any term, even if it belongs to another sub-system. This is intended so that the term of a subsystem can be removed through the composite system, especially for nested-composite systems. You can also give a list of terms (or their named/aliases) to be removed. This method is a wrapper around the actual remove method the _removeTermExc so that it is called with an empty _exclude list, which is used to avoid infinite recursions when finding the term inside a nested system. Note that it will raise an error, if the given term is the first-term if the system.

resetTerms()[source]#

Method to delete all the existing terms by assigning a new empty dictionary.

property terms#

Property to get & set the terms of the quantum system. Note that the setter is not intended for adding a new term, but replace the all the existing terms with the given term/s (which can be a single term or a list of terms, and it also works with names and/or aliases). In order to add an additional term to existing ones, use addTerm method.

property _firstTerm#

Property to get the first term of the quantum system.

property frequency#

Property to get & set the frequency of the first term of the quantum system.

property operator#

Property to get & set the operator of the first term of the quantum system.

property order#

Property to get & set the order of the first term of the quantum system.

property _freeMatrix#

Property to get & set the free (i.e. no frequency or, equivalently frequency=1) matrix for the first term.

copy(**kwargs)[source]#

Creates an empty copy of self. This method is introduced here to be extended in child class. In here, it ** does not copy ** the object, but creates a new object of the same class and sets the given kwargs

__rmul__(other)[source]#

With this method, * creates a composite quantum system that contains N=other many quantum systems with the same type as self.

Dicke(couplingStrength, subSys1=None, subSys2=None)#
JC(couplingStrength, subSys1=None, subSys2=None)#
Rabi(couplingStrength, subSys1=None, subSys2=None)#
class Cavity(**kwargs)[source]#

Bases: quanguru.classes.QSystem.QuantumSystem

Cavity class, the only difference from a generic quantum object is that, by default, its operator is the number operator.

label: str = 'Cavity'#

(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

class Spin(**kwargs)[source]#

Bases: quanguru.classes.QSystem.QuantumSystem

Object for a single Spin system with spin j (jValue).

label: str = 'Spin'#

(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

__jValue#

spin quantum number

property jValue#

Gets and sets the spin quantum number

class Qubit(**kwargs)[source]#

Bases: quanguru.classes.QSystem.Spin

Spin 1/2 special case of Spin class, i.e. a Qubit.

label: str = 'Qubit'#

(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