Exemple #1
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)
Exemple #2
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)
Exemple #3
0
class TestProjectData(PyironTestCase):
    @classmethod
    def setUpClass(cls):
        cls.file_location = dirname(abspath(__file__)).replace("\\", "/")
        cls.project_name = join(cls.file_location, "test_project")

    @classmethod
    def tearDownClass(cls):
        try:
            remove(join(cls.file_location, "pyiron.log"))
        except FileNotFoundError:
            pass

    def setUp(self):
        self.project = Project(self.project_name)

    def tearDown(self):
        self.project.remove(enable=True)

    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)

    def test_iterjobs(self):

        try:
            for j in self.project.iter_jobs():
                pass
        except:
            self.fail(
                "Iterating over empty project should not raise exception.")

        try:
            for j in self.project.iter_jobs(status="finished"):
                pass
        except:
            self.fail(
                "Iterating over empty project with set status flag should not raise exception."
            )

    def test_create_job_name(self):
        self.assertEqual(self.project.create.job_name(['job', 0.1]), 'job_0d1')
        self.assertEqual(
            self.project.create.job_name(['job', 0.1],
                                         special_symbols={'.': 'c'}),
            'job_0c1')
        self.assertEqual(
            self.project.create.job_name(['job', 1.0000000000005]), 'job_1d0')
        self.assertEqual(
            self.project.create.job_name(['job', 1.0000000000005],
                                         ndigits=None), 'job_1d0000000000005')
Exemple #4
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)
class TestProjectData(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.file_location = dirname(abspath(__file__)).replace("\\", "/")
        cls.project_name = join(cls.file_location, "test_project")

    @classmethod
    def tearDownClass(cls):
        try:
            remove(join(cls.file_location, "pyiron.log"))
        except FileNotFoundError:
            pass

    def setUp(self):
        self.project = Project(self.project_name)

    def tearDown(self):
        self.project.remove(enable=True)

    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)

    def test_iterjobs(self):

        try:
            for j in self.project.iter_jobs():
                pass
        except:
            self.fail(
                "Iterating over empty project should not raise exception.")

        try:
            for j in self.project.iter_jobs(status="finished"):
                pass
        except:
            self.fail(
                "Iterating over empty project with set status flag should not raise exception."
            )
Exemple #6
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')
Exemple #7
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)
Exemple #8
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)
 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)
    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")
 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)
Exemple #12
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])
Exemple #13
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")
Exemple #14
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)
Exemple #15
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"))
 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)
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(os.path.join(cls.file_location, "master_copy"))
Exemple #18
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"))
 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()
Exemple #20
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)
Exemple #21
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
Exemple #22
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)
Exemple #23
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)
Exemple #24
0
from pyiron_base.master.list import ListMaster
from pyiron_base.master.parallel import ParallelMaster, JobGenerator
from pyiron_base.master.serial import SerialMasterBase
from pyiron_base.master.flexible import FlexibleMaster
from pyiron_base.project.generic import Project, Creator
from pyiron_base.pyio.parser import Logstatus, extract_data_from_file
from pyiron_base.server.queuestatus import validate_que_request
from pyiron_base.state.settings import Settings
from pyiron_base.state.install import install_dialog
from pyiron_base.table.datamining import PyironTable, TableJob
from pyiron_base.generic.object import HasDatabase, HasStorage, PyironObject
from pyiron_base.database.performance import get_database_statistics

from pyiron_base.toolkit import Toolkit, BaseTools

Project.register_tools("base", BaseTools)

# optional API of the pyiron_base module
try:
    from pyiron_base.project.gui import ProjectGUI
except (ImportError, TypeError, AttributeError):
    pass

# Internal init
from ._version import get_versions
from pyiron_base.generic.jedi import fix_ipython_autocomplete

# Set version of pyiron_base
__version__ = get_versions()["version"]
del get_versions
 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"))
Exemple #26
0
 def setUp(self):
     self.project = Project(self.project_name)
Exemple #27
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)
Exemple #28
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)
 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")