public ASTNESTMLCompilationUnit process( final ASTNESTMLCompilationUnit root, final Path outputBase) { checkState(root.getNeurons().size() > 0); final ASTNeuron neuron = root.getNeurons().get(0); final ASTBodyDecorator astBodyDecorator = new ASTBodyDecorator(neuron.getBody()); if (astBodyDecorator.getOdeDefinition().isPresent()) { return handleNeuronWithODE(root, outputBase); } else { return root; } }
private ASTNESTMLCompilationUnit handleNeuronWithODE( final ASTNESTMLCompilationUnit root, final Path outputBase) { final Optional<Path> generatedScript = SymPyScriptGenerator.generateSympyODEAnalyzer(root.getNeurons().get(0), outputBase); checkState(generatedScript.isPresent()); final SymPyScriptEvaluator evaluator = new SymPyScriptEvaluator(); boolean successfulExecution = evaluator.execute(generatedScript.get()); checkState(successfulExecution, "Error during solver script evaluation."); final Path odeTypePath = Paths.get(outputBase.toString(), SymPyScriptEvaluator.ODE_TYPE); final SolutionType solutionType = readSolutionType(odeTypePath); if (solutionType.equals(SolutionType.exact)) { info("ODE is solved exactly.", LOG_NAME); final ASTNESTMLCompilationUnit transformedModel = explicitSolutionTransformer.replaceODEWithSymPySolution( root, Paths.get(outputBase.toString(), SymPyScriptEvaluator.P30_FILE), Paths.get(outputBase.toString(), SymPyScriptEvaluator.PSC_INITIAL_VALUE_FILE), Paths.get(outputBase.toString(), SymPyScriptEvaluator.STATE_VECTOR_FILE), Paths.get(outputBase.toString(), SymPyScriptEvaluator.UPDATE_STEP_FILE)); return transformedModel; } else { info("ODE is solved numerically.", LOG_NAME); return root; } }