def convert_parameter(name, value, converter=None): if isinstance(value, Parameter): if callable(converter): value.set_parser = converter return value if callable(converter): return Parameter(name, converter(value), set_parser=converter) return Parameter(name, value)
def assert_no_parallel_function_evaluation(): e = Parameter('e', 1) @experiment def baz(): return e() with pytest.raises(IndexError): assert baz(parallel=True)
def test_serial_function_evaluation(): d = Parameter('d', 2) @experiment def bar(): return d() assert bar() == 2 assert bar(d=4) == 4 assert bar() == 4
def test_grid_search(): x = Parameter('x') @experiment def result(): return x**2 opt = GridSearch(result, steps=5) opt.add_parameter(x, bounds=(-1, 1)) opt.run() assert (opt.X.flatten() == [-1, -0.5, 0, 0.5, 1]).all()
def test_inplace(): z = Parameter('z', 1) z += 1 assert z == 2 z -= 1 assert z == 1 z *= 2 assert z == 2 z /= 2 assert z == 1
from dashboard import API import attr from parametric import Parameter, Attribute, Instrument @attr.s class MyInstrument(Instrument): x = Attribute('x', 0) name = attr.ib(default='MyInstrument') y = Parameter('y', 1) inst = MyInstrument(x=2) api = API(globals()) api.run() def test_parameter_endpoints(): api.get('/parameters/y/set/3.14') # set parameter value assert api.get('/parameters/y/get') == 3.14 # get parameter value def test_instrument_endpoints(): api.get('/instruments/MyInstrument/parameters/x/set/6.28') # set instrument parameter assert api.get('/instruments/MyInstrument/parameters/x/get') == 6.28 # get instrument parameter def test_shutdown(): api.get('/shutdown')
def test_add_existing_parameter(): e = Algorithm(result) phase = Parameter('phase', bounds=[0, 6.28]) e.add_parameter(phase) assert 'phase' in e.parameters assert e.bounds['phase'] == [0, 6.28]
from parametric import Parameter import pytest x = Parameter('x', 2, bounds=(2, 4)) y = Parameter('y', 3) def test_neg(): assert -x == -2 def test_add(): assert x + 2 == 2 + x == 4 assert x + y == y + x == 5 def test_sub(): assert x - 2 == -(2 - x) == 0 assert x - y == -(y - x) == -1 def test_mult(): assert 2 * x == x * 2 == 4 assert x * y == y * x == 6 def test_div(): assert x / 2 == 1 / (2 / x) == 1 assert x / y == 1 / (y / x) == 2 / 3
IconButton(context, "./icons/save.png", 50 + 2 * icon_spacing, 50, func1) IconButton(context, "./icons/load.png", 50 + 3 * icon_spacing, 53, func1) IconButton(context, "./icons/settings.png", 50 + 4 * icon_spacing, 50, func1) Label(context, 'Status: Ready.', 30, 90, 40, context.black, centered=False) Label(context, 'Transmission: 0.0 V', 30, 120, 40, context.black, centered=False) from parametric import Parameter x = Parameter('x', 0) y = Parameter('y', 0) from parameter_widget import IncrementLabel IncrementLabel(context, 'X', x, 30, 230) IncrementLabel(context, 'Y', y, 30, 330) pygame.display.update() ''' Touchscreen/mouse loops ''' if not args.dev: while True: pos = touchscreen.position() print(pos) context.on_click(pos) pygame.display.update()