diff --git a/pynestml/codegeneration/nest_desktop_code_generator.py b/pynestml/codegeneration/nest_desktop_code_generator.py index 1eaca5f45..6983888c5 100644 --- a/pynestml/codegeneration/nest_desktop_code_generator.py +++ b/pynestml/codegeneration/nest_desktop_code_generator.py @@ -22,9 +22,9 @@ 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): @@ -32,8 +32,10 @@ class NESTDesktopCodeGenerator(CodeGenerator): Code generator for NEST Desktop """ _default_options = { + "neuron_models": [], + "synapse_models": [], "templates": { - "path": "", + "path": "resources_nest_desktop", "model_templates": { "neuron": ["@NEURON_NAME@.json.jinja2"], } @@ -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 diff --git a/tests/nest_desktop_code_generator_test.py b/tests/nest_desktop_code_generator_test.py index f1c39e364..7c2e1a551 100644 --- a/tests/nest_desktop_code_generator_test.py +++ b/tests/nest_desktop_code_generator_test.py @@ -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, @@ -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"]