Skip to content

Commit 5732200

Browse files
committed
fix: ignored value when using default_factory in field
1 parent fce5975 commit 5732200

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

docs/connectors/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Connectors
22

3-
- Localhost connector (default)
3+
Connectors define how to access a computer (file and process management). There are two types at the moment in experimaestro:
4+
5+
- Localhost connector (by default)
46
- SSH (alpha)
57

68

docs/launchers/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Launchers
22

3+
Launchers, together with the [Connector](../connectors/index.md), specify how a task should be launched.
4+
There exist two types of launchers at the moment, [direct launcher](#direct) (starting
5+
a new process) or through [slurm](#slurm)
6+
37
## Types
48

5-
### direct (default)
9+
### Direct
610

711
By default, jobs are launched directly by the scheduler using python scripts.
812

913
::: experimaestro.launchers.direct.DirectLauncher
1014

11-
### Slurm (since 0.8.7)
15+
### Slurm
1216

1317
The [Slurm](https://slurm.schedmd.com/documentation.html) workload manager launcher is supported.
1418
It is possible to use different settings for different jobs by using the `config`

src/experimaestro/core/objects/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ def postprocess(self, stub, config: Config, values):
339339
try:
340340
if argument.generator:
341341
if not isinstance(argument.generator, Generator):
342+
# Don't set if already set
343+
if config.__xpm__.values.get(k) is not None:
344+
continue
342345
value = argument.generator()
343346
else:
344347
sig = inspect.signature(argument.generator)

src/experimaestro/tests/test_identifier.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class C(Config):
3838
b: Param[int]
3939

4040

41+
class CField(Config):
42+
a: Param[int] = field(default_factory=lambda: 1)
43+
b: Param[int]
44+
45+
4146
class D(Config):
4247
a: Param[A]
4348

@@ -79,6 +84,10 @@ def test_param_default():
7984
assert_equal(C(a=1, b=2), C(b=2))
8085

8186

87+
def test_identifier_default_field():
88+
assert_equal(CField(a=1, b=2), CField(b=2))
89+
90+
8291
def test_param_inner_eq():
8392
assert_equal(D(a=A(a=1)), D(a=A(a=1)))
8493

src/experimaestro/tests/test_param.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,26 @@ class A(Config):
290290
A.__getxpmtype__().getArgument("x")
291291

292292

293+
# --- Handling default with field
294+
295+
296+
def test_param_default_set():
297+
"""Test that the default setting is well set"""
298+
299+
class A0(Config):
300+
x: Param[int] = 2
301+
302+
assert A0().instance().x == 2
303+
assert A0(x=3).instance().x == 3
304+
305+
class A(Config):
306+
x: Param[int] = field(default_factory=lambda: 2)
307+
308+
assert A().instance().x == 2
309+
310+
assert A(x=3).instance().x == 3
311+
312+
293313
# --- Handling help annotations
294314

295315

0 commit comments

Comments
 (0)