lightlab.util.io.jsonpickleable module

Objects that can be serialized in a (sort of) human readable json format

Tested in tests.test_JSONpickleable.

Summary

Classes:

HardwareReference Spoofs an instrument
JSONpickleable Produces human readable json files.

Reference

class HardwareReference(klassname)[source]

Bases: object

Spoofs an instrument

open()[source]
class JSONpickleable(**kwargs)[source]

Bases: lightlab.laboratory.Hashable

Produces human readable json files. Inherits _toJSON from Hashable Automatically strips attributes beginning with __.

notPickled

set – names of attributes that will be guaranteed to exist in instances. They will not go into the pickled string. Good for references to things like hardware instruments that you should re-init when reloading.

See the test_JSONpickleable for much more detail

What is not pickled?
  1. attributes with names in notPickled
  2. attributes starting with __
  3. VISAObjects: they are replaced with a placeholder HardwareReference
  4. bound methods (not checked, will error if you try)
What functions can be pickled
  1. module-level, such as np.linspace
  2. lambdas

Todo

This should support unbound methods

Args:
filepath (str/Path): path string to file to save to
notPickled = set()
copy()[source]

This will throw out hardware references and anything starting with __

Good test for what will be saved

save(filename)[source]
classmethod load(filename)[source]