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; } }
private SolutionType readSolutionType(Path odeTypePath) { try { final List<String> type = Files.readAllLines(odeTypePath); checkState(type.size() == 1); return SolutionType.valueOf(type.get(0)); } catch (IOException e) { throw new RuntimeException(e); } }