Manager Classes#
This class handles several important package wide tasks:
Usage of units across objects storing data
Basis conversion of all registered objects
3) Calls to proper optimized implementations of numerically heavy sections of the calculations
Manager is a singleton class, only one instance exists at all times and all managing objects have the instance of the Manager.
Properies#
version : string contains the package version number
allower_utypes : list contains a list of unit types which can be controlled by the Manager
units : dictionary dictionary of available units for each units type
units_repre : dictionary dictionary of abreviations used to represent various units
units_repre_latex : dictionary dictionary of latex prepresentations of available units
Units Management#
Units management is performed for all classes derived from quantarhei.managers.UnitsManaged class.
Basis Conversion Management#
Units management is performed for all classes derived from quantarhei.managers.BasisManaged class.
Basis management works like this: when an class is defined, and its property needs to be basis managed, one should use a predefined type basis_managed_array_property
- exception quantarhei.core.managers.SecurityWarning[source]#
Bases:
UserWarningWarning about security-sensitive operations.
- class quantarhei.core.managers.Manager(*args: Any, **kwargs: Any)[source]#
Bases:
objectMain package Manager.
Handles units management, basis conversion, and selection of optimized implementations for the entire Quantarhei package. Only one instance exists at any time (Singleton pattern).
- version#
The installed package version number.
- Type:
str
- allowed_utypes#
Unit types that can be managed (
'energy','frequency', etc.).- Type:
list of str
- units#
Available unit strings for each unit type.
- Type:
dict
- units_repre#
Short string abbreviations for each unit string.
- Type:
dict
- units_repre_latex#
LaTeX representations for each unit string.
- Type:
dict
- version = '0.0.69'#
- allowed_utypes = ['energy', 'frequency', 'dipolemoment', 'temperature', 'time', 'length']#
- units = {'dipolemoment': ['Debye', 'a.u'], 'energy': ['1/fs', 'int', '1/cm', 'eV', 'meV', 'THz', 'J', 'SI', 'nm', 'Ha', 'a.u.'], 'frequency': ['1/fs', 'int', '1/cm', 'THz', 'Hz', 'SI', 'nm', 'Ha', 'a.u.'], 'length': ['int', 'A', 'nm', 'Bohr', 'a.u.', 'm', 'SI'], 'temperature': ['1/fs', 'int', 'Kelvin', 'Celsius', '1/cm', 'eV', 'meV', 'Thz', 'SI'], 'time': ['fs', 'int', 'as', 'ps', 'ns', 'Ms', 'ms', 's', 'SI']}#
- units_repre = {'1/cm': '1/cm', '1/fs': '1/fs', 'Celsius': 'C', 'Debye': 'D', 'Ha': 'Ha', 'Kelvin': 'K', 'THz': 'THz', 'a.u.': 'a.u.', 'eV': 'eV', 'int': '1/fs', 'meV': 'meV', 'nm': 'nm'}#
- units_repre_latex = {'1/cm': 'cm$^-1$', '1/fs': 'fs$^{-1}$', 'Celsius': 'C', 'Debye': 'D', 'Ha': 'Ha', 'Kelvin': 'K', 'THz': 'THz', 'a.u.': 'a.u.', 'eV': 'eV', 'int': '1/fs', 'meV': 'meV', 'nm': 'nm'}#
- main_conf: dict[str, Any]#
- current_basis_operator: Any#
- internal_units: dict[str, str]#
- current_units: dict[str, str]#
- implementation_points: dict[str, str]#
- all_implementations: dict[str, dict[str, str]]#
- default_implementations: dict[str, str]#
- optimal_implementations: dict[str, str]#
- current_implementations: dict[str, str]#
- basis_stack: list[int]#
- basis_transformations: list[Any]#
- basis_registered: dict[int, list[Any]]#
- save_dict: dict[str, Any]#
- unit_repr(utype: str = 'energy', mode: str = 'current') str[source]#
Returns a string representing the currently used units
- unit_repr_latex(utype: str = 'energy', mode: str = 'current') str[source]#
Returns a string representing the currently used units
- set_current_units(utype: str, units: str) None[source]#
Set the current units for a given unit type.
- Parameters:
utype (str) – Unit type (e.g.
'energy','length').units (str) – Unit string to set as current (must be a recognized value for the given
utype).
- Raises:
Exception – If
utypeis not inallowed_utypesorunitsis not recognized forutype.
- convert_energy_2_internal_u(val: float | ndarray) float | ndarray[source]#
Convert energy from currently used units to internal units
- Parameters:
val (number, array, list, tuple of numbers) – values to convert
- convert_energy_2_current_u(val: float | ndarray) float | ndarray[source]#
Converts energy from internal units to currently used units
- Parameters:
val (number, array, list, tuple of numbers) – values to convert
- convert_frequency_2_internal_u(val: float | ndarray) float | ndarray[source]#
Converts frequency from currently used units to internal units
- Parameters:
val (number, array, list, tuple of numbers) – values to convert
- convert_frequency_2_current_u(val: float | ndarray) float | ndarray[source]#
Converts frequency from internal units to currently used units
- Parameters:
val (number, array, list, tuple of numbers) – values to convert
- convert_length_2_internal_u(val: float | ndarray) float | ndarray[source]#
Converts length from currently used units to internal units
- Parameters:
val (number, array, list, tuple of numbers) – values to convert
- convert_length_2_current_u(val: float | ndarray) float | ndarray[source]#
Converts frequency from internal units to currently used units
- Parameters:
val (number, array, list, tuple of numbers) – values to convert
- class quantarhei.core.managers.Managed[source]#
Bases:
objectBase class for managed objects
- manager = <quantarhei.core.managers.Manager object>#
- class quantarhei.core.managers.UnitsManaged[source]#
Bases:
ManagedBase class for objects with management of units
- class quantarhei.core.managers.EnergyUnitsManaged[source]#
Bases:
Managed- utype = 'energy'#
- units = '1/fs'#
- class quantarhei.core.managers.LengthUnitsManaged[source]#
Bases:
ManagedClass providing functions for length units conversion
- utype = 'length'#
- units = 'A'#
- class quantarhei.core.managers.BasisManaged[source]#
Bases:
ManagedBase class for objects with managed basis
- class quantarhei.core.managers.units_context_manager(utype: str = 'energy')[source]#
Bases:
objectGeneral context manager to manage physical units of values
- class quantarhei.core.managers.energy_units(units: str)[source]#
Bases:
units_context_managerContext manager for units of energy.
Sets the active energy units for the duration of the
withblock and restores the previous units on exit.- Parameters:
units (str) – Energy unit string (e.g.
'1/cm','eV','int').
Examples
>>> import quantarhei as qr >>> with qr.energy_units("1/cm"): ... H = qr.Hamiltonian(data=[[0.0, 100.0], [100.0, 12000.0]])
- class quantarhei.core.managers.frequency_units(units: str)[source]#
Bases:
energy_unitsContext manager for units of frequency.
Behaves identically to
energy_unitssince frequency and energy share the same internal representation in Quantarhei.- Parameters:
units (str) – Frequency unit string (e.g.
'1/cm','THz','int').
- class quantarhei.core.managers.length_units(units: str)[source]#
Bases:
units_context_managerContext manager for length units.
Sets the active length units for the duration of the
withblock and restores the previous units on exit.- Parameters:
units (str) – Length unit string (e.g.
'A','nm','Bohr').
- class quantarhei.core.managers.basis_context_manager[source]#
Bases:
objectGeneral context manager to manage basis
- class quantarhei.core.managers.eigenbasis_of(operator: Any)[source]#
Bases:
basis_context_managerContext manager for working in the eigenbasis of an operator.
Diagonalizes the given operator on entry, making subsequent calculations in the eigenbasis, and transforms all registered objects back on exit.
- Parameters:
operator (SelfAdjointOperator) – The operator whose eigenbasis is used inside the context block.
- quantarhei.core.managers.set_current_units(units: dict[str, str] | None = None) None[source]#
Set units globally without a context manager.
- Parameters:
units (dict of str, optional) – Mapping from unit type (e.g.
'energy') to unit string (e.g.'1/cm'). IfNone, all unit types are reset to their internal defaults.- Raises:
Exception – If any key in
unitsis not a recognized unit type.
- quantarhei.core.managers.units_state() dict[str, str][source]#
Returns a snapshot of the current global unit settings.
Useful for inspecting Manager state in notebooks or debugging unexpected unit conversions.
- Returns:
dict – Mapping of unit type to current unit string, e.g.
{'energy': '1/cm', 'frequency': '1/fs', 'length': 'A', 'temperature': 'Kelvin', 'dipolemoment': 'Debye'}.
Examples
>>> import quantarhei as qr >>> state = qr.units_state() >>> state['energy'] '1/fs'