-
Notifications
You must be signed in to change notification settings - Fork 20
CLI tool #162
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
Merged
Merged
CLI tool #162
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
e816ff6
Initial cli for psij
wilke 8687ca5
Merge remote-tracking branch 'origin/main' into wilke/command-line-tool
wilke bc49a6c
Initial readme
wilke 792d7ef
Changed file name
wilke b599da2
Added desription
wilke 85d36ec
Minor update
wilke f206338
Initial readme for serializing jobs
wilke e9a75f0
Initial readme for serializing jobs
wilke cd2bb4b
Initial hello world example script
wilke 2860e52
Initial import export example script
wilke ff38224
Deleted
wilke 4ab6a44
Added example code snippets
wilke c98562b
Added import statement
wilke 64f881d
Changed import statement
wilke 009cb69
Added Serialize module and Export Import class
wilke fe167b7
Updated import statements
wilke dd72160
Updated import statement
wilke c89a6b4
Updated import statement
wilke 223a289
Reading requirements file
wilke 118d76e
Added check for none value
wilke 639057c
Bugfix pass jobspec not job, fixed name collision
wilke 595b9a8
Removed print statemenet
wilke 2a26211
Resolved merge conflict
wilke 0d089e7
Added input type to argparse
wilke dc5e9e3
Bugfix
wilke dcd06d5
Removed duplicate line
wilke ebba7e1
Removed spaces
wilke 47003fc
Removed comment
wilke 05bcdd0
Changed layout
wilke 45352cb
Changed command line option for job-executor to required
wilke f8fbd21
Changed to require verbose option to print progress
wilke 6f6750d
Fixes #163, added exeception handling
wilke 9294b4f
Fixes #164, changed command line option, job executor is a positional…
wilke 1d23603
Renamed file
wilke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Scripts | ||
|
|
||
| This directory contains examples, helper scripts and the console for PSIJ. | ||
|
|
||
| ## psij-console | ||
|
|
||
| The console takes an exported JobSpec document and either validates or executes it. | ||
|
|
||
|
|
||
| ``` | ||
| usage: psij-consol [-h] [-v] [--debug] {validate,run} ... | ||
| positional arguments: | ||
| {validate,run} Subcommands | ||
| validate validate JobSpec file | ||
| run execute JobSpec file | ||
| optional arguments: | ||
| -h, --help show this help message and exit | ||
| -v, --verbose print detailed information | ||
| --debug print debug information | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Job import and export | ||
|
|
||
| This example is in Python and based on the hello world example from the Quick-Start guide. | ||
|
|
||
| Code snippet for exporting a JobSpec as json: | ||
| ``` | ||
| from psij import Export | ||
|
|
||
| e = Export() | ||
| ... | ||
| job = make_job() | ||
| e.export(obj=job.spec , dest="jobSpec.json") | ||
| ``` | ||
|
|
||
| The command line example below shows how to run and submit an exported job 10 times using slurm. | ||
| ``` | ||
| python ./psij-consol.py run --job-executor slurm --number-of-jobs 10 jobSpec.json | ||
| ``` | ||
|
|
||
| In addition a job can be imported and submitted using the import functionality of PSIJ: | ||
| ``` | ||
| from psij import Import | ||
| i = Import() | ||
| job = psij.Job() | ||
| spec = i.load(src="jobSpec.json") | ||
| job.spec = spec | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import psij | ||
|
|
||
| jex = psij.JobExecutor.get_instance('slurm') | ||
|
|
||
| N=2 # number of jobs to run | ||
|
|
||
| def make_job(i): | ||
| job = psij.Job() | ||
| spec = psij.JobSpec() | ||
| spec.executable = 'echo' | ||
| spec.arguments = ['I am number ' , i , ">>" , "hello.txt"] | ||
| spec.stdout_path = 'hello.' + str(i) + '.stdout' | ||
| job.spec = spec | ||
| return job | ||
|
|
||
| jobs = [] | ||
| for i in range(N): | ||
| job = make_job(i) | ||
| jobs.append(job) | ||
| jex.submit(job) | ||
|
|
||
| for i in range(N): | ||
| jobs[i].wait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import psij | ||
| from psij import Export | ||
| from psij import Import | ||
|
|
||
|
|
||
| jex = psij.JobExecutor.get_instance('local') | ||
|
|
||
| N=1 # number of jobs to run | ||
|
|
||
| def make_job(): | ||
| job = psij.Job() | ||
| spec = psij.JobSpec() | ||
| spec.executable = 'echo Hello World' | ||
| spec.arguments = ['10'] | ||
| job.spec = spec | ||
| return job | ||
|
|
||
|
|
||
|
|
||
| # Create Job and export | ||
| e = Export() | ||
| for i in range(N): | ||
| job = make_job() | ||
| e.export(obj=job.spec , dest="jobSpec." + str(i) + ".json") | ||
|
|
||
| # Import Job and submit | ||
| imp = Import() | ||
| jobs = [] | ||
| for i in range(N): | ||
| job = psij.Job() | ||
| spec = imp.load(src="jobSpec." + str(i) + ".json") | ||
| job.spec = spec | ||
| jobs.append(job) | ||
| jex.submit(job) | ||
|
|
||
| for i in range(N): | ||
| jobs[i].wait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #! /usr/bin/python3 | ||
|
|
||
| import psij | ||
| from psij import JobExecutor | ||
| from psij import JobSpec | ||
| import sys | ||
| import os | ||
| import argparse | ||
| from psij import Import | ||
|
|
||
|
|
||
|
|
||
|
|
||
| parser = argparse.ArgumentParser(prog='psij-consol') | ||
| subparser = parser.add_subparsers(dest="command", help='Subcommands') | ||
| validate_parser = subparser.add_parser("validate", help='validate JobSpec file') | ||
| validate_parser.add_argument("file", help="JobSpec file") | ||
| execute_parser = subparser.add_parser("run", help='execute JobSpec file') | ||
| execute_parser.add_argument( "executor", | ||
| choices = [ "cobalt", | ||
| "local", | ||
| "batch-test", | ||
| "flux", | ||
| "lsf", | ||
| "rp", | ||
| "saga", | ||
| "slurm" | ||
| ], | ||
| ) | ||
| execute_parser.add_argument("file", help="JobSpec file") | ||
| execute_parser.add_argument("-n", | ||
| "--number-of-jobs", | ||
| dest = "jobs", | ||
| type = int, | ||
| default=1, | ||
| help="Number of jobs to submit, default 1" | ||
| ) | ||
|
|
||
| parser.add_argument("-v", "--verbose", | ||
| dest = "verbose", | ||
| default=False, | ||
| action='store_true', | ||
| help="print detailed information") | ||
|
|
||
| parser.add_argument("--debug", | ||
| dest = "debug", | ||
| action='store_true', | ||
| help="print debug information") | ||
|
|
||
|
|
||
| # parser.print_help() | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| i = Import() | ||
|
|
||
| if args.command == 'validate': | ||
| if args.verbose: | ||
| print("Validating " + args.file) | ||
| job_spec = i.load(args.file) | ||
|
|
||
| if job_spec and isinstance(job_spec, JobSpec): | ||
| print("File ok") | ||
| else: | ||
| sys.exit("Not a valid file, could not import " + args.file) | ||
| elif args.command == "run": | ||
|
|
||
| if not args.executor: | ||
| sys.exit("Missing argument executor") | ||
|
|
||
| if args.verbose: | ||
| print("Importing " + args.file) | ||
| job_spec = i.load(args.file) | ||
| if not (job_spec and isinstance(job_spec, JobSpec)): | ||
| sys.exit("Something wrong with JobSpec") | ||
|
|
||
| # Get job executor | ||
| if args.verbose: | ||
| print("Initializing job executor") | ||
|
|
||
| jex = None | ||
|
|
||
| try: | ||
| jex = psij.JobExecutor.get_instance(args.executor) | ||
| except ValueError as err: | ||
| sys.exit(f"Panic, {err}") | ||
| except BaseException as err: | ||
| sys.exit(f"Unexpected: {err}, {type(err)}") | ||
|
|
||
| # Submit jobs | ||
| number_of_jobs = args.jobs | ||
| if args.verbose: | ||
| print("Submitting " + str(number_of_jobs) + " job(s)") | ||
|
|
||
| jobs = [] # list of created jobs | ||
| for i in range(number_of_jobs): | ||
| job = psij.Job() | ||
| job.spec = job_spec | ||
| jobs.append(job) | ||
| jex.submit(job) | ||
|
|
||
| if args.verbose: | ||
| print("Waiting for jobs to finish") | ||
| for i in range(number_of_jobs): | ||
| jobs[i].wait() | ||
| else: | ||
| # Should never be here | ||
| sys.stderr.write("Missig command. Use --help for more information.\n") | ||
| parser.print_help(sys.stderr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,6 @@ | |
| 'psij': ["py.typed"] | ||
| }, | ||
|
|
||
|
|
||
| scripts=[], | ||
|
|
||
| entry_points={ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of this name but I can't think of anything better, and we can always change it later I guess.