2
2
3
3
> ** TL;DR**
4
4
> * Sync* : return a scalar or a dict ⟶ NePS records it automatically.
5
- > * Async* : return ` None ` , launch a job, and call ` neps.save_callback () ` when the job finishes.
5
+ > * Async* : return ` None ` , launch a job, and call ` neps.save_pipeline_results () ` when the job finishes.
6
6
7
7
---
8
8
@@ -57,7 +57,6 @@ All other values raise a `TypeError` inside NePS.
57
57
58
58
``` python
59
59
from pathlib import Path
60
- import subprocess
61
60
import neps
62
61
63
62
def evaluate_pipeline (
@@ -67,9 +66,8 @@ def evaluate_pipeline(
67
66
learning_rate : float ,
68
67
optimizer : str ,
69
68
):
70
- # 1) write a Slurm script into the trial dir
71
- sh = pipeline_directory / " run.sh"
72
- sh.write_text(f """ #!/bin/bash
69
+ # 1) write a Slurm script
70
+ script = f """ #!/bin/bash
73
71
#SBATCH --time=0-00:10
74
72
#SBATCH --job-name=trial_ { pipeline_id}
75
73
#SBATCH --partition=bosch_cpu-cascadelake
@@ -82,10 +80,9 @@ python run_pipeline.py \
82
80
--pipeline_id { pipeline_id} \
83
81
--root_dir { root_directory}
84
82
""" )
85
- sh.chmod(0o 755 )
86
83
87
84
# 2) submit and RETURN None (async)
88
- subprocess.check_call([ " sbatch " , str (sh)] )
85
+ sumit_job(script )
89
86
return None # ⟵ signals async mode
90
87
```
91
88
@@ -101,17 +98,22 @@ parser.add_argument("--optimizer")
101
98
parser.add_argument(" --pipeline_id" )
102
99
parser.add_argument(" --root_dir" )
103
100
args = parser.parse_args()
104
-
105
- # … do heavy training …
106
- val_loss = 0.1234
107
- wall_clock_cost = 180 # seconds
108
-
109
- result = {
110
- " objective_to_minimize" : val_loss,
111
- " cost" : wall_clock_cost,
112
- }
113
-
114
- neps.save_callback(
101
+ try :
102
+ # … do heavy training …
103
+ val_loss = 0.1234
104
+ wall_clock_cost = 180 # seconds
105
+ result = {
106
+ " objective_to_minimize" : val_loss,
107
+ " cost" : wall_clock_cost,
108
+ }
109
+ except Exception as e:
110
+ result = {
111
+ " objective_to_minimize" : val_loss,
112
+ " cost" : wall_clock_cost,
113
+ " exception" : e
114
+ }
115
+
116
+ neps.save_pipeline_results(
115
117
user_result = result,
116
118
pipeline_id = args.pipeline_id,
117
119
root_directory = Path(args.root_dir),
@@ -143,6 +145,6 @@ Use them to handle warm‑starts, logging and result persistence.
143
145
144
146
* [x] Return scalar ** or** dict ** or** ` None ` .
145
147
* [x] Include ` cost ` when using cost budgets.
146
- * [x] When returning ` None ` , make sure ** exactly one** call to ` neps.save_callback ` happens.
148
+ * [x] When returning ` None ` , make sure ** exactly one** call to ` neps.save_pipeline_results ` happens.
147
149
* [x] Save checkpoints and artefacts in ` pipeline_directory ` .
148
150
* [x] Handle resume via ` previous_pipeline_directory ` .
0 commit comments