Exemplo n.º 1
0
 def tearDownClass(cls):
     file_location = os.path.dirname(os.path.abspath(__file__))
     project = Project(os.path.join(file_location, "testing_copyto"))
     sub_project = project.open("sub_project_ex")
     sub_project.remove(enable=True)
     sub_project = project.open("sub_project")
     sub_project.remove(enable=True)
Exemplo n.º 2
0
def main(args):
    with h5py.File(args.input_path, mode="r") as f:
        job_name = list(f.keys())[0]
    project_path = os.path.join(os.path.abspath("."), job_name + ".h5")
    shutil.copy(args.input_path, project_path)

    file = os.path.basename(project_path)
    job_name = os.path.splitext(file)[0]

    db_project_path = s.top_path(project_path)
    project = os.path.dirname(project_path)
    db_project = (project + "/").replace(db_project_path, "")
    job_reload = Project(project).load_from_jobpath(
        job_id=None,
        db_entry={
            "id": 1000,
            "status": "",
            "chemicalformula": "",
            "job": job_name,
            "subjob": "/" + job_name,
            "projectpath": db_project_path,
            "project": db_project,
            "hamilton": "",
            "hamversion": "",
            "parentid": None,
            "masterid": None,
        },
        convert_to_object=True,
    )
    job_reload.status.initialized = True
    job_reload.server.run_mode.modal = True
    job_reload.run()
    shutil.copy(project_path, args.output_path)
Exemplo n.º 3
0
 def tearDownClass(cls):
     project = Project(
         os.path.join(os.path.dirname(os.path.abspath(__file__)), "hdf5_content")
     )
     ham = project.load(project.get_job_ids()[0])
     ham.remove()
     project.remove(enable=True)
Exemplo n.º 4
0
 def setUpClass(cls):
     super().setUpClass()
     job = cls.project.create_job(ToyJob, 'testjob')
     job.run()
     hdf = cls.project.create_hdf(cls.project.path, 'test_hdf.h5')
     hdf['key'] = 'value'
     Project(cls.project.path + 'sub')
     with open(cls.project.path+'text.txt', 'w') as f:
         f.write('some text')
Exemplo n.º 5
0
    def create_project_from_hdf5(self):
        """
        Internal function to create a pyiron project pointing to the directory where the HDF5 file is located.

        Returns:
            Project: pyiron project object
        """
        from pyiron_base.project.generic import Project

        return Project(path=self.file_path)
Exemplo n.º 6
0
    def test_data(self):
        self.assertRaises(KeyError, self.project.data.read)

        self.project.data.foo = "foo"
        self.project.data.write()
        self.project.data.read()
        self.assertEqual(1, len(self.project.data))

        project2 = Project(self.project_name)
        self.assertEqual(1, len(project2.data))
        self.assertEqual(self.project.data.foo, project2.data.foo)
Exemplo n.º 7
0
    def __init__(
        self,
        working_directory,
        job_id=None,
        hdf5_file=None,
        h5_path=None,
        submit_on_remote=False,
        debug=False,
        connection_string=None,
    ):
        self.working_directory = working_directory
        self._remote_flag = submit_on_remote
        if connection_string is not None:
            state.database.open_local_sqlite_connection(
                connection_string=connection_string)
        pr = Project(path=os.path.join(working_directory, "..", ".."))
        if job_id is not None:
            self.job = pr.load(int(job_id))
        else:
            projectpath = state.database.top_path(hdf5_file)
            if projectpath is None:
                project = os.path.dirname(hdf5_file)
            else:
                project = os.path.relpath(os.path.dirname(hdf5_file),
                                          projectpath)
            job_name = h5_path[1:]
            self.job = pr.load_from_jobpath(
                job_id=None,
                db_entry={
                    "job":
                    job_name,
                    "subjob":
                    h5_path,
                    "projectpath":
                    projectpath,
                    "project":
                    project + "/",
                    "status":
                    get_job_status_from_file(hdf5_file=hdf5_file,
                                             job_name=job_name),
                    "hamilton":
                    get_hamilton_from_file(hdf5_file=hdf5_file,
                                           job_name=job_name),
                    "hamversion":
                    get_hamilton_version_from_file(hdf5_file=hdf5_file,
                                                   job_name=job_name),
                },
                convert_to_object=True,
            )

        # setup logger
        self._logger = self.setup_logger(debug=debug)
Exemplo n.º 8
0
    def setUpClass(cls):
        cls.pl = InputList([{
            "foo": "bar"
        }, 2, 42, {
            "next": [0, {
                "depth": 23
            }]
        }],
                           table_name="input")
        cls.pl["tail"] = InputList([2, 4, 8])

        file_location = os.path.dirname(os.path.abspath(__file__))
        pr = Project(file_location)
        cls.file_name = os.path.join(file_location, "input.h5")
        cls.hdf = ProjectHDFio(project=pr,
                               file_name=cls.file_name,
                               h5_path="/test",
                               mode="a")
Exemplo n.º 9
0
 def test_hdf(self):
     pr = Project(self.file_location)
     file_name = os.path.join(self.file_location, "genericpara.h5")
     hdf = ProjectHDFio(project=pr,
                        file_name=file_name,
                        h5_path="/test",
                        mode="a")
     hdf.create_group("test")
     self.generic_parameters_str.to_hdf(hdf=hdf, group_name="input")
     gp_reload = GenericParameters(table_name="str")
     gp_reload.from_hdf(hdf=hdf, group_name="input")
     self.assertEqual(gp_reload.get("par___1"), 1)
     self.assertEqual(gp_reload.get("par_2"), "all")
     self.assertEqual(gp_reload.get("count"), 0)
     self.assertTrue(gp_reload.get("write_restart"))
     self.assertFalse(gp_reload.get("read_restart"))
     self.assertEqual(gp_reload.get("dict"), {"a": 1, "b": 2})
     self.assertEqual(gp_reload.get("list"), [1, "s"])
     os.remove(file_name)
Exemplo n.º 10
0
    def __init__(self, job_path):
        job_path_lst = job_path.replace("\\", "/").split(".h5")
        if len(job_path_lst) != 2:
            raise ValueError

        sub_job = job_path_lst[1]
        h5_path = None
        if sub_job is not None:
            if len(sub_job.strip()) > 0:
                h5_path = "/".join(sub_job.split("/")[:-1])

        hdf_project = ProjectHDFio(
            project=Project(os.path.dirname(job_path_lst[0])),
            file_name=job_path_lst[0].split("/")[-1] + ".h5",
            h5_path=h5_path,
            mode="r",
        )
        super(JobPathBase,
              self).__init__(project=hdf_project,
                             job_name=job_path_lst[1].split("/")[-1])
Exemplo n.º 11
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(os.path.join(cls.file_location,
                                        "random_testing"))
     cls.ham = cls.project.create_job('ScriptJob', "job_test_run")
Exemplo n.º 12
0
 def setUpClass(cls):
     super().setUpClass()
     print("TestWithProject: Setting up test project")
     cls.project_path = getfile(cls)[:-3].replace("\\", "/")
     cls.file_location, cls.project_name = os.path.split(cls.project_path)
     cls.project = Project(cls.project_path)
Exemplo n.º 13
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(os.path.join(cls.file_location, "testing_copyto"))
Exemplo n.º 14
0
 def tearDownClass(cls):
     file_location = os.path.dirname(os.path.abspath(__file__))
     project = Project(os.path.join(file_location, "master_copy"))
     project.remove(enforce=True, enable=True)
Exemplo n.º 15
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(os.path.join(cls.file_location, "master_copy"))
Exemplo n.º 16
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__)).replace(
         "\\", "/"
     )
     cls.project = Project(os.path.join(cls.file_location, "test_interactive"))
Exemplo n.º 17
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(os.path.join(cls.file_location, "jobs_testing"))
     cls.master = cls.project.create_job(TestMaster, "master")
     cls.master.ref_job = cls.project.create_job(
         cls.project.job_type.ScriptJob, "ref")
Exemplo n.º 18
0
 def tearDownClass(cls):
     file_location = os.path.dirname(os.path.abspath(__file__))
     project = Project(os.path.join(file_location, "testing_childids"))
     project.remove_jobs(recursive=True, silently=True)
     project.remove(enable=True)
Exemplo n.º 19
0
 def setUp(self):
     self.project = Project(self.project_name)
     self.data = ProjectData(project=self.project, table_name="data")
     self.data.foo = "foo"
     self.data.bar = 42
Exemplo n.º 20
0
 def setUpClass(cls):
     cls.project_path = getfile(cls)[:-3].replace("\\", "/")
     cls.file_location, cls.project_name = split(cls.project_path)
     cls.project = Project(cls.project_path)
Exemplo n.º 21
0
 def setUpClass(cls):
     cls.current_dir = os.path.dirname(os.path.abspath(__file__)).replace(
         "\\", "/")
     cls.project = Project(os.path.join(cls.current_dir, "sub_folder"))
Exemplo n.º 22
0
 def setUp(self):
     self.project = Project(self.project_name)
Exemplo n.º 23
0
 def tearDownClass(cls):
     file_location = os.path.dirname(os.path.abspath(__file__))
     project = Project(os.path.join(file_location, "jobs_testing"))
     project.remove(enforce=True)
Exemplo n.º 24
0
 def test_load_file_ProjectHDF(self):
     pr = Project(self.current_dir + '/test_pr')
     pr_hdf = load_file(self.current_dir + '/test_data.h5', project=pr)
     self.assertIsInstance(pr_hdf, ProjectHDFio)
     self.assertEqual(pr_hdf['content/key'], 'value')
     pr.remove(enable=True)
Exemplo n.º 25
0
 def tearDownClass(cls):
     file_location = os.path.dirname(os.path.abspath(__file__))
     project = Project(os.path.join(file_location, "test_genericjob"))
     project.remove(enable=True)
Exemplo n.º 26
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(os.path.join(cls.file_location, "hdf5_content"))
     cls.ham = cls.project.create_job('ScriptJob', "job_test_run")
     cls.ham.save()