Skip to content

Commit 0d4a261

Browse files
authored
Make cores_per_node and mem_per_node regular provider attributes (#3988)
Prior to this PR, these were defined with @Property which passed through directly to underlying state attributes. Moving from mypy 1.5.1 to 1.18.2 in testing revealed that the type annotations on the property setters were incorrect. For example, ``` parsl/providers/slurm/slurm.py:174: error: Incompatible types in assignment (expression has type "int | None", variable has type "int") [assignment] ``` As part of tidying that up, it seemed to me that those property methods weren't necessary at all. This PR removes property behaviour for those attributes. The type annotations are now defined in ExecutionProvider.__init__ (unchanged as already correct). The documentation which used to live on the @Property is moved to the class level docstring. ## Type of change - Code maintenance/cleanup
1 parent e4c2178 commit 0d4a261

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

parsl/providers/base.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,28 @@ class ExecutionProvider(metaclass=ABCMeta):
3333
[cancel] <--------|----+
3434
|
3535
+-------------------
36-
"""
36+
37+
In addition to the listed methods, an ExecutionProvider instance must always
38+
have these attributes, which both default to `None`:
39+
40+
mem_per_node: Real memory to provision per node in GB.
41+
42+
Providers which set this attribute should ask for mem_per_node of memory
43+
when provisioning resources, and set the corresponding environment
44+
variable PARSL_MEMORY_GB before executing submitted commands.
45+
46+
If this attribute is set, executors may use it to calculate how many tasks can
47+
run concurrently per node.
48+
49+
cores_per_node: Number of cores to provision per node.
50+
51+
Providers which set this attribute should ask for cores_per_node cores
52+
when provisioning resources, and set the corresponding environment
53+
variable PARSL_CORES before executing submitted commands.
54+
55+
If this attribute is set, executors may use it to calculate how many tasks can
56+
run concurrently per node.
57+
"""
3758

3859
@abstractmethod
3960
def __init__(self) -> None:
@@ -44,8 +65,8 @@ def __init__(self) -> None:
4465
self.script_dir: Optional[str]
4566
self.parallelism: float
4667
self.resources: Dict[object, Any]
47-
self._cores_per_node: Optional[int] = None
48-
self._mem_per_node: Optional[float] = None
68+
self.cores_per_node: Optional[int] = None
69+
self.mem_per_node: Optional[float] = None
4970
pass
5071

5172
@abstractmethod
@@ -111,40 +132,6 @@ def label(self) -> str:
111132
''' Provides the label for this provider '''
112133
pass
113134

114-
@property
115-
def mem_per_node(self) -> Optional[float]:
116-
"""Real memory to provision per node in GB.
117-
118-
Providers which set this property should ask for mem_per_node of memory
119-
when provisioning resources, and set the corresponding environment
120-
variable PARSL_MEMORY_GB before executing submitted commands.
121-
122-
If this property is set, executors may use it to calculate how many tasks can
123-
run concurrently per node.
124-
"""
125-
return self._mem_per_node
126-
127-
@mem_per_node.setter
128-
def mem_per_node(self, value: float) -> None:
129-
self._mem_per_node = value
130-
131-
@property
132-
def cores_per_node(self) -> Optional[int]:
133-
"""Number of cores to provision per node.
134-
135-
Providers which set this property should ask for cores_per_node cores
136-
when provisioning resources, and set the corresponding environment
137-
variable PARSL_CORES before executing submitted commands.
138-
139-
If this property is set, executors may use it to calculate how many tasks can
140-
run concurrently per node.
141-
"""
142-
return self._cores_per_node
143-
144-
@cores_per_node.setter
145-
def cores_per_node(self, value: int) -> None:
146-
self._cores_per_node = value
147-
148135
@property
149136
@abstractmethod
150137
def status_polling_interval(self) -> int:

0 commit comments

Comments
 (0)