Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirements By Job Type And BatchSystem.submit #489

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

TimothyWillard
Copy link
Contributor

Describe your changes.

This pull request:

  • Adds internal _job_resources_from_size_and_inference to give a default JobResources from JobSize and inference method name*,
  • Adds abstract method BatchSystem.submit to submit jobs to a batch system which can return a JobSubmission which is a thin extension of subprocess.CompletedProcess with a job_id attribute,
  • Implemented submit for LocalBatchSystem and SlurmBatchSystem,
  • Adds _format_cli_options to gempyor.utils for formatting CLI arguments,
  • Adds a light testing utility sample_script.

*There were discussions of creating a JobType ABC and have EMCEE and legacy implement this and then add this method to that (similar to BatchSystem). I decided against this to 1) develop the MVP faster, and 2) I think this method would have to be added to both the simulator and inference ABCs (see GH-402 & GH-432 respectively), because the inference method would have to call the simulator one and use that result in it's own calculation.

Does this pull request make any user interface changes? If so please describe.

The user interface changes are some API changes to gempyor.batch which have been documented in docstrings, has not been documented in GitBook yet. I think documenting there is more appropriate once further along in the product.

What does your pull request address? Tag relevant issues.

This pull request addresses GH-487, spun out of GH-394. After this PR will be actually creating the flepimop submit CLI action using all of this infrastructure.

Added `_job_resources_from_size_and_inference` to calculate job
resources from job size and inference type along with corresponding docs
and tests. This is a temporary solution since a method like this should
be added to GH-402/GH-432 rather than hard coded in `gempyor.batch`.
Simpler to do this way for MVP's sake rather than trying to abstract
code in a way that won't be reusable in the future.
Added `gempyor.utils._format_cli_options` for formatting CLI options in
calls to executables via `subprocess.run` and similar.
Added `gempyor.testing.sample_script` utility for creating an executable
(or optionally non-executable) script for unit tests that need to call
out to some command.
* Added an abstract method to `BatchSystem` for `submit` which submits a
  job.
* Implemented said method for `SlurmBatchSystem` and `LocalBatchSystem`.
* Added `JobSubmission` class to represent result of job submission with
  a job id.
* Corresponding docs and unit tests.
['-o=/path/to/output.log']
>>> _format_cli_options({"opt1": "```", "opt2": "$( echo 'Hello!')"})
["--opt1='```'", '--opt2=\'$( echo \'"\'"\'Hello!\'"\'"\')\'']
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this handle {"opt1": ["foo", "bar", "fizz", "buzz"]}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a60ddce.

@@ -319,6 +487,77 @@ class LocalBatchSystem(BatchSystem):

name = "local"

def submit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels and the next concrete implementation feels a bit copy-pasta. are there elements of these that should be pulled into the parent class, and then called in these with, say, super().log(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ea1c864.

@@ -159,6 +164,123 @@ class JobSize(BaseModel):
blocks: PositiveInt


def _job_resources_from_size_and_inference(
job_size: JobSize,
inference: Literal["emcee"] | None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda think I'd prefer this as inference: Literal["emcee", "r"] = "emcee" and then error on an argument it doesn't understand

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Carl on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f7c99e6.

Change the `inference` arg from `Literal["emcee"] | None` to
`Literal["emcee", "r"]` to reflect that the absense of inference method
refers to "r" inference.
Changed `_format_cli_options` to either take a string or an iterable of
strings as values. Previously had accepted any value, but only accepting
string(s) makes it the responsibility of the caller to format objects to
a string(s). Added an option to configure iterable formatting as well.
@TimothyWillard TimothyWillard added gempyor Concerns the Python core. batch Relating to batch processing. high priority High priority. next release Marks a PR as a target to include in the next release. labels Feb 3, 2025
Consolidated `LocalBatchSystem.submit` and `SlurmBatchSystem.submit`
into `_submit_via_subprocess` internal helper to deduplicate code.
Added extensive unit tests for `gempyor.batch._submit_via_subprocess`
internal utility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
batch Relating to batch processing. gempyor Concerns the Python core. high priority High priority. next release Marks a PR as a target to include in the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request]: flepimop submit Action For Submitting Calibration Jobs To HPC Environments
4 participants