Code Monkey home page Code Monkey logo

paranormal's People

Contributors

caryan avatar chancez avatar deanna-abrams avatar jmackeyrigetti avatar kalzoo avatar schuylerfried avatar semantic-release-bot avatar spherical-tensor avatar stevenheidel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

paranormal's Issues

Hide vs Omit

When creating nested params, want to be able to hide some from the command line but not omit them

to_json_serializable_dict doesn't correctly serialize nested classes

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, ...}, ...}

overriding defaults of nested params class broken when parsing from the command line

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.

Be able to override the descriptor behavior by setting the attribute equal to anything

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.

remove dependency upper bounds in pyproject.toml

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.

Class attributes aren't present in subclasses

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)

Find explicit way to expose Params subclass parameters to the user when constructing an instance of the subclass

  • 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:

  1. Override the help on a class somehow, such that it prints all the attributes.
  2. Autogenerate an __init__ function through a decorator on the Params subclass

+= not blocked from params with units

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.

Allow users to specify param type in cli or yaml for subset of numpy functions

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

Streamline types for descriptors set and get

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)

prefix _ gets added twice

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

Would be nice if flattening a class automatically resolved param name conflicts by appending prefixes

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.