Skip to content

Commit

Permalink
Fix NEST-Desktop code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbabu committed Jul 15, 2024
1 parent 1a47ef6 commit de139f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions pynestml/codegeneration/nest_desktop_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@
from typing import Sequence, Union, Optional, Mapping, Any, Dict

from pynestml.codegeneration.code_generator import CodeGenerator
from pynestml.codegeneration.code_generator_utils import CodeGeneratorUtils
from pynestml.frontend.frontend_configuration import FrontendConfiguration
from pynestml.meta_model.ast_neuron import ASTNeuron
from pynestml.meta_model.ast_synapse import ASTSynapse
from pynestml.meta_model.ast_model import ASTModel


class NESTDesktopCodeGenerator(CodeGenerator):
"""
Code generator for NEST Desktop
"""
_default_options = {
"neuron_models": [],
"synapse_models": [],
"templates": {
"path": "",
"path": "resources_nest_desktop",
"model_templates": {
"neuron": ["@[email protected]"],
}
Expand All @@ -45,19 +47,17 @@ def __init__(self, options: Optional[Mapping[str, Any]] = None):
super().__init__(self._target, options)
self.setup_template_env()

def generate_code(self, models: Sequence[Union[ASTNeuron, ASTSynapse]]) -> None:
def generate_code(self, models: Sequence[ASTModel]) -> None:
"""
Generate the .json files for the given neuron and synapse models
:param models: list of neuron models
"""
if not os.path.isdir(FrontendConfiguration.get_target_path()):
os.makedirs(FrontendConfiguration.get_target_path())
neurons = [model for model in models if isinstance(model, ASTNeuron)]
synapses = [model for model in models if isinstance(model, ASTSynapse)]
neurons, synapses = CodeGeneratorUtils.get_model_types_from_names(models, neuron_models=self.get_option("neuron_models"),
synapse_models=self.get_option("synapse_models"))
self.generate_neurons(neurons)
self.generate_synapses(synapses)

def _get_neuron_model_namespace(self, neuron: ASTNeuron) -> Dict:
def _get_neuron_model_namespace(self, neuron: ASTModel) -> Dict:
"""
Returns a standard namespace with often required functionality.
:param neuron: a single neuron instance
Expand Down
10 changes: 5 additions & 5 deletions tests/nest_desktop_code_generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_nest_desktop_code_generator(self):
Test to generate the json file for NEST Desktop target for the given neuron model
"""
input_path = os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join(
os.pardir, "models", "neurons", "iaf_psc_exp.nestml"))))
os.pardir, "models", "neurons", "iaf_psc_exp_neuron.nestml"))))
target_path = "target_iaf"
target_platform = "NEST_DESKTOP"
generate_target(input_path=input_path,
Expand All @@ -47,17 +47,17 @@ def test_nest_desktop_code_generator(self):
logging_level="INFO")

# Read the parameters from the generated json file and match them with the actual values
with open(os.path.join(target_path, "iaf_psc_exp.json")) as f:
with open(os.path.join(target_path, "iaf_psc_exp_neuron.json")) as f:
data = f.read()
json_data = json.loads(data)
actual_params = {"C_m": "250.0",
"tau_m": "10.0",
"tau_syn_inh": "2.0",
"tau_syn_exc": "2.0",
"t_ref": "2.0",
"refr_T": "2.0",
"E_L": "-70.0",
"V_reset": "0.0",
"Theta": "15.0",
"V_reset": "-70.0",
"V_th": "-55.0",
"I_e": "0.0"}
for param_data in json_data["params"]:
_id = param_data["id"]
Expand Down

0 comments on commit de139f3

Please sign in to comment.