Exemple #1
0
    def compare_trajectories(self,traj1,traj2):

        trajlength = len(traj1)

        if traj1.f_get_run_information(0)['completed']:

            # We need this fix in case the trajectory was never run
            # thus it does not contain any run groups but still has a length
            if 'results.runs' in traj1:
                rungroups = traj1.results.runs.f_children()
            else:
                rungroups = 1

            self.assertEqual(trajlength, rungroups, 'len of traj1 is %d, rungroups %d' % (trajlength, rungroups))

        old_items = to_dict_wo_config(traj1)
        new_items = to_dict_wo_config(traj2)

        self.assertEqual(len(traj1),len(traj2), 'Length unequal %d != %d.' % (len(traj1), len(traj2)))

        self.assertEqual(len(old_items),len(new_items))
        for key,item in new_items.items():
            old_item = old_items[key]

            if isinstance(item, BaseParameter):
                self.assertTrue(parameters_equal(item,old_item),
                                'For key %s: %s not equal to %s' % (key,str(old_item),str(item)))
            elif isinstance(item,BaseResult):
                self.assertTrue(results_equal(item, old_item),
                                'For key %s: %s not equal to %s' % (key, str(old_item),str(item)))
            else:
                raise RuntimeError('You shall not pass')


            self.assertTrue(str(item.v_annotations)==str(old_item.v_annotations),'%s != %s' %
                        (item.v_annotations.f_ann_to_str(),old_item.v_annotations.f_ann_to_str()))

        # Check the annotations
        for node in traj1.f_iter_nodes(recursive=True):

            if node.v_run_branch == traj1.f_wildcard('$', 0) or node.v_run_branch == 'trajectory':
                if node.v_comment != '' and node.v_full_name in traj2:
                    second_comment = traj2.f_get(node.v_full_name).v_comment
                    self.assertEqual(node.v_comment, second_comment, '%s != %s, for %s' %
                                                (node.v_comment, second_comment, node.v_full_name))

            if not node.v_annotations.f_is_empty():
                second_anns = traj2.f_get(node.v_full_name).v_annotations
                self.assertTrue(str(node.v_annotations) == str(second_anns))
Exemple #2
0
    def test_storing_and_loading_groups(self):
        filename = make_temp_dir('grpgrp.hdf5')
        traj = Trajectory(name='traj', add_time=True, filename=filename)
        res=traj.f_add_result('aaa.bbb.ccc.iii', 42, 43, comment=7777 * '6')
        traj.ccc.v_annotations['gg']=4
        res=traj.f_add_result('aaa.ddd.eee.jjj', 42, 43, comment=777 * '6')
        traj.ccc.v_annotations['j'] = 'osajdsojds'
        traj.f_store(only_init=True)
        traj.f_store_item('aaa', recursive=True)
        newtraj = load_trajectory(traj.v_name, filename=filename, load_all=2)

        self.compare_trajectories(traj, newtraj)

        traj.iii.f_set(55)

        self.assertFalse(results_equal(traj.iii, newtraj.iii))

        traj.aaa.f_store(recursive=True, store_data=3)

        newtraj.bbb.f_load(recursive=True, load_data=3)

        self.compare_trajectories(traj, newtraj)

        traj.ccc.v_annotations['gg'] = 5
        traj.f_load(load_data=3)
        self.assertTrue(traj.ccc.v_annotations['gg'] == 4)
        traj.ccc.v_annotations['gg'] = 5
        traj.f_store(store_data=3)
        newtraj.f_load(load_data=2)
        self.assertTrue(newtraj.ccc.v_annotations['gg'] == 4)
        newtraj.f_load(load_data=3)
        self.assertTrue(newtraj.ccc.v_annotations['gg'] == 5)

        traj.ccc.f_add_link('link', res)
        traj.f_store_item(traj.ccc, store_data=3, with_links=False)

        newtraj.f_load(load_data=3)
        self.assertTrue('link' not in newtraj.ccc)

        traj.f_store_item(traj.ccc, store_data=3, with_links=True, recursive=True)

        newtraj.f_load_item(newtraj.ccc, with_links=False, recursive=True)
        self.assertTrue('link' not in newtraj.ccc)

        newtraj.f_load_item(newtraj.ccc, recursive=True)
        self.assertTrue('link' in newtraj.ccc)
Exemple #3
0
    def compare_trajectories(self,traj1,traj2):

        trajlength = len(traj1)

        if 'results.runs' in traj1:
            rungroups = traj1.results.runs.f_children()
        else:
            rungroups = 1

        self.assertEqual(trajlength, rungroups, 'len of traj1 is %d, rungroups %d' % (trajlength, rungroups))

        old_items = to_dict_wo_config(traj1)
        new_items = to_dict_wo_config(traj2)

        self.assertEqual(len(traj1),len(traj2), 'Length unequal %d != %d.' % (len(traj1), len(traj2)))

        self.assertEqual(len(old_items),len(new_items))
        for key,item in new_items.items():
            old_item = old_items[key]

            if isinstance(item, BaseParameter):
                self.assertTrue(parameters_equal(item,old_item),
                                'For key %s: %s not equal to %s' %(key,str(old_item),str(item)))
            elif isinstance(item,BaseResult):
                self.assertTrue(results_equal(item, old_item),
                                'For key %s: %s not equal to %s' %(key,str(old_item),str(item)))
            else:
                raise RuntimeError('You shall not pass')


            self.assertTrue(str(item.v_annotations)==str(old_item.v_annotations),'%s != %s' %
                        (item.v_annotations.f_ann_to_str(),old_item.v_annotations.f_ann_to_str()))

        # Check the annotations
        for node in traj1.f_iter_nodes(recursive=True):

            if (not 'run' in node.v_full_name) or 'run_00000000' in node.v_full_name:
                if node.v_comment != '' and node.v_full_name in traj2:
                    second_comment = traj2.f_get(node.v_full_name).v_comment
                    self.assertEqual(node.v_comment, second_comment, '%s != %s, for %s' %
                                                                     (node.v_comment, second_comment, node.v_full_name))

            if not node.v_annotations.f_is_empty():
                second_anns = traj2.f_get(node.v_full_name).v_annotations
                self.assertTrue(str(node.v_annotations) == str(second_anns))