-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from NeuroML/feat/sim-meta
Expose `meta` in LEMSSimulation
- Loading branch information
Showing
3 changed files
with
112 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,51 @@ | ||
<Lems> | ||
|
||
#if ($comment)## | ||
<!-- ${comment} --> | ||
#end## | ||
|
||
#end## | ||
<!-- Specify which component to run --> | ||
<Target component="${sim_id}"${report}/> | ||
|
||
<!-- Include core NeuroML2 ComponentType definitions --> | ||
<Include file="Cells.xml"/> | ||
<Include file="Networks.xml"/> | ||
<Include file="Simulation.xml"/> | ||
|
||
#foreach ($include_file in $include_files)## | ||
<Include file="${include_file}"/> | ||
#end## | ||
#end## | ||
|
||
#set( $start = -0.1 * $duration ) | ||
#set( $end = 1.1 * $duration ) | ||
<Simulation id="${sim_id}" length="${duration}ms" step="${dt}ms" target="${target}" seed="${seed}"> <!-- Note seed: ensures same random numbers used every run --> | ||
|
||
#if ($meta)## | ||
<Meta for="${meta.for}" method="${meta.method}" abs_tolerance="${meta.abs_tolerance}" rel_tolerance="${meta.rel_tolerance}"/> | ||
#end## | ||
#foreach ($display in $displays)## | ||
<Display id="${display.id}" title="${display.title}" timeScale="${display.time_scale}" xmin="$start" xmax="$end" ymin="${display.ymin}" ymax="${display.ymax}"> | ||
#foreach ($line in $display.lines)## | ||
<Line id="${line.id}" quantity="${line.quantity}" scale="${line.scale}" color="${line.color}" timeScale="${line.time_scale}"/> | ||
#end## | ||
#end## | ||
</Display> | ||
#end## | ||
|
||
#end## | ||
#foreach ($output_file in $output_files)## | ||
<OutputFile id="${output_file.id}" fileName="${output_file.file_name}"> | ||
#foreach ($column in $output_file.columns)## | ||
<OutputColumn id="${column.id}" quantity="${column.quantity}"/> | ||
#end## | ||
<OutputColumn id="${column.id}" quantity="${column.quantity}"/> | ||
#end## | ||
</OutputFile> | ||
#end## | ||
|
||
#end## | ||
#foreach ($event_output_file in $event_output_files)## | ||
<EventOutputFile id="${event_output_file.id}" fileName="${event_output_file.file_name}" format="${event_output_file.format}"> | ||
#foreach ($selection in $event_output_file.selections)## | ||
<EventSelection id="${selection.id}" select="${selection.select}" eventPort="${selection.event_port}"/> | ||
#end## | ||
<EventSelection id="${selection.id}" select="${selection.select}" eventPort="${selection.event_port}"/> | ||
#end## | ||
</EventOutputFile> | ||
#end## | ||
|
||
#end## | ||
</Simulation> | ||
|
||
</Lems> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Test the LEMSSimulation class | ||
File: tests/lems/test_lemssimulation.py | ||
Copyright 2023 NeuroML contributors | ||
Author: Ankur Sinha <sanjay DOT ankur AT gmail DOT com> | ||
""" | ||
|
||
import logging | ||
import pathlib as pl | ||
import unittest | ||
|
||
import pytest | ||
from pyneuroml.lems import LEMSSimulation | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
class TestLEMSSimulation(unittest.TestCase): | ||
|
||
"""Test the LEMSSimulation class""" | ||
|
||
def test_lemssimulation_meta(self): | ||
"""Test the LEMSSimulation class.""" | ||
# Create a simulation instance of the model | ||
simulation_id = "tests-sim" | ||
simulation = LEMSSimulation( | ||
sim_id=simulation_id, | ||
duration=1000, | ||
dt=0.1, | ||
simulation_seed=123, | ||
meta={ | ||
"for": "neuron", | ||
"method": "cvode", | ||
"abs_tolerance": "0.0001", | ||
"rel_tolerance": "0.0004", | ||
}, | ||
) | ||
simulation.assign_simulation_target("some_network") | ||
# Save the simulation to a file | ||
lems_simulation_file = simulation.save_to_file() | ||
|
||
expected_string = '<Meta for="neuron" method="cvode" abs_tolerance="0.0001" rel_tolerance="0.0004"/>' | ||
|
||
with open(lems_simulation_file, "r") as f: | ||
self.assertIn(expected_string, f.read()) | ||
|
||
pl.Path(lems_simulation_file).unlink() | ||
|
||
@pytest.mark.xfail | ||
def test_lemssimulation_meta_should_fail(self): | ||
"""Test without meta to ensure it's not always added""" | ||
# Create a simulation instance of the model | ||
simulation_id = "tests-sim-failure" | ||
simulation = LEMSSimulation( | ||
sim_id=simulation_id, | ||
duration=1000, | ||
dt=0.1, | ||
simulation_seed=123, | ||
) | ||
simulation.assign_simulation_target("some_network") | ||
# Save the simulation to a file | ||
lems_simulation_file = simulation.save_to_file() | ||
|
||
expected_string = '<Meta for="neuron" method="cvode" abs_tolerance="0.0001" rel_tolerance="0.0004"/>' | ||
|
||
with open(lems_simulation_file, "r") as f: | ||
self.assertIn(expected_string, f.read()) | ||
|
||
pl.Path(lems_simulation_file).unlink() |