Labmate

Latest version: v0.7.0

Safety actively analyzes 641221 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 2

0.6.0

Version 0.6.0. What's new?

Quickly:

- You can access the filename inside `parse_config_str` function
- Smarter config parsing. Now you can save the values used during acquisition.
- `cfg` is now an attribute of `aqm.data` object.
- Linting works with the local function definition.
- Add json utils
- class Path have more functionality

You can access the filename inside `parse_config_str` function

As easy as it sounds all these syntaxes are possible:

python
aqm.parse_config_str(['filename']) -> "filename = ..."

aqm.parse_config_str(['file']) -> "file = ..."

aqm.parse_config_str(['f']) -> "f = ..."


`cfg` is now an attribute of `aqm.data` object.

With version 0.5.0 possibility to parse default configurations was added.
The syntax is like this:

python
aqm.set_default_config_files(['config1.py', ...])
...
aqm.analysis_cell()
aqm.cfg.b Wrong way to access the configuration value


But to make it more explicit that the configurations which have been parsed is the ones saved during acquisition, the best practice is to use `aqm.data.cfg` instead.

python
aqm.set_default_config_files(['config1.py', ...])
...
aqm.analysis_cell()
aqm.data.cfg.b Right way


Keep in mind that in future updates the syntax `aqm.cfg` could be suspended.

Smarter config parsing. Now you can save the values used during acquisition.

More on parsing the configurations files. Some configuration files are like this:

python
def local_switch(param):
if param == 'a':
return 'param_a'
return 'param_b'

str_1 = "a"
str_2 = local_switch(str_1)


And it's evident that str_2 is equal to "param_b". We still don't want to eval the config file during analysis just to find out what the values are. But you imported the config file during the acquisition, so why not save the values that were used? And this is exactly the logic of the following function.

Suppose you have the configuration file named `config.py` with the code given just above. Inside your main script you `import config as some_cfg`. Then, you should give this module to aqm:

python
aqm.set_config_file(["files/config.py"])
aqm.set_config_evaluation_module("files/config.py", some_cfg)


Remember that the name of the config files should be unique even if there are in different folders.

Then inside your analysis_cell you can parse `str_2` parameter.

python
aqm.analysis_cell()

aqm.data.parse_config_str(['str_1', 'str_2'])
-> 'str_1 = a; str_2 = param_a'


Linting works with the local function definition.

Now the linting works with the local function definition, but not completely ignores it. It will ignore all the local variables inside your function, but will lint the global ones.

Example:

python
aqm.analysis_cell()
def abc(a, b):
c = a + b
return c * x


This code will lint only `x` variable.

Add json utils

Problems with classical json that are solved:

- When loading, int and float values are strings. So `read` function uses `NumbersDecoder` by default.
- When dumping, object that can be converted to string or list are not converted. So `write` function converts objects to string and iterable to list.

Example:

python
from labmate import json as jsn
data = {'a': 1}
jsn.write(path, data)


python
from labmate import json as jsn
data = jsn.read(path)


Better Path class

Class Path is improvement of class Path from standard pathlib library. And now it's even better.

Features of Path class:

- `makedirs`. Same as os.makedirs(dirname(path)).
- `make_extension`. Checks is extension of the file is the one (or ones) expected. Otherwise add suffix to the end of the path.

Useful properties:

- `dirname`
- `basename`

Both return object of type Path.

Minor features

- Fix bugs with `AcquisitionLoop`
- Fix the bug at detecting an error in a last acquisition_cell run
- Remove all `from __future__ import annotations`
- Ignore bool type during config evaluation

0.5.0

Version 0.5.0. What's new?

Quickly:

- Linting ignores the variables inside save_acquisition
- New AcquisitionLoop which saves on edit
- Possibility to save data with setitem on aqm
- Possibility to precise inside the analysis_cell the name of the expected acquisition
- Parse config files more easily
- Prerun hook, i.e. a function that runs at the beginning of each acquisition or analysis.

Linting ignores the variables inside save_acquisition

The title is explicit, now there is no need to write `noqa` at the end of each line of `save_acquisition`, all variables are ignored automatically.

New AcquisitionLoop which saves on edit

Previously `AcquisitionLoop` did not support saving on edit, or to be more precise, it saved everything every time something changed. This is not normal, so this module has been rewritten and now only saves the part that has been changed.

Usage is the same:

python
aqm['loop'] = loop = AcquisitionLoop()
for i in loop.iter(10):
loop.append(x=i**2)
aqm.save_acquisition()


Or the same thing in the more short way:

python
aqm['loop'] = loop = AcquisitionLoop()
for i in loop(10):
loop(x=i**2)
aqm.save_acquisition()


Note: In case of any bugs, the old AcquisitionLoop is still available using `AcquisitionLoopOld` class. But if there's any problem open an issue, please.

Possibility to save data with setitem on aqm

Now it's possible to save data as:

python
aqm['loop'] = AcquisitionLoop()


Instead of this:

python
aqm.aq['loop'] = AcquisitionLoop()


Note:

- This function is only available **inside `acquisition_cell`** and **not `analysis_cell`**. Inside an analysis_cell use `aqm.d['key']=value` to save something.
- It's only possible to save data and not get it. To get data use `aqm.d['key']` inside `analysis_cell` or `aqm.aq['key']` inside `acquisition_cell`.

Possibility to precise inside the analysis_cell the name of the expected acquisition

Sometimes you have to double-check that you don't start the wrong analysis. Now it's possible to specify inside an analysis_cell which acquisition_cell it should follow.

Suppose an acquisition cell is:

python
aqm.acquisition_cell("measure_1")
...


Then, inside an analysis cell:

python
aqm.analysis_cell(acquisition_name = "measure_1")
...


It's also possible to use regex syntax:
(note: string should start with `^`)

python
aqm.analysis_cell(acquisition_name = r"^measure_\d")
...


Parse config files more easily

From v0.4.0 it was possible to do something like this to output the values:

python
aqm.parse_config_str(["a", "b"]) -> 'a = 123; b = 123000'


But what if you needed to get the actual value? The solution before was:

python
aqm.set_default_config_files(['config1.py', 'config2.py'])
data = aqm.parse_config()
data['x'] -> 123
data.b -> 123


Now you can do:

python
aqm.set_default_config_files(['config1.py', 'config2.py'])
aqm.cfg['x'] -> 123
aqm.cfg.b -> 123000


Note: values inside the config files are calculated once and then cached to make access quicker. Therefore, you should not modify them.

Prerun hook

If you have a default function that should be run before each acquisition or analysis, it's possible to provide it as a hook.

First, define the function:

python
def check_instruments():
...


Then inside the acquisition cell give this function as an argument:

python
aqm.acquisition_cell('measure_1', prerun=check_instruments)
...


It is also possible to pass a default function for all acquisition cells:

python
aqm.set_acquisition_cell_prerun_hook(check_instruments)


Note:

- It's possible to provide a list of functions or do a mix between default functions and locally given ones.

- The same possibility exists for `analysis_cell`. Use `prerun` as a keyword or `set_analysis_cell_prerun_hook` for the global definition.

Minor features

- tight_layout is run by default before saving the figure.
- Almost everything is tested so hope a number of the errors will converge to zero. Coverage report: 96%.

0.4.0

Version 0.4.0. What's new?

Quickly:

- Linting error inside analysis_cell!
- Function to parse your config files
- New class AttrDict. Classical dictionary accessible by attr

Parse config files

python
aqm.set_default_config_files(['config1.py', 'config2.py'])

aqm.parse_config_str(["a", "b"]) -> 'a = 123; b = 123000'


Units and format

It's possible to provide a unit and a format to parse config function.
Use the such structure for the string `key__unit__format`.

Examples:

python

0.3.0

0.2

Stable release

0.1.0

First published working version

Page 2 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.