|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +This is a script used to wrap the process of processing a node on the farm |
| 5 | +It will handle chunk creation and create all the jobs for these chunks |
| 6 | +If the submitter cannot create chunks, then it will process the chunks serially |
| 7 | +in the current process |
| 8 | +""" |
| 9 | + |
| 10 | +import argparse |
| 11 | +import logging |
| 12 | +import os |
| 13 | +import sys |
| 14 | +try: |
| 15 | + import meshroom |
| 16 | +except Exception: |
| 17 | + # If meshroom module is not in the PYTHONPATH, add our root using the relative path |
| 18 | + import pathlib |
| 19 | + meshroomRootFolder = pathlib.Path(__file__).parent.parent.resolve() |
| 20 | + sys.path.append(meshroomRootFolder) |
| 21 | + import meshroom |
| 22 | +meshroom.setupEnvironment() |
| 23 | + |
| 24 | +import meshroom.core |
| 25 | +import meshroom.core.graph |
| 26 | +from meshroom.core import submitters |
| 27 | +from meshroom.core.submitter import SubmitterOptionsEnum |
| 28 | +from meshroom.core.node import Status |
| 29 | + |
| 30 | + |
| 31 | +parser = argparse.ArgumentParser(description='Execute a Graph of processes.') |
| 32 | +parser.add_argument('graphFile', metavar='GRAPHFILE.mg', type=str, |
| 33 | + help='Filepath to a graph file.') |
| 34 | + |
| 35 | +parser.add_argument('--submitter', type=str, required=True, |
| 36 | + help='Name of the submitter used to create the job.') |
| 37 | +parser.add_argument('--node', metavar='NODE_NAME', type=str, required=True, |
| 38 | + help='Process the node. It will generate an error if the dependencies are not already computed.') |
| 39 | +parser.add_argument('--inCurrentEnv', help='Execute process in current env without creating a dedicated runtime environment.', |
| 40 | + action='store_true') |
| 41 | +parser.add_argument('--forceStatus', help='Force computation if status is RUNNING or SUBMITTED.', |
| 42 | + action='store_true') |
| 43 | +parser.add_argument('--forceCompute', help='Compute in all cases even if already computed.', |
| 44 | + action='store_true') |
| 45 | +parser.add_argument('--extern', help='Use this option when you compute externally after submission to a render farm from meshroom.', |
| 46 | + action='store_true') |
| 47 | +parser.add_argument('--cache', metavar='FOLDER', type=str, |
| 48 | + default=None, |
| 49 | + help='Override the cache folder') |
| 50 | +parser.add_argument('-v', '--verbose', |
| 51 | + help='Set the verbosity level for logging:\n' |
| 52 | + ' - fatal: Show only critical errors.\n' |
| 53 | + ' - error: Show errors only.\n' |
| 54 | + ' - warning: Show warnings and errors.\n' |
| 55 | + ' - info: Show standard informational messages.\n' |
| 56 | + ' - debug: Show detailed debug information.\n' |
| 57 | + ' - trace: Show all messages, including trace-level details.', |
| 58 | + default=os.environ.get('MESHROOM_VERBOSE', 'info'), |
| 59 | + choices=['fatal', 'error', 'warning', 'info', 'debug', 'trace']) |
| 60 | + |
| 61 | +args = parser.parse_args() |
| 62 | + |
| 63 | +# For extern computation, we want to focus on the node computation log. |
| 64 | +# So, we avoid polluting the log with general warning about plugins, versions of nodes in file, etc. |
| 65 | +logging.getLogger().setLevel(level=logging.INFO) |
| 66 | + |
| 67 | +meshroom.core.initPlugins() |
| 68 | +meshroom.core.initNodes() |
| 69 | +meshroom.core.initSubmitters() # Required to spool child job |
| 70 | + |
| 71 | +graph = meshroom.core.graph.loadGraph(args.graphFile) |
| 72 | +if args.cache: |
| 73 | + graph.cacheDir = args.cache |
| 74 | +graph.update() |
| 75 | + |
| 76 | +# Execute the node |
| 77 | +node = graph.findNode(args.node) |
| 78 | +submittedStatuses = [Status.RUNNING] |
| 79 | + |
| 80 | +# Find submitter |
| 81 | +submitter = None |
| 82 | +# It's required if we want to spool chunks on different machines |
| 83 | +for subName, sub in submitters.items(): |
| 84 | + if args.submitter == subName: |
| 85 | + submitter = sub |
| 86 | + break |
| 87 | + |
| 88 | +if node._nodeStatus.status in (Status.STOPPED, Status.KILLED): |
| 89 | + logging.error("Node status is STOPPED or KILLED.") |
| 90 | + if submitter: |
| 91 | + submitter.killRunningJob() |
| 92 | + sys.exit(meshroom.MeshroomExitStatus.ERROR_NO_RETRY) |
| 93 | + |
| 94 | +if not node._chunksCreated: |
| 95 | + # Create node chunks |
| 96 | + # Once created we don't have to do it again even if we relaunch the job |
| 97 | + node.createChunks() |
| 98 | + # Set the chunks statuses |
| 99 | + for chunk in node._chunks: |
| 100 | + if args.forceCompute or chunk._status.status != Status.SUCCESS: |
| 101 | + hasChunkToLaunch = True |
| 102 | + chunk._status.setNode(node) |
| 103 | + chunk._status.initExternSubmit() |
| 104 | + chunk.upgradeStatusFile() |
| 105 | + |
| 106 | +# Get chunks to process in the current process |
| 107 | +chunksToProcess = [] |
| 108 | +if submitter: |
| 109 | + if not submitter._options.includes(SubmitterOptionsEnum.EDIT_TASKS): |
| 110 | + chunksToProcess = node.chunks |
| 111 | +else: |
| 112 | + # Cannot retrieve job -> execute process serially |
| 113 | + chunksToProcess = node.chunks |
| 114 | + |
| 115 | +logging.info(f"[MeshroomCreateChunks] Chunks to process here : {chunksToProcess}") |
| 116 | + |
| 117 | +if not args.forceStatus and not args.forceCompute: |
| 118 | + for chunk in chunksToProcess: |
| 119 | + if chunk.status.status in submittedStatuses: |
| 120 | + # Particular case for the local isolated, the node status is set to RUNNING by the submitter directly. |
| 121 | + # We ensure that no other instance has started to compute, by checking that the sessicomputeSessionUidonUid is empty. |
| 122 | + if chunk.node.getMrNodeType() == meshroom.core.MrNodeType.NODE and \ |
| 123 | + not chunk.status.computeSessionUid and node._nodeStatus.submitterSessionUid: |
| 124 | + continue |
| 125 | + logging.warning( |
| 126 | + f"[MeshroomCreateChunks] Node is already submitted with status " \ |
| 127 | + f"\"{chunk.status.status.name}\". See file: \"{chunk.statusFile}\". " \ |
| 128 | + f"ExecMode: {chunk.status.execMode.name}, computeSessionUid: {chunk.status.computeSessionUid}, " \ |
| 129 | + f"submitterSessionUid: {node._nodeStatus.submitterSessionUid}") |
| 130 | + |
| 131 | +if chunksToProcess: |
| 132 | + node.prepareLogger() |
| 133 | + node.preprocess() |
| 134 | + for chunk in chunksToProcess: |
| 135 | + logging.info(f"[MeshroomCreateChunks] process chunk {chunk}") |
| 136 | + chunk.process(args.forceCompute, args.inCurrentEnv) |
| 137 | + node.postprocess() |
| 138 | + node.restoreLogger() |
| 139 | +else: |
| 140 | + logging.info(f"[MeshroomCreateChunks] -> create job to process chunks {node.chunks}") |
| 141 | + submitter.createChunkTask(node, graphFile=args.graphFile, cache=args.cache, |
| 142 | + forceStatus=args.forceStatus, forceCompute=args.forceCompute) |
| 143 | + |
| 144 | +# Restore the log level |
| 145 | +logging.getLogger().setLevel(meshroom.logStringToPython[args.verbose]) |
0 commit comments