Skip to content

Commit

Permalink
Merge branch 'main' into reintroduce_flux
Browse files Browse the repository at this point in the history
  • Loading branch information
liamhuber committed Jun 19, 2023
2 parents 2cb984b + d4495db commit 01c5eb9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 82 deletions.
1 change: 0 additions & 1 deletion pyiron_base/jobs/job/extension/server/runmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"thread",
"worker",
"srun",
"flux",
"interactive",
"interactive_non_modal",
]
Expand Down
16 changes: 3 additions & 13 deletions pyiron_base/jobs/job/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def __init__(self, project, job_name):
self._compress_by_default = False
self._python_only_job = False
self._write_work_dir_warnings = True
self._flux_executor = None
self.interactive_cache = None
self.error = GenericError(job=self)

Expand Down Expand Up @@ -210,15 +209,6 @@ def executable(self, exe):
self._executable_activate()
self._executable.executable_path = exe

@property
def flux_executor(self):
return self._flux_executor

@flux_executor.setter
def flux_executor(self, exe):
self.server.run_mode.flux = True
self._flux_executor = exe

@property
def server(self):
"""
Expand Down Expand Up @@ -700,9 +690,9 @@ def run(
if repair and self.job_id and not self.status.finished:
self._run_if_repair()
elif status == "initialized":
return self._run_if_new(debug=debug)
self._run_if_new(debug=debug)
elif status == "created":
return self._run_if_created()
self._run_if_created()
elif status == "submitted":
run_job_with_status_submitted(job=self)
elif status == "running":
Expand Down Expand Up @@ -1201,7 +1191,7 @@ def _run_if_new(self, debug=False):
Args:
debug (bool): Debug Mode
"""
return run_job_with_status_initialized(job=self, debug=debug)
run_job_with_status_initialized(job=self, debug=debug)

def _run_if_created(self):
"""
Expand Down
69 changes: 1 addition & 68 deletions pyiron_base/jobs/job/runfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@
import posixpath
import subprocess

from jinja2 import Template

from pyiron_base.utils.deprecate import deprecate
from pyiron_base.jobs.job.wrapper import JobWrapper
from pyiron_base.state import state

try:
import flux.job

flux_available = True
except ImportError:
flux_available = False


"""
The function job.run() inside pyiron is executed differently depending on the status of the job object. This module
Expand Down Expand Up @@ -48,7 +39,6 @@
interactive_non_modal: run_job_with_runmode_interactive_non_modal
queue: run_job_with_runmode_queue
srun: run_job_with_runmode_srun
flux: run_job_with_runmode_flux
thread: only affects children of a GenericMaster
worker: only affects children of a GenericMaster
Expand Down Expand Up @@ -86,7 +76,7 @@ def run_job_with_status_initialized(job, debug=False):
print("job exists already and therefore was not created!")
else:
job.save()
return job.run()
job.run()


def run_job_with_status_created(job):
Expand All @@ -112,16 +102,6 @@ def run_job_with_status_created(job):
job.run_static()
elif job.server.run_mode.srun:
run_job_with_runmode_srun(job=job)
elif job.server.run_mode.flux:
if job.server.gpus is not None:
gpus_per_slot = int(job.server.gpus / job.server.cores)
else:
gpus_per_slot = None
return run_job_with_runmode_flux(
job=job,
executor=job.flux_executor,
gpus_per_slot=gpus_per_slot,
)
elif (
job.server.run_mode.non_modal
or job.server.run_mode.thread
Expand Down Expand Up @@ -451,53 +431,6 @@ def run_job_with_runmode_srun(job):
)


def run_job_with_runmode_flux(job, executor, gpus_per_slot=None):
if not flux_available:
raise ModuleNotFoundError(
"No module named 'flux'. Running in flux mode is only available on Linux;"
"For CPU jobs, please use `conda install -c conda-forge flux-core`; for "
"GPU support you will additionally need "
"`conda install -c conda-forge flux-sched libhwloc=*=cuda*`"
)
if not state.database.database_is_disabled:
executable_template = Template(
"""\
#!/bin/bash
python -m pyiron_base.cli wrapper -p {{working_directory}} -j {{job_id}}
"""
)
exeuctable_str = executable_template.render(
working_directory=job.working_directory,
job_id=str(job.job_id),
)
job_name = "pi_" + str(job.job_id)
else:
executable_template = Template(
"""\
#!/bin/bash
python -m pyiron_base.cli wrapper -p {{working_directory}} -f {{file_name}}{{h5_path}}
"""
)
exeuctable_str = executable_template.render(
working_directory=job.working_directory,
file_name=job.project_hdf5.file_name,
h5_path=job.project_hdf5.h5_path,
)
job_name = "pi_" + job.job_name

jobspec = flux.job.JobspecV1.from_batch_command(
jobname=job_name,
script=exeuctable_str,
num_nodes=1,
cores_per_slot=1,
gpus_per_slot=gpus_per_slot,
num_slots=job.server.cores,
)
jobspec.cwd = job.project_hdf5.working_directory
jobspec.environment = dict(os.environ)
return executor.submit(jobspec)


def run_time_decorator(func):
def wrapper(job):
if not state.database.database_is_disabled and job.job_id is not None:
Expand Down

0 comments on commit 01c5eb9

Please sign in to comment.