Manager Classes#

This class handles several important package wide tasks:

  1. Usage of units across objects storing data

  2. 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: UserWarning

Warning about security-sensitive operations.

class quantarhei.core.managers.Manager(*args: Any, **kwargs: Any)[source]#

Bases: object

Main 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]#
load_conf() None[source]#

Loads configuration file

This is to be called in scripts and notebooks

save_settings() None[source]#
save_implementations() None[source]#
load_implementations() None[source]#
save_units() None[source]#
load_units() None[source]#
get_real_type() type[source]#

Returns default numpy float type

get_complex_type() type[source]#

Returns default numpy complex type

store_current_basis_operator(op: Any) None[source]#
remove_current_basis_operator() None[source]#
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 utype is not in allowed_utypes or units is not recognized for utype.

unset_current_units(utype: str) None[source]#

Restores previously saved units of a given type

get_current_units(utype: str) str[source]#
cu_energy(val: float | ndarray, units: str = '1/cm') Any[source]#

Converst to current energy units

iu_energy(val: float | ndarray, units: str = '1/cm') Any[source]#

Converst to internal energy units

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

get_implementation_prefix(package: str = '', taskname: str = '') str[source]#
get_implementation_points() dict[str, str][source]#
get_all_implementations() dict[str, dict[str, str]][source]#
get_all_implementations_of(imp: str) dict[str, str][source]#
get_current_implementation(imp: str) str[source]#
set_current_implementation(imp: str, choice: str) None[source]#
register_implementation(imp_point: str, prefix: str, asint: Any = None) None[source]#
commit_implementation(imp_point: str, prefix: str, asint: Any = None) None[source]#
get_current_basis() int[source]#

Returns the current basis id

set_new_basis(SS: Any) int[source]#
transform_to_current_basis(operator: Any) None[source]#

Transforms an operator to the currently used basis

Parameters:

operator (operator) – Any basis managed operator

register_with_basis(nb: int, operator: Any) None[source]#
class quantarhei.core.managers.Managed[source]#

Bases: object

Base class for managed objects

manager = <quantarhei.core.managers.Manager object>#
class quantarhei.core.managers.UnitsManaged[source]#

Bases: Managed

Base class for objects with management of units

convert_energy_2_internal_u(val: float | ndarray) float | ndarray[source]#
convert_energy_2_current_u(val: float | ndarray) float | ndarray[source]#
convert_length_2_internal_u(val: float | ndarray) float | ndarray[source]#
convert_length_2_current_u(val: float | ndarray) float | ndarray[source]#
unit_repr(utype: str = 'energy') str[source]#
unit_repr_latex(utype: str = 'energy') str[source]#
class quantarhei.core.managers.EnergyUnitsManaged[source]#

Bases: Managed

utype = 'energy'#
units = '1/fs'#
convert_2_internal_u(val: float | ndarray) float | ndarray[source]#
convert_2_current_u(val: float | ndarray) float | ndarray[source]#
unit_repr() str[source]#
unit_repr_latex(utype: str = 'energy') str[source]#
class quantarhei.core.managers.LengthUnitsManaged[source]#

Bases: Managed

Class providing functions for length units conversion

utype = 'length'#
units = 'A'#
convert_2_internal_u(val: float | ndarray) float | ndarray[source]#
convert_2_current_u(val: float | ndarray) float | ndarray[source]#
unit_repr() str[source]#
unit_repr_latex() str[source]#
class quantarhei.core.managers.BasisManaged[source]#

Bases: Managed

Base class for objects with managed basis

get_current_basis() int[source]#
set_current_basis(bb: int) None[source]#
class quantarhei.core.managers.units_context_manager(utype: str = 'energy')[source]#

Bases: object

General context manager to manage physical units of values

class quantarhei.core.managers.energy_units(units: str)[source]#

Bases: units_context_manager

Context manager for units of energy.

Sets the active energy units for the duration of the with block 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_units

Context manager for units of frequency.

Behaves identically to energy_units since 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_manager

Context manager for length units.

Sets the active length units for the duration of the with block 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: object

General context manager to manage basis

class quantarhei.core.managers.eigenbasis_of(operator: Any)[source]#

Bases: basis_context_manager

Context 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'). If None, all unit types are reset to their internal defaults.

Raises:

Exception – If any key in units is 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'