|
| 1 | +import os |
| 2 | +import subprocess as sp |
| 3 | + |
| 4 | +from omv.engines.brian2_ import Brian2Engine |
| 5 | +from omv.engines.pynn import PyNNEngine |
| 6 | + |
| 7 | +from omv.common.inout import inform, trim_path, check_output, is_verbose |
| 8 | +from omv.engines.engine import EngineExecutionError |
| 9 | + |
| 10 | + |
| 11 | +class PyNNBrian2Engine(PyNNEngine): |
| 12 | + |
| 13 | + name = "PyNN_Brian2" |
| 14 | + python3_compatible = Brian2Engine.python3_compatible |
| 15 | + |
| 16 | + @staticmethod |
| 17 | + def is_installed(): |
| 18 | + if is_verbose(): |
| 19 | + inform("Checking whether %s is installed..." % |
| 20 | + PyNNBrian2Engine.name, indent=1) |
| 21 | + return PyNNEngine.is_installed() and Brian2Engine.is_installed() |
| 22 | + |
| 23 | + @staticmethod |
| 24 | + def install(version): |
| 25 | + if not Brian2Engine.is_installed(): |
| 26 | + Brian2Engine.install(version) # interpret version as version of Brian! |
| 27 | + inform("%s installed Brian..." % PyNNBrian2Engine.name, indent=2, verbosity =1) |
| 28 | + if not PyNNEngine.is_installed(): |
| 29 | + PyNNEngine.install(None) |
| 30 | + inform("%s installed PyNN..." % PyNNBrian2Engine.name, indent=2, verbosity =1) |
| 31 | + |
| 32 | + PyNNBrian2Engine.path = PyNNEngine.path + \ |
| 33 | + ":" + Brian2Engine.path |
| 34 | + PyNNBrian2Engine.environment_vars = {} |
| 35 | + PyNNBrian2Engine.environment_vars.update( |
| 36 | + PyNNEngine.environment_vars) |
| 37 | + PyNNBrian2Engine.environment_vars.update( |
| 38 | + Brian2Engine.environment_vars) |
| 39 | + inform("PATH: " + PyNNBrian2Engine.path) |
| 40 | + |
| 41 | + |
| 42 | + def run(self): |
| 43 | + try: |
| 44 | + inform("Running file %s with %s" % (trim_path(self.modelpath), self.name), indent=1) |
| 45 | + self.stdout = check_output(['python', self.modelpath, 'brian2'], |
| 46 | + cwd=os.path.dirname(self.modelpath)) |
| 47 | + self.returncode = 0 |
| 48 | + except sp.CalledProcessError as err: |
| 49 | + self.returncode = err.returncode |
| 50 | + self.stdout = err.output |
| 51 | + raise EngineExecutionError |
| 52 | + except Exception as err: |
| 53 | + inform("Another error with running %s: "%self.name, err, indent=1) |
| 54 | + self.returncode = -1 |
| 55 | + self.stdout = "???" |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
0 commit comments