@@ -100,13 +100,10 @@ On a Slurm cluster, this code might look like:
100100
101101Slurm // Local // LSF // PBS // Cobalt
102102
103- .. code-block :: python
104-
105- from psij import Job, JobExecutor, JobSpec
106-
107- ex = JobExecutor.get_instance(" <&executor-type>" )
108- job = Job(JobSpec(executable = ' /bin/date' ))
109- ex.submit(job)
103+ .. literalinclude :: ../tests/getting_started/test_single_job.py
104+ :language: python
105+ :dedent: 4
106+ :lines: 6-8
110107
111108And by way of comparison, other backends can be selected with the tabs above.
112109Note that the only difference is the argument to the ``get_instance `` method.
@@ -129,14 +126,10 @@ simple as adding a loop:
129126
130127Slurm // Local // LSF // PBS // Cobalt
131128
132- .. code-block :: python
133-
134- from psij import Job, JobExecutor, JobSpec
135-
136- ex = JobExecutor.get_instance(" <&executor-type>" )
137- for _ in range (10 ):
138- job = Job(JobSpec(executable = " /bin/date" ))
139- ex.submit(job)
129+ .. literalinclude :: ../tests/getting_started/test_multiple_jobs.py
130+ :language: python
131+ :dedent: 4
132+ :lines: 6-9
140133
141134Every :class: `JobExecutor <psij.job_executor.JobExecutor> ` can handle arbitrary
142135numbers of jobs (tested with up to 64k jobs).
@@ -171,13 +164,10 @@ formatting:
171164
172165Slurm // Local // LSF // PBS // Cobalt
173166
174- .. code-block :: python
175-
176- from psij import Job, JobExecutor, JobSpec
177-
178- ex = JobExecutor.get_instance(' <&executor-type>' )
179- job = Job(JobSpec(executable = ' /bin/date' , arguments = [' -utc' , ' --debug' ]))
180- ex.submit(job)
167+ .. literalinclude :: ../tests/getting_started/test_job_arguements.py
168+ :language: python
169+ :dedent: 4
170+ :lines: 6-8
181171
182172Note: `JobSpec ` attributes can also be added incrementally:
183173
@@ -305,23 +295,10 @@ attributes=my_job_attributes)``:
305295
306296Slurm // Local // LSF // PBS // Cobalt
307297
308- .. code-block :: python
309-
310- from psij import Job, JobExecutor, JobSpec, JobAttributes, ResourceSpecV1
311-
312- executor = JobExecutor.get_instance(" <&executor-type>" )
313-
314- job = Job(
315- JobSpec(
316- executable = " /bin/date" ,
317- resources = ResourceSpecV1(node_count = 1 ),
318- attributes = JobAttributes(
319- queue_name = " <QUEUE_NAME>" , project_name = " <ALLOCATION>"
320- ),
321- )
322- )
323-
324- executor.submit(job)
298+ .. literalinclude :: ../tests/getting_started/test_scheduling_information.py
299+ :language: python
300+ :dedent: 4
301+ :lines: 7-20
325302
326303The `<QUEUE_NAME> ` and `<ALLOCATION> ` fields will depend on the system you are
327304running on.
@@ -392,29 +369,14 @@ To wait on multiple jobs at once:
392369
393370Slurm // Local // LSF // PBS // Cobalt
394371
395- .. code-block :: python
396-
397- import time
398- from psij import Job, JobExecutor, JobSpec
399-
400- count = 10
401-
402- def callback (job , status ):
403- global count
404-
405- if status.final:
406- print (f " Job { job} completed with status { status} " )
407- count -= 1
408-
409- ex = JobExecutor.get_instance(" <&executor-type>" )
410- ex.set_job_status_callback(callback)
411-
412- for _ in range (count):
413- job = Job(JobSpec(executable = " /bin/date" ))
414- ex.submit(job)
372+ .. literalinclude :: ../tests/getting_started/test_status_callbacks.py
373+ :language: python
374+ :lines: 5
415375
416- while count > 0 :
417- time.sleep(0.01 )
376+ .. literalinclude :: ../tests/getting_started/test_status_callbacks.py
377+ :language: python
378+ :dedent: 4
379+ :lines: 9-24
418380
419381Status callbacks can also be set on individual jobs with
420382:meth: `set_job_status_callback <psij.job.Job.set_job_status_callback> `.
0 commit comments