Skip to content

Commit 098429a

Browse files
committed
wiip
1 parent 96fee57 commit 098429a

File tree

7 files changed

+76
-69
lines changed

7 files changed

+76
-69
lines changed

bin/meshroom_compute

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ meshroom.setupEnvironment()
1818
import meshroom.core
1919
import meshroom.core.graph
2020
from meshroom.core.node import Status
21+
from meshroom.core.node import ChunkIndex
2122

2223

2324
parser = argparse.ArgumentParser(description='Execute a Graph of processes.')
@@ -49,11 +50,17 @@ parser.add_argument('-v', '--verbose',
4950
default=os.environ.get('MESHROOM_VERBOSE', 'info'),
5051
choices=['fatal', 'error', 'warning', 'info', 'debug', 'trace'])
5152

52-
parser.add_argument('-i', '--iteration', type=int,
53-
default=-1, help='')
53+
parser.add_argument('-i', '--iteration', type=int, default=ChunkIndex.NONE, help='')
54+
parser.add_argument('--preprocess', help='Execute preprocess chunk', action='store_true')
55+
parser.add_argument('--postprocess', help='Execute postprocess chunk', action='store_true')
5456

5557
args = parser.parse_args()
5658

59+
if args.preprocess:
60+
args.iteration = ChunkIndex.PREPROCESS
61+
elif args.postprocess:
62+
args.iteration = ChunkIndex.POSTPROCESS
63+
5764
# Setup the verbose level
5865
if args.extern:
5966
# For extern computation, we want to focus on the node computation log.
@@ -111,11 +118,16 @@ if args.node:
111118
print(f"InputNode: No computation to do.")
112119
sys.exit(0)
113120

121+
if args.iteration == ChunkIndex.NONE:
122+
chunks = node.chunks
123+
elif args.preprocess:
124+
chunks = [node._preprocessChunk]
125+
elif args.postprocess:
126+
chunks = [node._postprocessChunk]
127+
else:
128+
chunks = [node.chunks[args.iteration]]
129+
114130
if not args.forceStatus and not args.forceCompute:
115-
if args.iteration != -1:
116-
chunks = [node.chunks[args.iteration]]
117-
else:
118-
chunks = node.chunks
119131
for chunk in chunks:
120132
if chunk.status.status in submittedStatuses:
121133
# Particular case for the local isolated, the node status is set to RUNNING by the submitter directly.
@@ -130,23 +142,28 @@ if args.node:
130142
# Restore the log level
131143
logging.getLogger().setLevel(meshroom.logStringToPython[args.verbose])
132144

145+
# Prepare logger
133146
node.prepareLogger(args.iteration)
134-
node.preprocess()
135-
if args.iteration != -1:
136-
chunk = node.chunks[args.iteration]
137-
if chunk._status.status == Status.STOPPED:
138-
print(f"Chunk {chunk}: status is STOPPED")
139-
killRunningJob(node)
140-
chunk.process(args.forceCompute, args.inCurrentEnv)
141-
else:
147+
# Preprocess
148+
node.preprocess(args.forceCompute, args.inCurrentEnv)
149+
# Process
150+
if args.iteration == ChunkIndex.NONE:
142151
if node.nodeStatus.status == Status.STOPPED:
143152
print(f"Node {node}: status is STOPPED")
144153
killRunningJob(node)
145154
node.process(args.forceCompute, args.inCurrentEnv)
146-
node.postprocess()
155+
else:
156+
chunk = chunks[0]
157+
if chunk._status.status == Status.STOPPED:
158+
print(f"Chunk {chunk}: status is STOPPED")
159+
killRunningJob(node)
160+
chunk.process(args.forceCompute, args.inCurrentEnv)
161+
# Postprocess
162+
node.postprocess(args.forceCompute, args.inCurrentEnv)
163+
# Restore logger
147164
node.restoreLogger()
148165
else:
149-
if args.iteration != -1:
166+
if args.iteration != ChunkIndex.NONE:
150167
print('Error: "--iteration" only makes sense when used with "--node".')
151168
sys.exit(-1)
152169
toNodes = None

meshroom/core/desc/node.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,11 @@ def processChunkInEnvironment(self, chunk):
422422
meshroomComputeCmd = f"{chunk.node.nodeDesc.pythonExecutable} {_MESHROOM_COMPUTE}" + \
423423
f" \"{chunk.node.graph.filepath}\" --node {chunk.node.name}" + \
424424
" --extern --inCurrentEnv"
425-
426-
if len(chunk.node.getChunks()) > 1:
425+
if chunk.isPreprocess:
426+
meshroomComputeCmd += f" --preprocess"
427+
elif chunk.isPostprocess:
428+
meshroomComputeCmd += f" --postprocess"
429+
elif len(chunk.node.getChunks()) > 1:
427430
meshroomComputeCmd += f" --iteration {chunk.range.iteration}"
428431

429432
runtimeEnv = chunk.node.nodeDesc.plugin.runtimeEnv

meshroom/core/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ def executeGraph(graph, toNodes=None, forceCompute=False, forceStatus=False):
17871787
continue
17881788

17891789
print("A")
1790-
node.preprocess()
1790+
node.preprocess(forceCompute)
17911791
if not node._chunksCreated:
17921792
print("B create chunks")
17931793
node.createChunks()
@@ -1804,7 +1804,7 @@ def executeGraph(graph, toNodes=None, forceCompute=False, forceStatus=False):
18041804
print("E")
18051805
chunk.process(forceCompute)
18061806
print("F")
1807-
node.postprocess()
1807+
node.postprocess(forceCompute)
18081808
except Exception as exc:
18091809
logging.error(f"Error on node computation: {exc}")
18101810
graph.clearSubmittedNodes()

meshroom/core/node.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ExecMode(Enum):
6565

6666

6767
class ChunkIndex(IntEnum):
68+
NONE=-3
6869
PREPROCESS=-2
6970
POSTPROCESS=-1
7071
# Standard chunks are indexed from 0
@@ -660,8 +661,6 @@ def isFinished(self):
660661
return self._status.status == Status.SUCCESS
661662

662663
def process(self, forceCompute=False, inCurrentEnv=False):
663-
print(f"(NodeChunk) process {self} -> pre={self.isPreprocess}, post={self.isPostprocess}")
664-
665664
if not forceCompute and self._status.status == Status.SUCCESS:
666665
logging.info(f"Node chunk already computed: {self.name}")
667666
return
@@ -670,30 +669,19 @@ def process(self, forceCompute=False, inCurrentEnv=False):
670669
# This only happens once, when the node has the SUBMITTED status.
671670
# The sub-process will go through this method again, but the node status will
672671
# have been set to RUNNING.
673-
print(f"(_process) A")
674672
if not inCurrentEnv and self.node.getMrNodeType() == MrNodeType.NODE:
675-
print(f"(_process) B")
676673
self._processInIsolatedEnvironment()
677674
return
678675

679-
print(f"(_process) C")
680676
runningProcesses[self.name] = self
681-
print(f"(_process) D")
682677
self._status.setNode(self.node)
683-
print(f"(_process) E")
684678
self._status.initStartCompute()
685-
print(f"(_process) F")
686679
self.upgradeStatusFile()
687-
print(f"(_process) G")
688680
executionStatus = None
689-
print(f"(_process) H")
690681
self.statThread = stats.StatisticsThread(self)
691-
print(f"(_process) I")
692682
self.statThread.start()
693683

694-
print(f"(_process) J")
695684
try:
696-
print(f"(_process) K")
697685
if self.isPreprocess:
698686
self.node.nodeDesc.preprocess(self.node)
699687
elif self.isPostprocess:
@@ -704,17 +692,14 @@ def process(self, forceCompute=False, inCurrentEnv=False):
704692
self.node.saveOutputAttr()
705693
executionStatus = Status.SUCCESS
706694
except Exception:
707-
print(f"(_process) L")
708695
self.updateStatusFromCache() # check if the status has been updated by another process
709696
if self._status.status != Status.STOPPED:
710697
executionStatus = Status.ERROR
711698
raise
712699
except (KeyboardInterrupt, SystemError, GeneratorExit):
713-
print(f"(_process) M")
714700
executionStatus = Status.STOPPED
715701
raise
716702
finally:
717-
print(f"(_process) N")
718703
self._status.setNode(self.node)
719704
self._status.initEndCompute()
720705
self.upgradeStatusFile()
@@ -728,8 +713,6 @@ def process(self, forceCompute=False, inCurrentEnv=False):
728713
self.statistics = stats.Statistics()
729714
del runningProcesses[self.name]
730715

731-
print(f"(_process) O")
732-
733716
def _processInIsolatedEnvironment(self):
734717
"""
735718
Process this node chunk in the isolated environment defined in the environment
@@ -1721,42 +1704,45 @@ def initStatusOnCompute(self, forceCompute=False):
17211704
chunkPlaceholder._status.status = self._nodeStatus.status
17221705
self._chunkPlaceholder.setObjectList([chunkPlaceholder])
17231706
self.chunksChanged.emit()
1707+
1708+
def getChunkName(self, iteration: int):
1709+
if iteration >= 0:
1710+
return str(self.chunks[iteration].index)
1711+
elif iteration == ChunkIndex.PREPROCESS:
1712+
return "preprocess"
1713+
elif iteration == ChunkIndex.POSTPROCESS:
1714+
return "postprocess"
1715+
return "0"
17241716

17251717
def processIteration(self, iteration):
17261718
self._chunks[iteration].process()
17271719

1728-
def preprocess(self):
1720+
def preprocess(self, forceCompute=False, inCurrentEnv=False):
17291721
""" Prepare the node processing """
1730-
print("(preprocess)")
17311722
if self.nodeDesc._hasPreprocess:
1732-
print("-> has preprocess")
17331723
# self.nodeDesc.preprocess(self)
1734-
self._preprocessChunk.process()
1724+
self._preprocessChunk.process(forceCompute, inCurrentEnv)
17351725

17361726
def process(self, forceCompute=False, inCurrentEnv=False):
1737-
print("(process)")
17381727
for chunk in self._chunks:
1739-
print("-> chunk", chunk)
17401728
chunk.process(forceCompute, inCurrentEnv)
17411729

1742-
def postprocess(self):
1730+
def postprocess(self, forceCompute=False, inCurrentEnv=False):
17431731
"""
17441732
Invoke the post process on Client Node to execute after the processing on the
17451733
node is completed
17461734
"""
1747-
print("(postprocess)")
17481735
if self.nodeDesc._hasPostprocess:
1749-
print("-> has postprocess")
17501736
# self.nodeDesc.postprocess(self)
1751-
self._postprocessChunk.process()
1737+
self._postprocessChunk.process(forceCompute, inCurrentEnv)
17521738

17531739
def getLogHandlers(self):
17541740
return self._handlers
17551741

17561742
def prepareLogger(self, iteration=-1):
17571743
# Get file handler path
1758-
chunkIndex = self.chunks[iteration].index if iteration != -1 else 0
1759-
logFileName = f"{chunkIndex}.log"
1744+
chunkName = self.getChunkName(iteration)
1745+
logFileName = f"{chunkName}.log"
17601746
logFile = os.path.join(self.internalFolder, logFileName)
17611747
# Setup logger
17621748
rootLogger = logging.getLogger()
@@ -2336,10 +2322,14 @@ def _resetChunks(self):
23362322
""" Set chunks on the node.
23372323
# TODO : Maybe don't delete chunks if we will recreate them as before ?
23382324
"""
2339-
if self.isInputNode:
2325+
if not self.isComputableType:
23402326
self._chunksCreated = True
23412327
return
23422328
# Disconnect signals
2329+
if self._preprocessChunk:
2330+
self._preprocessChunk.statusChanged.disconnect(self.globalStatusChanged)
2331+
if self._postprocessChunk:
2332+
self._postprocessChunk.statusChanged.disconnect(self.globalStatusChanged)
23432333
for chunk in self._chunks:
23442334
chunk.statusChanged.disconnect(self.globalStatusChanged)
23452335
# Empty list
@@ -2375,7 +2365,18 @@ def _resetChunks(self):
23752365
self._chunksCreated = False
23762366
self.setSize(0)
23772367
self._chunkPlaceholder.setObjectList([NodeChunk(self, desc.computation.Range())])
2378-
2368+
# Pre/post process
2369+
if self.nodeDesc._hasPreprocess:
2370+
self._preprocessChunk = NodeChunk(self, desc.Range(ChunkIndex.PREPROCESS))
2371+
self._preprocessChunk.statusChanged.connect(self.globalStatusChanged)
2372+
else:
2373+
self._preprocessChunk = None
2374+
if self.nodeDesc._hasPostprocess:
2375+
self._postprocessChunk = NodeChunk(self, desc.Range(ChunkIndex.POSTPROCESS))
2376+
self._postprocessChunk.statusChanged.connect(self.globalStatusChanged)
2377+
else:
2378+
self._postprocessChunk = None
2379+
23792380
# Create chunks when possible
23802381
self.chunksCreatedChanged.emit()
23812382
self.chunksChanged.emit()

meshroom/core/taskManager.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ def run(self):
9797
continue
9898

9999

100-
print("(tm) A")
101-
node.preprocess()
102-
print("(tm) B")
100+
node.preprocess(self.forceCompute)
103101
for cId, chunk in enumerate(node.chunks):
104-
print("(tm) C", cId, chunk)
105102
if chunk.isFinishedOrRunning() or not self.isRunning():
106103
continue
107104

@@ -111,17 +108,13 @@ def run(self):
111108
_nodeName, _node, _nbNodes = node.nodeType, nId+1, len(self._manager._nodesToProcess)
112109

113110
if multiChunks:
114-
print("(tm) D0")
115111
_chunk, _nbChunks = cId+1, len(node.chunks)
116112
logging.info(f"[{_node}/{_nbNodes}]({_chunk}/{_nbChunks}) {_nodeName}")
117113
else:
118-
print("(tm) D1")
119114
logging.info(f"[{_node}/{_nbNodes}] {_nodeName}")
120115
try:
121-
print("(tm) D")
122116
chunk.process(self.forceCompute)
123117
except Exception as exc:
124-
print("(tm) D2")
125118
if chunk.isStopped():
126119
stopAndRestart = True
127120
break
@@ -136,8 +129,7 @@ def run(self):
136129
# Node already removed (for instance a global clear of _nodesToProcess)
137130
pass
138131
n.clearSubmittedChunks()
139-
print("(tm) E")
140-
node.postprocess()
132+
node.postprocess(self.forceCompute)
141133

142134
if stopAndRestart:
143135
break

meshroom/ui/qml/GraphEditor/ChunksListView.qml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ ColumnLayout {
2222
property int currentIndex: 0
2323

2424
function getCurrentChunkIndex() {
25-
console.log("(getCurrentChunkIndex)", currentIndex, chunks.length)
2625
if ( currentIndex == undefined || !chunks || currentIndex == ChunksListView.IndexItems.NULL ) { return -1 }
2726
let hasPreprocess = chunks.some(function(chk) { return chk.chunkIndex == ChunksListView.IndexItems.PREPROCESS })
2827
let hasPostprocess = chunks.some(function(chk) { return chk.chunkIndex == ChunksListView.IndexItems.POSTPROCESS })
@@ -33,7 +32,7 @@ ColumnLayout {
3332

3433
property int currentItemIndex: getCurrentChunkIndex()
3534

36-
property variant currentChunk: (currentItemIndex >= 0 && chunks && chunks.length > currentItemIndex) ? chunks[currentItemIndex].chunk : null
35+
property variant currentChunk: (currentItemIndex >= 0 && chunks && chunks.length > currentItemIndex) ? chunks[currentItemIndex].chunk : undefined
3736

3837
onChunksChanged: {
3938
// When the list changes, ensure the current index is in the new range
@@ -95,7 +94,6 @@ ColumnLayout {
9594
width: ListView.view.width
9695
leftPadding: 8
9796
onClicked: {
98-
console.log("clicked on chunk", chunkIndex, "(", text, ")")
9997
chunksLV.forceActiveFocus()
10098
root.currentIndex = chunkIndex
10199
}

meshroom/ui/qml/GraphEditor/NodeLog.qml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ FocusScope {
1717
property int currentChunkIndex
1818
property variant currentChunk
1919

20-
onCurrentChunkIndexChanged: {
21-
console.log("[log] changed chunk :", currentChunkIndex, root.currentChunk.logFile)
22-
}
23-
2420
Layout.fillWidth: true
2521
Layout.fillHeight: true
2622

0 commit comments

Comments
 (0)