Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into server_remove_hdf
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Mar 19, 2024
2 parents 4202582 + 0efd4e5 commit 23ed58a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .ci_support/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ dependencies:
- pytables =3.9.2
- sqlalchemy =2.0.28
- tqdm =4.66.2
- traitlets =5.14.1
- traitlets =5.14.2
2 changes: 1 addition & 1 deletion .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dependencies:
- pytables =3.9.2
- sqlalchemy =2.0.28
- tqdm =4.66.2
- traitlets =5.14.1
- traitlets =5.14.2
25 changes: 14 additions & 11 deletions pyiron_base/database/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def _item_update(self, par_dict, item_id):
else:
raise PermissionError("Not avilable in viewer mode.")

def delete_item(self, item_id):
def delete_item(self, item_id: int):
"""
Delete Item from database
Expand All @@ -749,18 +749,21 @@ def delete_item(self, item_id):
Returns:
"""
if not self._view_mode:
self.conn.execute(
self.simulation_table.delete().where(
self.simulation_table.c["id"] == int(item_id)
)
)
self.conn.commit()
if not self._keep_connection:
self.conn.close()
else:
if self._view_mode:
raise PermissionError("Not avilable in viewer mode.")

res = self.conn.execute(
self.simulation_table.delete().where(
self.simulation_table.c["id"] == int(item_id)
)
)
if res.rowcount == 0:
raise RuntimeError(f"Failed to delete job ({item_id}) from database!")
self.conn.commit()

if not self._keep_connection:
self.conn.close()

# IsDatabase impl'
def _get_jobs(self, sql_query, user, project_path, recursive=True, columns=None):
df = self.job_table(
Expand Down
13 changes: 7 additions & 6 deletions pyiron_base/jobs/datamining.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,13 @@ def update_table(self, job_status_list=None):
if self._executor_type is None and self.server.cores > 1:
self._executor_type = "pympipool.mpi.executor.PyMPIExecutor"
if self._executor_type is not None:
self._pyiron_table.create_table(
file=hdf5_input,
job_status_list=job_status_list,
enforce_update=self._enforce_update,
executor=self._get_executor(max_workers=self.server.cores),
)
with self._get_executor(max_workers=self.server.cores) as exe:
self._pyiron_table.create_table(
file=hdf5_input,
job_status_list=job_status_list,
enforce_update=self._enforce_update,
executor=exe,
)
else:
self._pyiron_table.create_table(
file=hdf5_input,
Expand Down
5 changes: 2 additions & 3 deletions pyiron_base/jobs/flex/pythonfunctioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ def run_static(self):
):
input_dict = self.input.to_builtin()
del input_dict["executor"]
output = self._function(
**input_dict, executor=self._get_executor(max_workers=self.server.cores)
)
with self._get_executor(max_workers=self.server.cores) as exe:
output = self._function(**input_dict, executor=exe)
else:
output = self._function(**self.input.to_builtin())
self.output.update({"result": output})
Expand Down
9 changes: 9 additions & 0 deletions pyiron_base/jobs/job/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import datetime
from inspect import isclass
import os
import platform
import posixpath
import warnings

Expand Down Expand Up @@ -1534,6 +1535,14 @@ def _get_executor(self, max_workers=None):
raise ValueError(
"No executor type defined - Please set self.executor_type."
)
elif (
self._executor_type == "pympipool.mpi.executor.PyMPIExecutor"
and platform.system() == "Darwin"
):
# The Mac firewall might prevent connections based on the network address - especially Github CI
return import_class(self._executor_type)(
max_workers=max_workers, hostname_localhost=True
)
elif isinstance(self._executor_type, str):
return import_class(self._executor_type)(max_workers=max_workers)
else:
Expand Down
2 changes: 1 addition & 1 deletion pyiron_base/project/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ def _remove_jobs_helper(self, recursive=False, progress=True):
self.remove_job(job_specifier=job_id)
state.logger.debug("Remove job with ID {0} ".format(job_id))
except (IndexError, Exception):
state.logger.debug("Could not remove job with ID {0} ".format(job_id))
state.logger.warning("Could not remove job with ID {0} ".format(job_id))

def _remove_files(self, pattern="*"):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
"sqlalchemy==2.0.28",
"tables==3.9.2",
"tqdm==4.66.2",
"traitlets==5.14.1",
"traitlets==5.14.2",
]
dynamic = ["version"]

Expand Down
5 changes: 4 additions & 1 deletion tests/database/test_database_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ def test_delete_item(self):
self.database.delete_item(key)
self.assertRaises(
Exception, self.database.delete_item, [key]
) # use only str or int
) # call function with unsupported list as argument
self.assertRaises(
RuntimeError, self.database.delete_item, 123456789
) # remove non existent job id
# self.assertRaises(Exception, self.database.get_item_by_id, key) # ensure item does not exist anymore

def test_get_item_by_id(self):
Expand Down

0 comments on commit 23ed58a

Please sign in to comment.