Skip to content

Commit d61487e

Browse files
committed
Minor Fixes
1 parent 1cbc5c5 commit d61487e

File tree

7 files changed

+152
-132
lines changed

7 files changed

+152
-132
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.9.0 - 2023/01/29 - 00 - Minor Fixes
4+
* Updated documentation of `qom.systems.BaseSystem` and `qom.ui.axes.BaseAxis` modules.
5+
* Minor fixes for 3D plot linewidths in `qom.ui.plotters.MPLPlotter` module.
6+
* Minor fixes to parellel instances in `qom.utils.looper` module.
7+
* Minor updates to docsources.
8+
39
## v0.9.0 - 2022/11/08 - 00 - Multiprocessing Support
410
* Updated `qom.loopers.BaseLooper` module:
511
* Added process variables to support object multiprocessing.

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20-
project = 'Quantum Optomechanics Toolbox'
21-
copyright = '2020, Sampreet Kalita'
20+
project = 'The Quantum Optomechanics Toolbox'
21+
copyright = '2023, Sampreet Kalita'
2222
author = 'Sampreet Kalita'
2323

2424

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. Quantum Optomechanics Toolbox documentation master file, created by
22
sphinx-quickstart on Fri Dec 4 15:06:12 2020.
33
4-
Welcome to the Documentation!
5-
=============================
4+
Welcome to the ``qom-v0.9.0`` Documentation!
5+
============================================
66

77
The Quantum Optomechanics Toolbox (packaged as ``qom``) is a wrapper-styled, scalable toolbox featuring multiple modules for the calculation of stationary as well as dynamical properties of many-body quantum optomechanical systems.
88
Its inheritable system classes can also be used to study other systems that follow the optomechanical model.

qom/systems/BaseSystem.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__name__ = 'qom.systems.BaseSystem'
77
__authors__ = ['Sampreet Kalita']
88
__created__ = '2020-12-04'
9-
__updated__ = '2022-09-18'
9+
__updated__ = '2022-11-26'
1010

1111
# dependencies
1212
from typing import Union
@@ -99,15 +99,15 @@ class BaseSystem():
9999
100100
Some methods require one or more of the following predefined callables to work properly:
101101
====================== ================================================
102-
callable purpose
102+
callable returns
103103
====================== ================================================
104-
func_ode function returning the rate equations of the classical mode amplitudes and quantum correlations, formatted as ``func_ode(t, v, c)``, where ``t`` is the time at which the integration is performed, ``v`` is a list of the amplitudes and fluctuations and ``c`` is a list of constant parameters. The output should match the dimension of ``v``. If ``func_ode_corrs`` parameter is given, this function is treated as the function for the modes only.
105-
func_ode_corrs function returning rate equations of the quantum correlations. It follows the same formatting as ``func_ode``.
106-
get_A function to obtain the drift matrix, formatted as ``get_A(modes, params, t)``, where ``modes`` are the modes amplitudes at time ``t`` and ``params`` are the constant parameters of the system. Returns the drift matrix ``A``.
107-
get_ivc function to obtain the initial values and constants, formatted as ``get_ivc()``. Returns values ``iv`` and ``c`` for the initial values and constants respectively.
108-
get_mode_rates function to obtain the rate of the classical mode amplitudes for a given list of modes, formatted as ``get_mode_rates(modes, params, t)``, where ``modes`` are the modes amplitudes at time ``t`` and ``params`` are the constant parameters of the system. Returns the mode rates with same dimension as ``modes``.
109-
get_oss_args function to obtain the required parameters to calculate the optical steady state, formatted as ``get_oss_args(params)``, where ``params`` are the constant parameters of the system.
110-
get_oss_modes function to obtain the classical mode amplitudes from the mean optical occupancy, formatted as ``get_oss_modes(params)``, where ``params`` are the constant parameters of the system. Returns the list of modes calculated for each mean optical occupancy.
104+
func_ode the rate equations of the classical mode amplitudes and quantum correlations, formatted as ``func_ode(t, v, c)``, where ``t`` is the time at which the integration is performed, ``v`` is a list of the amplitudes and fluctuations and ``c`` is a list of constant parameters. The output should match the dimension of ``v``. If ``func_ode_corrs`` parameter is given, this function is treated as the function for the modes only.
105+
func_ode_corrs the rate equations of the quantum correlations. It follows the same formatting as ``func_ode``.
106+
get_A the drift matrix, formatted as ``get_A(modes, params, t)``, where ``modes`` are the modes amplitudes at time ``t`` and ``params`` are the constant parameters of the system. Returns the drift matrix ``A``.
107+
get_ivc the initial values and constants, formatted as ``get_ivc()``. Returns values ``iv`` and ``c`` for the initial values and constants respectively.
108+
get_mode_rates the rates of the classical mode amplitudes, formatted as ``get_mode_rates(modes, params, t)``, where ``modes`` are the modes amplitudes at time ``t`` and ``params`` are the constant parameters of the system. Returns the mode rates with same dimension as ``modes``.
109+
get_oss_args the parameters required to calculate the optical steady states, formatted as ``get_oss_args(params)``, where ``params`` are the constant parameters of the system.
110+
get_oss_modes the steady state classical mode amplitudes from the mean optical occupancies, formatted as ``get_oss_modes(params)``, where ``params`` are the constant parameters of the system. Returns the list of modes calculated for each mean optical occupancy.
111111
====================== ================================================
112112
113113
The ``get_oss_args`` function should return the following values in order:

qom/ui/axes/BaseAxis.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ class BaseAxis():
3131
Values for the axis supporting a list of values or a dictionary containing the range of values with keys "min", "max", "dim" and "scale" or the values themselves under key "val".
3232
plotter_params : dict
3333
Parameters for the plotter. Currently supported keys are:
34-
============== ====================================================
35-
key value
36-
============== ====================================================
37-
"label" (*str*) text of the axis label.
38-
"label_color" (*str*) color of the axis label.
39-
"label_pad" (*int*) padding of the axis label.
40-
"limits" (*list*) minimum and maximum limits for the axis.
41-
"scale" (*str*) step scale for the values. Options are "linear" and "log".
42-
"tick_dim" (*float*) dimension of the ticks.
43-
"tick_labels" (*list*) tick labels of the plots.
44-
"tick_pad" (*int*) padding of the tick labels.
45-
"tick_position" (*str*) position of ticks on the plot. Options are "both", "bottom", "left", "right" or "top".
46-
"ticks" (*list*) ticks of the plots.
47-
"ticks_minor" (*list*) positions of minor ticks of the plots.
48-
============== ====================================================
34+
================ ================================================
35+
key value
36+
================ ================================================
37+
"label" (*str*) text of the axis label.
38+
"label_color" (*str*) color of the axis label.
39+
"label_pad" (*int*) padding of the axis label.
40+
"limits" (*list*) minimum and maximum limits for the axis.
41+
"scale" (*str*) step scale for the values. Options are "linear" and "log".
42+
"tick_dim" (*float*) dimension of the ticks.
43+
"tick_labels" (*list*) tick labels of the plots.
44+
"tick_pad" (*int*) padding of the tick labels.
45+
"tick_position" (*str*) position of ticks on the plot. Options are "both", "bottom", "left", "right" or "top".
46+
"ticks" (*list*) ticks of the plots.
47+
"ticks_minor" (*list*) positions of minor ticks of the plots.
48+
================ ================================================
4949
"""
5050

5151
# attributes

qom/ui/plotters/MPLPlotter.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__name__ = 'qom.ui.plotters.MPLPlotter'
77
__authors__ = ['Sampreet Kalita']
88
__created__ = '2020-10-03'
9-
__updated__ = '2022-11-04'
9+
__updated__ = '2023-01-29'
1010

1111
# dependencies
1212
from matplotlib.colors import LinearSegmentedColormap, Normalize
@@ -354,6 +354,20 @@ def _resize_plot(self, width: float=4.8, height: float=4.8):
354354
if _min < 4.0:
355355
_min = 4.0
356356

357+
# update 3D axes
358+
if self.params['type'] in self.types_3D:
359+
_mpl_axes = plt.gca()
360+
_axes = [_mpl_axes.xaxis, _mpl_axes.yaxis, _mpl_axes.zaxis]
361+
for _ax in _axes:
362+
_ax._axinfo['tick'].update({
363+
'linewidth': {
364+
True: _min / 5.0,
365+
False: _min / 20.0
366+
},
367+
'inward_factor': _min / 20.0
368+
})
369+
# _ax.set_tick_params(length=_min, width=_min / 5.0, which='major')
370+
# _ax.set_tick_params(length=_min / 2.0, width=_min / 5.0, which='minor')
357371
# update all axes
358372
for _ax in plt.gcf().get_axes():
359373
# update spines

qom/utils/looper.py

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import os
1111
import time
1212

13-
"""Module for utility functions to wrap subpackages."""
13+
"""Module containing utility functions for loopers."""
1414

1515
__name__ = 'qom.utils.looper'
1616
__authors__ = ['Sampreet Kalita']
1717
__created__ = '2021-05-25'
18-
__updated__ = '2022-09-19'
18+
__updated__ = '2023-01-29'
1919

2020
# qom modules
2121
from ..ui import init_log
@@ -125,106 +125,6 @@ def func_params(system_params, val, logger, results):
125125

126126
return func
127127

128-
def wrap_looper(SystemClass, params: dict, func, looper, file_path_prefix: str=None, plot: bool=False, hold: bool=True, width: float=5.0, height: float=5.0, parallel=False, p_start=time.time(), p_index=0):
129-
"""Function to wrap loopers.
130-
131-
Requires already defined callables ``func_ode``, ``get_mode_rates``, ``get_ivc``, ``get_A`` and ``get_oss_args`` inside the system class.
132-
133-
Parameters
134-
----------
135-
SystemClass : :class:`qom.systems.*`
136-
Class containing the system.
137-
params : dict
138-
All parameters as defined in :class:`qom.loopers.BaseLooper`.
139-
func : str or callable
140-
Code of the function or the function to loop, following the format defined in :class:`qom.loopers.BaseLooper`. Available function codes are:
141-
============== ================================================
142-
value meaning
143-
============== ================================================
144-
"aes" averaged eigenvalue of the drift matrix.
145-
"cad" classical amplitude difference.
146-
"cpd" classical phase difference.
147-
"les" Lyapunov exponents.
148-
"mav" measure averages (fallback).
149-
"mdy" measure dynamics.
150-
"moo" mean optical occupancies.
151-
"mss" stationary measure.
152-
"osz" optical stability zone.
153-
"pcc" Pearson correlation factor.
154-
============== ================================================
155-
looper : str
156-
Code of the looper. Available options are:
157-
============== ================================================
158-
value meaning
159-
============== ================================================
160-
"XLooper" 1D looper (:class:`qom.loopers.XLooper`) (fallback).
161-
"XYLooper" 2D looper (:class:`qom.loopers.XYLooper`).
162-
"XYZLooper" 3D looper (:class:`qom.loopers.XYZLooper`).
163-
============== ================================================
164-
file_path_prefix : str, optional
165-
Prefix of the file path.
166-
plot: bool, optional
167-
Option to plot the results.
168-
hold : bool, optional
169-
Option to hold the plot.
170-
width : float, optional
171-
Width of the figure.
172-
height : float, optional
173-
Height of the figure.
174-
parallel : bool, optional
175-
Option to format outputs when the looper is run in parallel.
176-
p_start : float, optional
177-
Time at which the process was started. If `None`, the value is initialized to current time.
178-
p_index : int, optional
179-
Index of the process.
180-
181-
Returns
182-
-------
183-
looper : :class:`qom.loopers.*`
184-
Instance of the looper.
185-
"""
186-
187-
# initialize logger
188-
init_log(parallel=parallel)
189-
190-
# select function
191-
if type(func) is str:
192-
func = get_looper_func(SystemClass=SystemClass, solver_params=params.get('solver', {}), func_code=func)
193-
194-
# select looper
195-
if type(looper) is str:
196-
if looper == 'XYLooper':
197-
looper = XYLooper(func=func, params=copy.deepcopy(params), parallel=parallel, p_start=p_start, p_index=p_index)
198-
elif looper == 'XYZLooper':
199-
looper = XYZLooper(func=func, params=copy.deepcopy(params), parallel=parallel, p_start=p_start, p_index=p_index)
200-
else:
201-
looper = XLooper(func=func, params=copy.deepcopy(params), parallel=parallel, p_start=p_start, p_index=p_index)
202-
203-
# wrap looper
204-
looper.wrap(file_path_prefix=file_path_prefix, plot=plot, hold=hold, width=width, height=height)
205-
206-
return looper
207-
208-
def run_wrap_looper_instance(args):
209-
'''Function to run a single instance of `wrap_looper`.
210-
211-
Parameters
212-
----------
213-
args : list
214-
Arguments of the `wrap_looper` function.
215-
216-
Returns
217-
-------
218-
looper : :class:`qom.loopers.*`
219-
Instance of the looper.
220-
'''
221-
222-
# extract arguments
223-
SystemClass, params, func, looper, file_path_prefix, plot, hold, width, height, parallel, p_start, p_index = args
224-
225-
# return instance
226-
return wrap_looper(SystemClass=SystemClass, params=params, func=func, looper=looper, file_path_prefix=file_path_prefix, plot=plot, hold=hold, width=width, height=height, parallel=parallel, p_start=p_start, p_index=p_index)
227-
228128
def run_loopers_in_parallel(SystemClass, params: dict, func, looper, file_path_prefix: str=None, plot: bool=False, hold: bool=True, width: float=5.0, height: float=5.0, num_loopers: int=None):
229129
"""Function to wrap loopers.
230130
@@ -281,7 +181,7 @@ def run_loopers_in_parallel(SystemClass, params: dict, func, looper, file_path_p
281181
if 'XYZ' in looper:
282182
looper = XYZLooper(func=func, params=params, parallel=True)
283183
axis = 'Z'
284-
if 'XY' in looper:
184+
elif 'XY' in looper:
285185
looper = XYLooper(func=func, params=params, parallel=True)
286186
axis = 'Y'
287187
else:
@@ -365,4 +265,104 @@ def run_loopers_in_parallel(SystemClass, params: dict, func, looper, file_path_p
365265
if plot:
366266
looper.plot_results(hold=hold, width=width, height=height)
367267

268+
return looper
269+
270+
def run_wrap_looper_instance(args):
271+
'''Function to run a single instance of `wrap_looper`.
272+
273+
Parameters
274+
----------
275+
args : list
276+
Arguments of the `wrap_looper` function.
277+
278+
Returns
279+
-------
280+
looper : :class:`qom.loopers.*`
281+
Instance of the looper.
282+
'''
283+
284+
# extract arguments
285+
SystemClass, params, func, looper, file_path_prefix, plot, hold, width, height, parallel, p_start, p_index = args
286+
287+
# return instance
288+
return wrap_looper(SystemClass=SystemClass, params=params, func=func, looper=looper, file_path_prefix=file_path_prefix, plot=plot, hold=hold, width=width, height=height, parallel=parallel, p_start=p_start, p_index=p_index)
289+
290+
def wrap_looper(SystemClass, params: dict, func, looper, file_path_prefix: str=None, plot: bool=False, hold: bool=True, width: float=5.0, height: float=5.0, parallel=False, p_start=time.time(), p_index=0):
291+
"""Function to wrap loopers.
292+
293+
Requires already defined callables ``func_ode``, ``get_mode_rates``, ``get_ivc``, ``get_A`` and ``get_oss_args`` inside the system class.
294+
295+
Parameters
296+
----------
297+
SystemClass : :class:`qom.systems.*`
298+
Class containing the system.
299+
params : dict
300+
All parameters as defined in :class:`qom.loopers.BaseLooper`.
301+
func : str or callable
302+
Code of the function or the function to loop, following the format defined in :class:`qom.loopers.BaseLooper`. Available function codes are:
303+
============== ================================================
304+
value meaning
305+
============== ================================================
306+
"aes" averaged eigenvalue of the drift matrix.
307+
"cad" classical amplitude difference.
308+
"cpd" classical phase difference.
309+
"les" Lyapunov exponents.
310+
"mav" measure averages (fallback).
311+
"mdy" measure dynamics.
312+
"moo" mean optical occupancies.
313+
"mss" stationary measure.
314+
"osz" optical stability zone.
315+
"pcc" Pearson correlation factor.
316+
============== ================================================
317+
looper : str
318+
Code of the looper. Available options are:
319+
============== ================================================
320+
value meaning
321+
============== ================================================
322+
"XLooper" 1D looper (:class:`qom.loopers.XLooper`) (fallback).
323+
"XYLooper" 2D looper (:class:`qom.loopers.XYLooper`).
324+
"XYZLooper" 3D looper (:class:`qom.loopers.XYZLooper`).
325+
============== ================================================
326+
file_path_prefix : str, optional
327+
Prefix of the file path.
328+
plot: bool, optional
329+
Option to plot the results.
330+
hold : bool, optional
331+
Option to hold the plot.
332+
width : float, optional
333+
Width of the figure.
334+
height : float, optional
335+
Height of the figure.
336+
parallel : bool, optional
337+
Option to format outputs when the looper is run in parallel.
338+
p_start : float, optional
339+
Time at which the process was started. If `None`, the value is initialized to current time.
340+
p_index : int, optional
341+
Index of the process.
342+
343+
Returns
344+
-------
345+
looper : :class:`qom.loopers.*`
346+
Instance of the looper.
347+
"""
348+
349+
# initialize logger
350+
init_log(parallel=parallel)
351+
352+
# select function
353+
if type(func) is str:
354+
func = get_looper_func(SystemClass=SystemClass, solver_params=params.get('solver', {}), func_code=func)
355+
356+
# select looper
357+
if type(looper) is str:
358+
if looper == 'XYLooper':
359+
looper = XYLooper(func=func, params=copy.deepcopy(params), parallel=parallel, p_start=p_start, p_index=p_index)
360+
elif looper == 'XYZLooper':
361+
looper = XYZLooper(func=func, params=copy.deepcopy(params), parallel=parallel, p_start=p_start, p_index=p_index)
362+
else:
363+
looper = XLooper(func=func, params=copy.deepcopy(params), parallel=parallel, p_start=p_start, p_index=p_index)
364+
365+
# wrap looper
366+
looper.wrap(file_path_prefix=file_path_prefix, plot=plot, hold=hold, width=width, height=height)
367+
368368
return looper

0 commit comments

Comments
 (0)