def test_no_run_information_loading(self): filename = make_temp_dir('testnoruninfo.hdf5') traj = Trajectory(name='TestDelete', filename=filename) length = 100000 traj.v_lazy_adding = True traj.par.x = 42 traj.f_explore({'x': range(length)}) traj.f_store() traj = load_trajectory(index=-1, filename=filename, with_run_information=False) self.assertEqual(len(traj), length) self.assertEqual(len(traj._run_information), 1)
# See: print('t=' + str(traj.t)) # What happens if our new parameter's name does not match the name passed to the constructor? traj.parameters.subgroup = Parameter('v', 2, comment='Fourth dimension') # Well, since 'subgroup' != 'v', 'subgroup' becomes just another group node created on the fly print(traj.parameters.subgroup) # This even works for already existing groups and with the well known *dot* notation: traj.parameters = Parameter('subgroup.subsubgroup.w', 2) # See print('w='+str(traj.par.subgroup.subsubgroup.w)) # There's a lazy version which does not require a constructor. # This can be turned on via traj.v_lazy_adding = True # And you can add a new parameter via traj.parameters.u = 1, 'Fourth dimension' print('u=' + str(traj.u)) # However, now you can no longer change values of existing parameters, # because this is interpreted as a new parameter addition, so this fails: try: traj.parameters.u = 2 print('I won`t be reached') except AttributeError as exc: print('Told you: `%s`' % repr(exc)) # See: print('u=' + str(traj.par.u)) # But disabling the new adding method makes this work again traj.v_lazy_adding = False
def test_new_assignment_method(self): filename = make_temp_dir('newassignment.hdf5') traj = Trajectory(filename=filename) traj.v_lazy_adding = True comment = 'A number' traj.par.x = 44, comment self.assertTrue(traj.f_get('x').v_comment == comment) traj.par.iamgroup = a_new_group self.assertTrue(isinstance(traj.iamgroup, ParameterGroup)) traj.v_lazy_adding = False traj.x = 45 self.assertTrue(traj.par.f_get('x').f_get() == 45) self.assertTrue(isinstance(traj.f_get('x'), Parameter)) traj.f = Parameter('lll', 444, 'lll') self.assertTrue(traj.f_get('f').v_name == 'f') traj.v_lazy_adding = True traj.res.k = 22, 'Hi' self.assertTrue(isinstance(traj.f_get('k'), Result)) self.assertTrue(traj.f_get('k')[1] == 'Hi') with self.assertRaises(AttributeError): traj.res.k = 33, 'adsd' conf = traj.conf with self.assertRaises(AttributeError): conf = traj.conf.jjjj traj.f_set_properties(fast_access=True) traj.crun = 43, 'JJJ' self.assertTrue(traj.run_A[0] == 43) with self.assertRaises(AttributeError): traj.f_set_properties(j=7) with self.assertRaises(AttributeError): traj.f_set_properties(depth=7) traj.hui = (('444', 'kkkk',), 'l') self.assertTrue(traj.f_get('hui')[1] == 'l') with self.assertRaises(AttributeError): traj.hui = ('445', 'kkkk',) traj.f_get('hui').f_set(('445', 'kkkk',)) self.assertTrue(traj.f_get('hui')[1] == 'l') self.assertTrue(traj.hui[0] == ('445', 'kkkk',)) traj.f_add_link('klkikju', traj.par) # for shizzle traj.meee = Result('h', 43, hui = 3213, comment='du') self.assertTrue(traj.meee.h.h == 43) with self.assertRaises(TypeError): traj.par.mu = NNGroupNode('jj', comment='mi') with self.assertRaises(TypeError): traj.res.mu = NNGroupNode('jj', comment='mi') with self.assertRaises(TypeError): traj.conf.mu = NNGroupNode('jj', comment='mi') with self.assertRaises(TypeError): traj.dpar.mu = NNGroupNode('jj', comment='mi') with self.assertRaises(TypeError): traj.par.mu = ResultGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.dpar.mu = ResultGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.conf.mu = ResultGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.mu = ResultGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.par.mu = ConfigGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.dpar.mu = ConfigGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.res.mu = ConfigGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.mu = ConfigGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.par.mu = DerivedParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.conf.mu = DerivedParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.res.mu = DerivedParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.mu = DerivedParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.dpar.mu = ParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.res.mu = ParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.conf.mu = ParameterGroup('jj', comment='mi') with self.assertRaises(TypeError): traj.mu = ParameterGroup('jj', comment='mi') traj.par.mu = ParameterGroup('jj', comment='mi') traj.res.mus = ResultGroup('jj', comment='mi') traj.mu = NNGroupNode('jj') cg = ConfigGroup('a.g') traj.conf.a = cg self.assertTrue(traj.f_get('conf.a.a.g', shortcuts=False) is cg) dg = DerivedParameterGroup('ttt') traj.dpar.ttt = dg self.assertTrue(traj.f_get('dpar.ttt', shortcuts=False) is dg) traj.mylink = traj.par self.assertTrue(traj.mylink is traj.par) traj.vvv = NNGroupNode('', comment='kkk') self.assertTrue(traj.vvv.v_full_name == 'vvv') self.assertTrue(traj.par.mu.v_name == 'mu') traj.rrr = MyParamGroup('ff') traj.par.g = MyParamGroup('') pg = traj.f_add_parameter_group(comment='gg', full_name='me') self.assertTrue(traj.par.me is pg) traj.f_store() traj = load_trajectory(index=-1, filename=filename, dynamic_imports=MyParamGroup) self.assertTrue(isinstance(traj.rrr, NNGroupNode)) self.assertTrue(isinstance(traj.rrr.ff, MyParamGroup)) self.assertTrue(isinstance(traj.par.g, MyParamGroup)) traj.par = Parameter('hiho', 42, comment='you') traj.par = Parameter('g1.g2.g3.g4.g5', 43) self.assertTrue(traj.hiho == 42) self.assertTrue(isinstance(traj.par.g1, ParameterGroup )) self.assertTrue(isinstance(traj.par.g3, ParameterGroup )) self.assertTrue(traj.g3.g5 == 43)