Skip to content

Commit

Permalink
Merge pull request #1059 from clinssen/generate_code_for_touch
Browse files Browse the repository at this point in the history
NESTCodeGeneratorUtils.generate_code_for() no longer touches source files on each call
  • Loading branch information
clinssen authored Jun 3, 2024
2 parents 076bd89 + 100be62 commit 99f32a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/nestml-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ jobs:
ipynb_fns=$(find $GITHUB_WORKSPACE/doc/tutorials -name '*.ipynb')
rc=0
for fn in $ipynb_fns; do
echo "Now running Jupyter notebook: ${fn}"
cd `dirname ${fn}`
ipython3 ${fn} || rc=1
ipython3 ${fn}
if [ $? -ne 0 ]; then
echo "Error running Jupyter notebook: ${fn}"
rc=1
fi
done;
cd $GITHUB_WORKSPACE
exit $rc
Expand Down
24 changes: 15 additions & 9 deletions pynestml/codegeneration/nest_code_generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,24 @@ def generate_code_for(cls,
-------
If a synapse is specified, returns a tuple (module_name, mangled_neuron_name, mangled_synapse_name) containing the names that can be used in ``nest.Install()``, ``nest.Create()`` and ``nest.Connect()`` calls. If no synapse is specified, returns a tuple (module_name, mangled_neuron_name).
"""

from pynestml.frontend.pynestml_frontend import generate_nest_target

# generate temporary install directory
install_path = tempfile.mkdtemp(prefix="nestml_target_")

# read neuron model from file?
if "\n" not in nestml_neuron_model and ".nestml" in nestml_neuron_model:
neuron_model_is_file_name: bool = "\n" not in nestml_neuron_model and ".nestml" in nestml_neuron_model
if neuron_model_is_file_name:
neuron_fn = nestml_neuron_model
with open(nestml_neuron_model, "r") as nestml_model_file:
nestml_neuron_model = nestml_model_file.read()

# update neuron model name inside the file
neuron_model_name = re.findall(r"model [^:\s]*:", nestml_neuron_model)[0][6:-1]
neuron_fn = neuron_model_name + ".nestml"
with open(neuron_fn, "w") as f:
print(nestml_neuron_model, file=f)
if not neuron_model_is_file_name:
neuron_fn = neuron_model_name + ".nestml"
with open(neuron_fn, "w") as f:
print(nestml_neuron_model, file=f)

input_fns = [neuron_fn]
_codegen_opts = {"neuron_parent_class": "StructuralPlasticityNode",
Expand All @@ -99,15 +101,19 @@ def generate_code_for(cls,

if nestml_synapse_model:
# read synapse model from file?
if "\n" not in nestml_synapse_model and ".nestml" in nestml_synapse_model:
synapse_model_is_file_name: bool = "\n" not in nestml_synapse_model and ".nestml" in nestml_synapse_model
if synapse_model_is_file_name:
synapse_fn = nestml_synapse_model
with open(nestml_synapse_model, "r") as nestml_model_file:
nestml_synapse_model = nestml_model_file.read()

# update synapse model name inside the file
synapse_model_name = re.findall(r"model [^:\s]*:", nestml_synapse_model)[0][6:-1]
synapse_fn = synapse_model_name + ".nestml"
with open(synapse_fn, "w") as f:
print(nestml_synapse_model, file=f)
if not synapse_model_is_file_name:
synapse_fn = synapse_model_name + ".nestml"
with open(synapse_fn, "w") as f:
print(nestml_synapse_model, file=f)

input_fns += [synapse_fn]
_codegen_opts["neuron_synapse_pairs"] = [{"neuron": neuron_model_name,
"synapse": synapse_model_name,
Expand Down

0 comments on commit 99f32a8

Please sign in to comment.