rigetti / paranormal Goto Github PK
View Code? Open in Web Editor NEWA declarative, parameter-parsing library that provides multiple parsing interfaces (YAML, command line, and JSON)
License: Apache License 2.0
A declarative, parameter-parsing library that provides multiple parsing interfaces (YAML, command line, and JSON)
License: Apache License 2.0
Ex.
class A(Params):
i = IntParam(help='int', default=1)
class B(Params):
f = FloatParam(help='float', default=2.0)
z = IntParam(help='another int')
concatenate_param_attributes(A, B, do_not_copy=['z'], override_dictionary={'f' : {'help': 'a better float', 'default': 3.0}})
a = A()
print(a.f) # prints 3.0
print(a.z) # throws error
When creating nested params, want to be able to hide some from the command line but not omit them
This happens when enclosing classes set the nested class param value within its constructor
Failure mode:
class A(Params):
f = FloatParam(help='float', default=2)
class B(Params):
a = A(f = 5)
b = B()
to_json_serializable_dict(b) # will give {'a': {'f': 5, ...}, ...} as expected
b.a.f = 7
to_json_serializable_dict(b) # will give {'a': {'f': 5, ...}, ...}, which should actually be
# {'a': {'f': 7, ...}, ...}
Ex.
class MultipleFreqSweeps(Params):
sweep_1 = FrequencySweep(freqs=[0, 1, 100])
sweep_2 = FrequencySweep(freqs=[1, 2, 100])
When you convert this class to a parser and parse a blank command line, the returned class
will not have sweep_1 freqs = [0,1,100] and sweep_2_freqs = [1,2,100]. Instead, both will be whatever the default for freqs is that's specified within FrequencySweep.
If you have something like:
class FreqSweep(Params):
freqs = SpanArangeParam(help='freqs', default=[1, 1, 0.1], unit='GHz')
and you don't want freqs to be a span arange for some reason, you should be able to override the descriptor behavior like so:
f = FreqSweep()
f.override('freqs', np.linspace(1e9, 20e9, 100), to_json_hook=lambda x: x.tolist(), from_json_hook=lambda x: np.array(x))
print(f.freqs) # prints an array of 100pts from 1e9 to 20e9
f.freqs = [1, 1, 0.1] # returns to default behavior
Note that overriding the SpanArangeParam will break JSON serializability guarantees, so we add extra arguments to give the user an option to provide their own JSON hooks.
This will require refactoring all descriptor get and set methods as well as JSON serialization routines.
Ex.
class P(Params):
a = LinspaceParam(help='linspace', default=[0.0, 1.0, 100])
p = P()
p.get_numpy_fn_param('a')[1] += 5
print(p.get_numpy_fn_param('a')) # prints [0.0, 6.0, 100]
It uses it as as [center, width, num]
when it's implemented as [center, width, step]
The package pyproject toml is using ^
limit some packages which is causing versioning conflicts.
^
in poetry prevents changes on the leftmost non-zero digit. In the case of, for example, pampy = "^0.2.1", we're stuck with the minor revision 0.2.x
and only have wiggle room to change the patch versions; which is problematic.
Setting some packages to >=
could be useful.
paranormal/paranormal/parameter_interface.py
Line 762 in 6d17c7e
This will be a useful function to expose
This breaks the Params __init__
function when you subclass it twice
def __init__(self, **kwargs):
cls = type(self)
for key, value in kwargs.items():
if not key in cls.__dict__:
raise KeyError(f'{cls.__name__} does not take {key} as an argument')
setattr(self, key, value)
_check_for_required_arguments(cls, kwargs)
ex.
class A(Params):
x = BoolParams(default=True, help='')
class B(A):
y = IntParam(help='')
# raises a KeyError
b = B(x=False)
Right now, if you have a value in SI units, you need to call params.x = unconvert_si_units(value, get_param_unit(cls, 'x'))
, which is unnecessarily verbose. It would be nice to use something like param.si_set('x', value)
instead
Ex:
class A(Params):
x = IntParam(help='int')
class B(Params):
a = A()
remove_params(a, 'x')
x = IntParam(help='a better int')
Right now, if you construct an instance of a Params subclass, you either need to manually create an __init__
function to override the BaseClass init to explicitly show what the subclass attributes are. Or, you need to read the source code.
Neither of these is ideal for people scripting in Ipython or using a jupyter notebook.
Possible avenues:
__init__
function through a decorator on the Params subclassEx.
class A(Params):
f = FloatParam(help='float', default=2)
class B(Params):
a = A(f = 5)
b = B()
b.a.f = 7
x = B()
print(x.a.f) # prints 7 and not 5
If a param has a certain unit, += is broken
Ex.
class A:
b = FloatParam(help='float', unit='ns')
a = A()
a.b = 2
print(a.b) # prints 2e-9
a.b += 2
print(a.b) # prints (2e-9 + 2) * 1e-9
There's no way to block the __iadd__
method for this case because what's actually being called is the __iadd__
method on a.b, which is a float. The alternative is to use si_set:
a.si_set('b', a.b + 2e-9)
but this isn't that nice. Alternatives are to remove units from the __get__
and __set__
methods and only use them for parsing from the command line or from a yaml.
Can't turn Params classes including a SpanArangeParam into an argparse instance
Would be pretty cool if you could do something like:
--delays 0 100 10 --delays_function Linspace
or
--delays 0 100 10 --delays_function Arange
and the corresponding Param would be created. You can imagine having a Param called NumpyFunctionParam that isn't specific and will add an extra x_function argument to the parser or to the json dictionary. That function will specify which function should be executed on those parameters.
This would be a really cool feature and actually wouldn't require that significant of a refactor (if we were to implement it the way I've specified above
paranormal/paranormal/parameter_interface.py
Line 353 in 5758336
If the user would like no prefixes, then there should be no prefixes - merge conflicts at your own risk
When initializing a param, it would be nice to have the option to set it as a hidden param without naming it using a leading underscore.
Should pass back the argument as a tuple
Instead of Lists, we should allow both a list and a tuple for params like SpanArange, etc.
Ex.
class A(Params):
freqs = SpanArangeParam(default=(1, 2, 0.1), help='freqs')
a = A()
a.freqs = [0, 1, 0.2]
a.freqs = (0, 2, 0.5)
in __nested_prefixes__
, example is given in readme as:
# Customize prefixes used for command line parsing
class MultipleFreqSweepsCustom(Params):
sweep_1 = FrequencySweep()
sweep_2 = FrequencySweep()
__nested_prefixes__ = {'sweep_1': None, 'sweep_2': 'second_'}
# Ex command line: '--freqs 100 120 2 --power -30 --second_power -40'
but the _
gets added again by _create_param_name_prefix
when it shouldn't
Example:
class A(Params):
freqs = LinspaceParam(expand=True, help='lin')
class B(Params):
freqs = LinspaceParam(expand=True, help='lin')
class C(Params):
a = A()
b = B()
c = create_parser_and_parse_args(C)
# Should be able to parse: --a_freqs_center --a_freqs_width --a_freqs_num --b_freqs_center --b_freqs_width --b_freqs_num
Additionally, it should handle conflicts within the same class:
class A(Params):
freqs = LinspaceParam(expand=True, help='freqs')
powers = LinspaceParam(expand=True, help='pwrs')
a = create_parser_and_parse_args(A)
# Should become --freqs_center --freqs_width --freqs_num --powers_center --powers_width --powers_num
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.