From: Anthony Geay Date: Tue, 27 Feb 2024 12:20:29 +0000 (+0100) Subject: [EDF29576] : before json management X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d056ecc219aba40f86cf0661611c2f243fa2d6bd;p=modules%2Fyacs.git [EDF29576] : before json management --- diff --git a/src/yacsloader/driver b/src/yacsloader/driver old mode 100755 new mode 100644 diff --git a/src/yacsloader/driver_internal.py b/src/yacsloader/driver_internal.py index 38f680431..9f9d727fb 100644 --- a/src/yacsloader/driver_internal.py +++ b/src/yacsloader/driver_internal.py @@ -28,95 +28,95 @@ my_runtime_yacs = None my_ior_ns = None def initializeSALOME(): - import SALOMERuntime - global my_runtime_yacs - if my_runtime_yacs: - return - salome.salome_init() - if my_ior_ns: - salome.naming_service.DumpIORInFile( my_ior_ns ) - flags = SALOMERuntime.RuntimeSALOME.UsePython + SALOMERuntime.RuntimeSALOME.UseCorba + SALOMERuntime.RuntimeSALOME.UseXml + SALOMERuntime.RuntimeSALOME.UseCpp + SALOMERuntime.RuntimeSALOME.UseSalome - SALOMERuntime.RuntimeSALOME.setRuntime( flags ) - my_runtime_yacs = SALOMERuntime.getSALOMERuntime() - anIOR = salome.orb.object_to_string ( salome.modulcat ) - aCatalog = my_runtime_yacs.loadCatalog( "session", anIOR ) - my_runtime_yacs.addCatalog( aCatalog ) + import SALOMERuntime + global my_runtime_yacs + if my_runtime_yacs: + return + salome.salome_init() + if my_ior_ns: + salome.naming_service.DumpIORInFile( my_ior_ns ) + flags = SALOMERuntime.RuntimeSALOME.UsePython + SALOMERuntime.RuntimeSALOME.UseCorba + SALOMERuntime.RuntimeSALOME.UseXml + SALOMERuntime.RuntimeSALOME.UseCpp + SALOMERuntime.RuntimeSALOME.UseSalome + SALOMERuntime.RuntimeSALOME.setRuntime( flags ) + my_runtime_yacs = SALOMERuntime.getSALOMERuntime() + anIOR = salome.orb.object_to_string ( salome.modulcat ) + aCatalog = my_runtime_yacs.loadCatalog( "session", anIOR ) + my_runtime_yacs.addCatalog( aCatalog ) def SALOMEInitializationNeeded(func): - def decaratedFunc(*args,**kwargs): - initializeSALOME() - return func(*args,**kwargs) - return decaratedFunc + def decaratedFunc(*args,**kwargs): + initializeSALOME() + return func(*args,**kwargs) + return decaratedFunc @SALOMEInitializationNeeded def loadGraph( xmlFileName ): - """ - Args: - ----- - xmlFileName : XML file containing YACS schema + """ + Args: + ----- + xmlFileName : XML file containing YACS schema - Returns - ------- + Returns + ------- - SALOMERuntime.SalomeProc : YACS graph instance - """ - import loader - l=loader.YACSLoader() - p=l.load( xmlFileName ) - return p + SALOMERuntime.SalomeProc : YACS graph instance + """ + import loader + l=loader.YACSLoader() + p=l.load( xmlFileName ) + return p def patchGraph( proc, squeezeMemory, initPorts, xmlSchema, loadStateXmlFile, reset, display): + """ + Args: + ----- + + proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated + squeezeMemory ( bool ) : squeezememory to be activated + initPorts (list) : list of bloc.node.port=value. + xmlSchema (string) : + loadStateXmlFile (string) : file if any of state to be loaded inside proc + reset (int) : + display (int) : + """ + import SALOMERuntime + import loader + def parse_init_port(input): """ - Args: - ----- - - proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated - squeezeMemory ( bool ) : squeezememory to be activated - initPorts (list) : list of bloc.node.port=value. - xmlSchema (string) : - loadStateXmlFile (string) : file if any of state to be loaded inside proc - reset (int) : - display (int) : + Returns + ------- + node, port, value """ - import SALOMERuntime - import loader - def parse_init_port(input): - """ - Returns - ------- - node, port, value - """ - node_port, value = input.split("=") - nodePortSpl = node_port.split(".") - port = nodePortSpl[-1] - node = ".".join( nodePortSpl[:-1] ) - return node,port,value - - if squeezeMemory: - logging.info("SqueezeMemory requested -> update proc") - allNodes = proc.getAllRecursiveNodes() - for node in allNodes: - if isinstance(proc,SALOMERuntime.PythonNode): - node.setSqueezeStatus( True ) - # - for initPort in initPorts: - node,port,value = parse_init_port(initPort) - init_state = proc.setInPortValue(node, port, value) - if init_state != value: - raise RuntimeError(f"Error on initialization of {initPort}") - # - if xmlSchema: - SALOMERuntime.VisitorSaveSalomeSchemaUnsafe(proc,xmlSchema) - pass - # - if loadStateXmlFile: - loader.loadState( proc, loadStateXmlFile ) - if reset > 0: - proc.resetState(reset) - proc.exUpdateState() - # - if display > 0: - proc.writeDotInFile("toto") + node_port, value = input.split("=") + nodePortSpl = node_port.split(".") + port = nodePortSpl[-1] + node = ".".join( nodePortSpl[:-1] ) + return node,port,value + + if squeezeMemory: + logging.info("SqueezeMemory requested -> update proc") + allNodes = proc.getAllRecursiveNodes() + for node in allNodes: + if isinstance(proc,SALOMERuntime.PythonNode): + node.setSqueezeStatus( True ) + # + for initPort in initPorts: + node,port,value = parse_init_port(initPort) + init_state = proc.setInPortValue(node, port, value) + if init_state != value: + raise RuntimeError(f"Error on initialization of {initPort}") + # + if xmlSchema: + SALOMERuntime.VisitorSaveSalomeSchemaUnsafe(proc,xmlSchema) + pass + # + if loadStateXmlFile: + loader.loadState( proc, loadStateXmlFile ) + if reset > 0: + proc.resetState(reset) + proc.exUpdateState() + # + if display > 0: + proc.writeDotInFile("toto") @SALOMEInitializationNeeded def prepareExecution(proc, isStop, dumpErrorFile): @@ -135,56 +135,80 @@ def prepareExecution(proc, isStop, dumpErrorFile): @SALOMEInitializationNeeded def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, shutdown ): - """ - Args: - ----- - - executor (pilot.ExecutorSwig) : Executor in charge of evaluation. - proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated - xmlfilename (string) - dump (int) : time interval between 2 dump state - finalDump ( string ) : filename containing final result of graph, if any. - display (int) : - shutdown (int) : shutdown level - """ - import SALOMERuntime - dump_thread = None - import pilot - import os - - if dump != 0: - dumpFile = "dumpState_{}".format( os.path.basename(xmlfilename) ) - lockFile = "{}.lock".format( os.path.splitext( os.path.basename(xmlfilename) )[0] ) - dump_thread = SALOMERuntime.ThreadDumpState(proc,dump,dumpFile,lockFile) - dump_thread.start() - - executor.RunPy(proc,display,isPyThread=True,fromscratch=True) # same as RunW but releasing GIL - if proc.getEffectiveState() != pilot.DONE: - raise RuntimeError( proc.getErrorReport() ) - # - if display > 0: - proc.writeDotInFile("titi") - # - if dump_thread: - dump_thread.join() - # - if finalDump: - logging.info(f"Final dump requested : {finalDump}") - SALOMERuntime.schemaSaveStateUnsafe( proc, finalDump ) + """ + Args: + ----- + + executor (pilot.ExecutorSwig) : Executor in charge of evaluation. + proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated + xmlfilename (string) + dump (int) : time interval between 2 dump state + finalDump ( string ) : filename containing final result of graph, if any. + display (int) : + shutdown (int) : shutdown level + """ + import SALOMERuntime + dump_thread = None + import pilot + import os + + if dump != 0: + dumpFile = "dumpState_{}".format( os.path.basename(xmlfilename) ) + lockFile = "{}.lock".format( os.path.splitext( os.path.basename(xmlfilename) )[0] ) + dump_thread = SALOMERuntime.ThreadDumpState(proc,dump,dumpFile,lockFile) + dump_thread.start() + + executor.RunPy(proc,display,isPyThread=True,fromscratch=True) # same as RunW but releasing GIL + if proc.getEffectiveState() != pilot.DONE: + raise RuntimeError( proc.getErrorReport() ) + # + if display > 0: + proc.writeDotInFile("titi") + # + if dump_thread: + dump_thread.join() + # + if finalDump: + logging.info(f"Final dump requested : {finalDump}") + SALOMERuntime.schemaSaveStateUnsafe( proc, finalDump ) @SALOMEInitializationNeeded def destroyElementsGeneratedByExecutionOfGraph( proc, shutdown ): - """ - Args: - ----- + """ + Args: + ----- - shutdown (int) : shutdown level + shutdown (int) : shutdown level - """ - if shutdown < 999: - proc.shutdown(shutdown) - salome.dsm.shutdownScopes() - my_runtime_yacs.fini( False ) + """ + if shutdown < 999: + proc.shutdown(shutdown) + salome.dsm.shutdownScopes() + my_runtime_yacs.fini( False ) + +def reprAfterArgParsing( args ): + """ + Args: + ----- + + args (argparse.Namespace) : instance after parsing + """ + return f""" +display : {args.display} +verbose : {args.verbose} +stop-on-error : {args.stop} +dump-on-error : "{args.dumpErrorFile}" +dump : {args.dump} +kerneltrace : {args.kerneltrace} +dump-final : {args.finalDump} +load-state : {args.loadState} +save-xml-schema : {args.saveXMLSchema} +shutdown : {args.shutdown} +reset : {args.reset} +init-port : {args.init_port} +donotsqueeze : {args.donotsqueeze} +iorNS : {args.iorNS} +""" def getArgumentParser(): import argparse @@ -218,6 +242,7 @@ def mainRun( args ): setVerbose( args.kerneltrace ) setVerboseLevel(logging.INFO) positionVerbosityOfLoggerRegardingState() + logging.info( reprAfterArgParsing(args) ) # proc = loadGraph( args.xmlfilename ) patchGraph( proc, not args.donotsqueeze, [elt for elt in args.init_port.split(",") if elt !=""], args.saveXMLSchema, args.loadState, args.reset, args.display)