def test_splitter_inset(): c1 = named_parameter('c', 0.5) x = named_parameter('x', [1,2]) y = named_parameter('y', ['a', 'b', 'c', 'd']) z = named_parameter('z', [11,22]) ischeme = Constants(c1) >> ISE(x) >> ISE(y).split(2) >> ISE(z) ischeme_parts = ischeme.nested_variables ischeme_content = [IS(part) for part in ischeme_parts] parts = [list(p) for p in ischeme_content] assert(len(parts) == 2) assert(len(parts[0]) == 8) assert(len(parts[1]) == 8) assert(parts[0][0] == (0.5, 1, 'a', 11)) assert(parts[0][1] == (0.5, 1, 'a', 22)) assert(parts[0][2] == (0.5, 1, 'b', 11)) assert(parts[0][3] == (0.5, 1, 'b', 22)) assert(parts[0][4] == (0.5, 2, 'a', 11)) assert(parts[0][5] == (0.5, 2, 'a', 22)) assert(parts[0][6] == (0.5, 2, 'b', 11)) assert(parts[0][7] == (0.5, 2, 'b', 22)) assert(parts[1][0] == (0.5, 1, 'c', 11)) assert(parts[1][1] == (0.5, 1, 'c', 22)) assert(parts[1][2] == (0.5, 1, 'd', 11)) assert(parts[1][3] == (0.5, 1, 'd', 22)) assert(parts[1][4] == (0.5, 2, 'c', 11)) assert(parts[1][5] == (0.5, 2, 'c', 22)) assert(parts[1][6] == (0.5, 2, 'd', 11)) assert(parts[1][7] == (0.5, 2, 'd', 22))
def test_named_numpy_2(): c1 = named_parameter('c1', 0.5) x = named_parameter('x', numpy.array([1.0,2.0,3.0])) ischeme = Constants(c1) >> ISE(x) ischeme_content = list(namedtuple_adapter(IS(ischeme))) assert(len(ischeme_content) == 3) for entry, xval in zip(ischeme_content, [1.0,2.0,3.0]): assert(entry.c1 == 0.5) assert(entry.x == xval)
def test_namedtuple_adapter(): c1 = named_parameter('c1', 0.5) x = named_parameter('x', [1,2,3]) y = named_parameter('y', ['a','b','c']) ischeme = Constants(c1) >> ISE(x) >> ISE(y) ischeme_content = list(namedtuple_adapter(IS(ischeme.nested_variables))) assert(len(ischeme_content) == 9) for entry, xval, yval in zip(ischeme_content, [1,1,1,2,2,2,3,3,3], ['a','b','c']*3): assert(entry.c1 == 0.5) assert(entry.x == xval) assert(entry.y == yval)
def test_single_string_named(): c1 = named_parameter('c1', 'some_string') ischeme = Constants(c1) ischeme_content = list(IS(ischeme)) assert(len(ischeme_content) == 1) assert(ischeme_content[0] == ('some_string',))
def test_single_bool_named(): c1 = named_parameter('c1', False) ischeme = Constants(c1) ischeme_content = list(IS(ischeme)) assert(len(ischeme_content) == 1) assert(ischeme_content[0] == (False,))
def test_splitter(): c1 = named_parameter('c', 0.5) x = named_parameter('x', [1,2,3,4,5,6]) ischeme = Constants(c1) >> ISE(x).split(2) ischeme_parts = ischeme.nested_variables ischeme_content = [IS(part) for part in ischeme_parts] parts = [list(p) for p in ischeme_content] assert(len(parts) == 2) assert(len(parts[0]) == 3) assert(len(parts[1]) == 3) assert(parts[0][0] == (0.5, 1, )) assert(parts[0][1] == (0.5, 2, )) assert(parts[0][2] == (0.5, 3, )) assert(parts[1][0] == (0.5, 4, )) assert(parts[1][1] == (0.5, 5, )) assert(parts[1][2] == (0.5, 6, ))
def main(): temperature = named_parameter('t', 25.0) um = named_parameter('um', -13.0 * 10**(-3)) phase = named_parameter('phase', 'i') radius = named_parameter('radius', 25) upot = named_parameter('upot', numpy.arange(0.0, 10.0, 1.0)) shift = named_parameter('shift', '10') needprev = named_parameter('needprev', [False] + [True] * (len(upot) - 1)) ischeme_elements = Constants(temperature, um, phase, radius, shift) \ >> ISE(upot, needprev) ischeme = namedtuple_adapter(IS(ischeme_elements)) subs_history = [] compute_substitutions = partial(_compute_substitutions, subs_history) for values in ischeme: subs = compute_substitutions(values) sim_config = prepare_config('./sim.i') new_config = sim_config(subs) sim_filename = f"{subs['filebase']}.i" with open(sim_filename, 'w') as simfile: simfile.writelines(new_config) ferret_run = f'mpiexec -n 28 ferret-opt -i {sim_filename}' procresult = run(ferret_run, shell=True) if procresult.returncode != 0: exit(1)
def test_splitter_multiple(): c1 = named_parameter('c', 0.5) x = named_parameter('x', [1,2,3,4,5,6]) y = named_parameter('y', 'abcdef') ischeme = Constants(c1) >> ISE(x,y).split(2) ischeme_parts = ischeme.nested_variables ischeme_content = [IS(part) for part in ischeme_parts] parts = [list(p) for p in ischeme_content] assert(len(parts) == 2) assert(len(parts[0]) == 3) assert(len(parts[1]) == 3) assert(parts[0][0] == (0.5, 1, 'a',)) assert(parts[0][1] == (0.5, 2, 'b',)) assert(parts[0][2] == (0.5, 3, 'c',)) assert(parts[1][0] == (0.5, 4, 'd',)) assert(parts[1][1] == (0.5, 5, 'e',)) assert(parts[1][2] == (0.5, 6, 'f',))
def test_dict_adapter(): c1 = named_parameter('c1', 0.5) x = named_parameter('x', [1,2,3]) y = named_parameter('y', ['a','b','c']) ischeme = Constants(c1) >> ISE(x) >> ISE(y) ischeme_content = list(dict_adapter(IS(ischeme.nested_variables))) assert(len(ischeme_content) == 9) assert(ischeme_content[0] == dict(c1=0.5, x=1, y='a')) assert(ischeme_content[1] == dict(c1=0.5, x=1, y='b')) assert(ischeme_content[2] == dict(c1=0.5, x=1, y='c')) assert(ischeme_content[3] == dict(c1=0.5, x=2, y='a')) assert(ischeme_content[4] == dict(c1=0.5, x=2, y='b')) assert(ischeme_content[5] == dict(c1=0.5, x=2, y='c')) assert(ischeme_content[6] == dict(c1=0.5, x=3, y='a')) assert(ischeme_content[7] == dict(c1=0.5, x=3, y='b')) assert(ischeme_content[8] == dict(c1=0.5, x=3, y='c'))
def test_slice_numpy(): x = named_parameter('x', numpy.array([1,2,3,4,5,6])) sl1 = x[:3] sl2 = x[3:] assert(len(sl1) == 3) assert(len(sl2) == 3) assert(sl1[0] == 1) assert(sl1[1] == 2) assert(sl1[2] == 3) assert(sl2[0] == 4) assert(sl2[1] == 5) assert(sl2[2] == 6)
def test_splitter_noconstants(): x = named_parameter('x', [1,2,3,4,5,6]) ischeme = NoConstants() >> ISE(x).split(2) ischeme_parts = ischeme.nested_variables ischeme_content = [IS(part) for part in ischeme_parts] parts = [list(p) for p in ischeme_content] assert(len(parts) == 2) assert(len(parts[0]) == 3) assert(len(parts[1]) == 3) assert(parts[0][0] == (1, )) assert(parts[0][1] == (2, )) assert(parts[0][2] == (3, )) assert(parts[1][0] == (4, )) assert(parts[1][1] == (5, )) assert(parts[1][2] == (6, ))