Skip to content

Commit 6ff93d8

Browse files
committed
Pre/Post tasks : Fix typos & style + remove dead code
1 parent 10782bf commit 6ff93d8

7 files changed

Lines changed: 33 additions & 54 deletions

File tree

bin/meshroom_compute

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ parser.add_argument('-v', '--verbose',
5050
default=os.environ.get('MESHROOM_VERBOSE', 'info'),
5151
choices=['fatal', 'error', 'warning', 'info', 'debug', 'trace'])
5252

53-
parser.add_argument('-i', '--iteration', type=int, default=ChunkIndex.NONE, help='')
53+
parser.add_argument('-i', '--iteration', type=int, default=ChunkIndex.NONE,
54+
help='Define specific chunk index to compute')
5455
parser.add_argument('--preprocess', help='Execute preprocess chunk', action='store_true')
5556
parser.add_argument('--postprocess', help='Execute postprocess chunk', action='store_true')
5657

@@ -151,8 +152,7 @@ if args.node:
151152
for chunk in chunks:
152153
if chunk.status.status in submittedStatuses:
153154
# Particular case for the local isolated, the node status is set to RUNNING by the submitter directly.
154-
# We ensure that no other instance has start
155-
# ed to compute, by checking that the computeSessionUid is empty.
155+
# We ensure that no other instance has started to compute, by checking that the computeSessionUid is empty.
156156
if chunk.node.getMrNodeType() == meshroom.core.MrNodeType.NODE and \
157157
not chunk.status.computeSessionUid and node._nodeStatus.submitterSessionUid:
158158
continue

meshroom/core/desc/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def preprocess(self, node):
281281
pass
282282

283283
@property
284-
def _hasPreprocess(self):
284+
def hasPreprocess(self):
285285
""" Returns True if the class has a preprocess """
286286
return type(self).preprocess is not BaseNode.preprocess
287287

@@ -294,7 +294,7 @@ def postprocess(self, node):
294294
pass
295295

296296
@property
297-
def _hasPostprocess(self):
297+
def hasPostprocess(self):
298298
""" Returns True if the class has a postprocess """
299299
return type(self).postprocess is not BaseNode.postprocess
300300

meshroom/core/node.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,9 @@ def __init__(self, nodeType: str, position: Position = None, parent: BaseObject
845845
self.dirty: bool = True # whether this node's outputs must be re-evaluated on next Graph update
846846
self._chunks: list[NodeChunk] = ListModel(parent=self)
847847
self._preprocessChunk = NodeChunk(self, desc.Range(ChunkIndex.PREPROCESS)) if \
848-
self.nodeDesc and self.nodeDesc._hasPreprocess else None
848+
self.nodeDesc and self.nodeDesc.hasPreprocess else None
849849
self._postprocessChunk = NodeChunk(self, desc.Range(ChunkIndex.POSTPROCESS)) if \
850-
self.nodeDesc and self.nodeDesc._hasPostprocess else None
850+
self.nodeDesc and self.nodeDesc.hasPostprocess else None
851851
self._chunksCreated = False # Only initialize chunks on compute
852852
self._chunkPlaceholder: list[NodeChunk] = ListModel(parent=self) # Placeholder chunk for nodes with dynamic ones
853853
self._uid: str = uid
@@ -1468,9 +1468,9 @@ def clearLocallySubmittedChunks(self):
14681468

14691469
def upgradeStatusTo(self, newStatus, execMode=None):
14701470
""" Upgrade node to the given status and save it on disk. """
1471-
if self.nodeDesc._hasPreprocess:
1471+
if self.nodeDesc.hasPreprocess:
14721472
self._preprocessChunk.upgradeStatusTo(newStatus)
1473-
if self.nodeDesc._hasPostprocess:
1473+
if self.nodeDesc.hasPostprocess:
14741474
self._postprocessChunk.upgradeStatusTo(newStatus)
14751475
if self._chunksCreated:
14761476
for chunk in self._chunks:
@@ -1674,9 +1674,9 @@ def updateStatusFromCache(self):
16741674
logging.warning(f"Could not create chunks from cache: {e}")
16751675
return
16761676
s = self.globalStatus
1677-
if self.nodeDesc._hasPreprocess:
1677+
if self.nodeDesc.hasPreprocess:
16781678
self._preprocessChunk.updateStatusFromCache()
1679-
if self.nodeDesc._hasPostprocess:
1679+
if self.nodeDesc.hasPostprocess:
16801680
self._postprocessChunk.updateStatusFromCache()
16811681
if self._chunksCreated:
16821682
for chunk in self._chunks:
@@ -1780,7 +1780,7 @@ def processIteration(self, iteration):
17801780

17811781
def preprocess(self, forceCompute=False, inCurrentEnv=False):
17821782
""" Prepare the node processing """
1783-
if self.nodeDesc._hasPreprocess:
1783+
if self.nodeDesc.hasPreprocess:
17841784
self.prepareLogger(ChunkIndex.PREPROCESS)
17851785
self._preprocessChunk.process(forceCompute, inCurrentEnv)
17861786
self.restoreLogger()
@@ -1794,7 +1794,7 @@ def postprocess(self, forceCompute=False, inCurrentEnv=False):
17941794
Invoke the post process on Client Node to execute after the processing on the
17951795
node is completed
17961796
"""
1797-
if self.nodeDesc._hasPostprocess:
1797+
if self.nodeDesc.hasPostprocess:
17981798
self.prepareLogger(ChunkIndex.POSTPROCESS)
17991799
self._postprocessChunk.process(forceCompute, inCurrentEnv)
18001800
self.restoreLogger()
@@ -1904,9 +1904,9 @@ def endSequence(self):
19041904

19051905
def stopComputation(self):
19061906
""" Stop the computation of this node. """
1907-
if self.nodeDesc._hasPreprocess:
1907+
if self.nodeDesc.hasPreprocess:
19081908
self._preprocessChunk.stopProcess()
1909-
if self.nodeDesc._hasPostprocess:
1909+
if self.nodeDesc.hasPostprocess:
19101910
self._postprocessChunk.stopProcess()
19111911
if self._chunks:
19121912
for chunk in self._chunks.values():
@@ -2002,19 +2002,19 @@ def getChunks(self) -> list[NodeChunk]:
20022002
@property
20032003
def _allChunks(self) -> list[NodeChunk]:
20042004
chunks = []
2005-
if self.nodeDesc._hasPreprocess:
2005+
if self.nodeDesc.hasPreprocess:
20062006
chunks.append(self._preprocessChunk)
20072007
chunks.extend([c for c in self._chunks])
2008-
if self.nodeDesc._hasPostprocess:
2008+
if self.nodeDesc.hasPostprocess:
20092009
chunks.append(self._postprocessChunk)
20102010
return chunks
20112011

20122012
def getAllChunks(self):
20132013
allChunks = []
2014-
if self.nodeDesc._hasPreprocess:
2014+
if self.nodeDesc.hasPreprocess:
20152015
allChunks.append({"chunkIndex": ChunkIndex.PREPROCESS, "chunk": self._preprocessChunk, "name": "Preprocess"})
20162016
allChunks.extend([{"chunkIndex": i, "chunk": c, "name": str(i)} for i, c in enumerate(self._chunks)])
2017-
if self.nodeDesc._hasPostprocess:
2017+
if self.nodeDesc.hasPostprocess:
20182018
allChunks.append({"chunkIndex": ChunkIndex.POSTPROCESS, "chunk": self._postprocessChunk, "name": "Postprocess"})
20192019
return allChunks
20202020

@@ -2277,6 +2277,8 @@ def _hasDisplayableShape(self):
22772277
chunksCreated = Property(bool, lambda self: self._chunksCreated, notify=chunksCreatedChanged)
22782278
chunksChanged = Signal()
22792279
chunks = Property(Variant, getChunks, notify=chunksChanged)
2280+
preprocessChunk = Property(Variant, lambda self: self._preprocessChunk, notify=chunksChanged)
2281+
postprocessChunk = Property(Variant, lambda self: self._postprocessChunk, notify=chunksChanged)
22802282
allChunks = Property(Variant, getAllChunks, notify=chunksChanged)
22812283
chunkPlaceholder = Property(Variant, lambda self: self._chunkPlaceholder, notify=chunksChanged)
22822284
nbParallelizationBlocks = Property(int, lambda self: len(self._chunks) if self._chunksCreated else 0, notify=chunksChanged)
@@ -2470,12 +2472,12 @@ def _resetChunks(self):
24702472
self.setSize(0)
24712473
self._chunkPlaceholder.setObjectList([NodeChunk(self, desc.computation.Range())])
24722474
# Pre/post process
2473-
if self.nodeDesc._hasPreprocess:
2475+
if self.nodeDesc.hasPreprocess:
24742476
self._preprocessChunk = NodeChunk(self, desc.Range(ChunkIndex.PREPROCESS))
24752477
self._preprocessChunk.statusChanged.connect(self.globalStatusChanged)
24762478
else:
24772479
self._preprocessChunk = None
2478-
if self.nodeDesc._hasPostprocess:
2480+
if self.nodeDesc.hasPostprocess:
24792481
self._postprocessChunk = NodeChunk(self, desc.Range(ChunkIndex.POSTPROCESS))
24802482
self._postprocessChunk.statusChanged.connect(self.globalStatusChanged)
24812483
else:

meshroom/core/submitter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def chunksIterations(self) -> list[int]:
132132
"""
133133
if self.isExpanding:
134134
return None
135-
if not self.isExpanding and self.node.isParallelized:
135+
if self.node.isParallelized:
136136
_, _, nbBlocks = self.node.nodeDesc.parallelization.getSizes(self.node)
137137
iterationsToIgnore = []
138138
for c in self.node._chunks:
@@ -144,11 +144,11 @@ def chunksIterations(self) -> list[int]:
144144

145145
@property
146146
def hasPreprocess(self) -> bool:
147-
return self.node.nodeDesc._hasPreprocess
147+
return self.node.nodeDesc.hasPreprocess
148148

149149
@property
150150
def hasPostprocess(self) -> bool:
151-
return self.node.nodeDesc._hasPostprocess
151+
return self.node.nodeDesc.hasPostprocess
152152

153153
def __repr__(self):
154154
depsNames = "|".join([t.node.name for t in self.dependencies])
@@ -181,7 +181,7 @@ def __init__(self, nodes, edges):
181181

182182
def _orderNodes(self, nodes, edges):
183183
"""
184-
Take all the nodes and connections and orger them by processing step
184+
Take all the nodes and connections and order them by processing step
185185
0 is the root nodes (can be executed last)
186186
Then 1 is the level with the direct dependencies for the root nodes, and etc...
187187
"""

meshroom/core/taskManager.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,6 @@ def onChunksCreated(createdNode):
7575
self._manager.chunksCreated.disconnect(onChunksCreated)
7676
timer.stop()
7777

78-
def execChunk(self, chunk, node, function) -> bool:
79-
""" Handle the chunk process & fail
80-
81-
Args:
82-
chunk (chunk to process): _description_
83-
node (_type_): _description_
84-
function (_type_): _description_
85-
86-
Returns:
87-
bool: _description_
88-
"""
89-
try:
90-
function(self.forceCompute)
91-
except Exception as exc:
92-
if chunk.isStopped():
93-
return True
94-
else:
95-
logging.error(f"Error on node computation: {exc}")
96-
self.clearNodes(node)
97-
return False
98-
9978
def clearNodes(self, node):
10079
nodesToRemove, _ = self._manager._graph.dfsOnDiscover(startNodes=[node], reverse=True)
10180
# remove following nodes from the task queue
@@ -152,7 +131,7 @@ def run(self):
152131
for chunk in node._chunks:
153132
if chunk.isAlreadySubmitted():
154133
chunk.upgradeStatusTo(Status.NONE, ExecMode.NONE)
155-
if node.nodeDesc._hasPostprocess:
134+
if node.nodeDesc.hasPostprocess:
156135
node._postprocessChunk.upgradeStatusTo(Status.NONE, ExecMode.NONE)
157136
break
158137
# Process

tests/test_compute.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,14 @@ def test_prepostprocess(self, tmp_path):
191191
root = chunkLog.parent
192192
preprocessLog = root / "preprocess.log"
193193
postprocessLog = root / "postprocess.log"
194-
def check_file(path, suffix = ""):
194+
def check_file(path, suffix=""):
195195
with open(path, "r") as f:
196196
content = f.read()
197-
suffix = ""
198197
reg = re.compile(self.logPrefix + "TestNodeD_1" + suffix)
199198
assert len(reg.findall(content)) == 1
200-
check_file(preprocessLog, " (preprocess)")
199+
check_file(preprocessLog, " \(preprocess\)")
201200
check_file(chunkLog, "")
202-
check_file(postprocessLog, " postprocess")
201+
check_file(postprocessLog, " \(postprocess\)")
203202

204203

205204
class TestLockUpdates:
@@ -568,8 +567,8 @@ def test_status(self, graphSavedOnDisk):
568567

569568
# Check node
570569
assert len(node.chunks) == 1
571-
assert node.nodeDesc._hasPreprocess
572-
assert node.nodeDesc._hasPostprocess
570+
assert node.nodeDesc.hasPreprocess
571+
assert node.nodeDesc.hasPostprocess
573572

574573
# Check status before
575574
assert node.globalStatus == Status.NONE.name

tests/test_submit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def test_orderTasks(self):
171171
nodeB = self.addNewNode(graph, "PluginSubmitter"+"B", nodeParams={"inputs": [nodeA.output]})
172172
nodeC = self.addNewNode(graph, "PluginSubmitter"+"C", nodeParams={"inputs": [nodeB.output]})
173173
# Order tasks
174-
submitter = get_submitter()
175174
nodes, edges = graph.dfsOnFinish(startNodes=[nodeC])
176175
orderedTasks = OrderedTasks(nodes, edges)
177176
# === Test result ===

0 commit comments

Comments
 (0)