Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into gap_junctions
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Jul 3, 2023
2 parents 909196a + ff24afe commit db76555
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 20 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/nestml-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,73 @@ jobs:
run: |
python3 extras/codeanalysis/check_copyright_headers.py && python3 -m pycodestyle $GITHUB_WORKSPACE -v --ignore=E241,E501,E714,E713,E714,E252,W503 --exclude=$GITHUB_WORKSPACE/doc,$GITHUB_WORKSPACE/.git,$GITHUB_WORKSPACE/NESTML.egg-info,$GITHUB_WORKSPACE/pynestml/generated,$GITHUB_WORKSPACE/extras,$GITHUB_WORKSPACE/build,$GITHUB_WORKSPACE/.github
build_and_test_py_standalone:
needs: [static_checks]
runs-on: ubuntu-latest
steps:
# Checkout the repository contents
- name: Checkout NESTML code
uses: actions/checkout@v3

# Setup Python version
- name: Setup Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

# Install dependencies
- name: Install apt dependencies
run: |
sudo apt-get update
sudo apt-get install libgsl0-dev libncurses5-dev pkg-config
sudo apt-get install python3-all-dev python3-matplotlib python3-numpy python3-scipy ipython3
# Install Python dependencies
- name: Python dependencies
run: |
python -m pip install --upgrade pip pytest jupyterlab matplotlib pycodestyle scipy
python -m pip install -r requirements.txt
# Install Java
- name: Install Java 11
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11.0.x'
java-package: jre

# Install Antlr4
- name: Install Antlr4
run: |
wget http://www.antlr.org/download/antlr-4.10-complete.jar
echo \#\!/bin/bash > antlr4
echo java -cp \"`pwd`/antlr-4.10-complete.jar:$CLASSPATH\" org.antlr.v4.Tool \"\$@\" >> antlr4
echo >> antlr4
chmod +x antlr4
echo PATH=$PATH:`pwd` >> $GITHUB_ENV
# Install NESTML
- name: Install NESTML
run: |
export PYTHONPATH=${{ env.PYTHONPATH }}:${{ env.NEST_INSTALL }}/lib/python3.8/site-packages
#echo PYTHONPATH=`pwd` >> $GITHUB_ENV
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
python setup.py install
- name: Generate Lexer and Parser using Antlr4
run: |
cd pynestml/grammars
./generate_lexer_parser
# Run integration tests
- name: Run integration tests
run: |
rc=0
for fn in $GITHUB_WORKSPACE/tests/python_standalone_tests/*.py; do
pytest -s -o log_cli=true -o log_cli_level="DEBUG" ${fn} || rc=1
done;
exit $rc
build_and_test:
needs: [static_checks]
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions pynestml/codegeneration/printers/nest_variable_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self, expression_printer: ExpressionPrinter, with_origin: bool = Tr
super().__init__(expression_printer)
self.with_origin = with_origin
self.with_vector_parameter = with_vector_parameter
self._state_symbols = []

def print_variable(self, variable: ASTVariable) -> str:
"""
Expand Down Expand Up @@ -159,8 +158,6 @@ def _print_buffer_value(self, variable: ASTVariable) -> str:
return variable_symbol.get_symbol_name() + '_grid_sum_'

def _print(self, variable: ASTVariable, symbol, with_origin: bool = True) -> str:
assert all([type(s) == str for s in self._state_symbols])

variable_name = CppVariablePrinter._print_cpp_name(variable.get_complete_name())

if symbol.is_local():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def print_variable(self, node: ASTVariable) -> str:
symbol = node.get_scope().resolve_to_symbol(node.get_complete_name(), SymbolKind.VARIABLE)

if symbol.is_state() and not symbol.is_inline_expression:
if node.get_complete_name() in self._state_symbols:
if "_is_numeric" in dir(node) and node._is_numeric:
# ode_state[] here is---and must be---the state vector supplied by the integrator, not the state vector in the node, node.S_.ode_state[].
return "ode_state[node.S_.ode_state_variable_name_to_index[\"" + CppVariablePrinter._print_cpp_name(node.get_complete_name()) + "\"]]"

Expand Down
3 changes: 0 additions & 3 deletions pynestml/codegeneration/printers/python_variable_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(self, expression_printer: ExpressionPrinter, with_origin: bool = Tr
super().__init__(expression_printer)
self.with_origin = with_origin
self.with_vector_parameter = with_vector_parameter
self._state_symbols = []

@classmethod
def _print_python_name(cls, variable_name: str) -> str:
Expand Down Expand Up @@ -146,8 +145,6 @@ def _print_vector_parameter_name_reference(self, variable: ASTVariable) -> str:
return self._expression_printer.print(vector_parameter)

def _print(self, variable, symbol, with_origin: bool = True) -> str:
assert all([type(s) == str for s in self._state_symbols])

variable_name = PythonVariablePrinter._print_python_name(variable.get_complete_name())

if symbol.is_local():
Expand Down
5 changes: 3 additions & 2 deletions pynestml/codegeneration/python_code_generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

from pynestml.meta_model.ast_variable import ASTVariable
from pynestml.symbols.variable_symbol import VariableSymbol
from pynestml.symbols.variable_symbol import BlockType


class PythonCodeGeneratorUtils:

@classmethod
def print_symbol_origin(cls, variable_symbol: VariableSymbol) -> str:
def print_symbol_origin(cls, variable_symbol: VariableSymbol, variable: ASTVariable) -> str:
"""
Returns a prefix corresponding to the origin of the variable symbol.
:param variable_symbol: a single variable symbol.
:return: the corresponding prefix
"""
if variable_symbol.block_type in [BlockType.STATE, BlockType.EQUATION]:
if numerical_state_symbols and variable_symbol.get_symbol_name() in numerical_state_symbols:
if "_is_numeric" in dir(variable) and variable._is_numeric:
return 'self.S_.ode_state[self.S_.ode_state_variable_name_to_index["%s"]]'

return 'self.S_.%s'
Expand Down
3 changes: 2 additions & 1 deletion pynestml/codegeneration/python_standalone_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class PythonStandaloneCodeGenerator(NESTCodeGenerator):
"neuron": ["@NEURON_NAME@.py.jinja2"]
},
"module_templates": ["simulator.py.jinja2", "test_python_standalone_module.py.jinja2", "neuron.py.jinja2", "spike_generator.py.jinja2", "utils.py.jinja2"]
}
},
"solver": "analytic"
}

def __init__(self, options: Optional[Mapping[str, Any]] = None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ void {{neuronName}}::handle(nest::DataLoggingRequest& e)
void {{neuronName}}::handle(nest::SpikeEvent &e)
{
assert(e.get_delay_steps() > 0);
assert( e.get_rport() < static_cast< int >( B_.spike_inputs_.size() ) );
assert( e.get_rport() < B_.spike_inputs_.size() );

double weight = e.get_weight();
size_t nestml_buffer_idx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ public:
/**
* Used to validate that we can send {{ output_event.OutputEvent() }} to desired target:port.
**/
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
size_t send_test_event(nest::Node& target, size_t receptor_type, nest::synindex, bool) override;
{%- else %}
nest::port send_test_event(nest::Node& target, nest::rport receptor_type, nest::synindex, bool) override;
{%- endif %}

// -------------------------------------------------------------------------
// Functions handling incoming events.
Expand All @@ -261,6 +265,7 @@ public:

void handle(nest::DataLoggingRequest &) override;//! allow recording with multimeter

<<<<<<< HEAD
{%- if use_gap_junctions %}
void handle( nest::GapJunctionEvent& ) override;
nest::port handles_test_event( nest::GapJunctionEvent&, nest::rport ) override;
Expand All @@ -270,7 +275,27 @@ public:

{%- endif %}

=======
{%- if has_spike_input %}
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
size_t handles_test_event(nest::SpikeEvent&, size_t) override;
{%- else %}
nest::port handles_test_event(nest::SpikeEvent&, nest::port) override;
{%- endif %}
{%- endif %}
{%- if has_continuous_input %}
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
size_t handles_test_event(nest::CurrentEvent&, size_t) override;
{%- else %}
nest::port handles_test_event(nest::CurrentEvent&, nest::port) override;
{%- endif %}
{%- endif %}
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
size_t handles_test_event(nest::DataLoggingRequest&, size_t) override;
{%- else %}
>>>>>>> upstream/master
nest::port handles_test_event(nest::DataLoggingRequest&, nest::port) override;
{%- endif %}

// -------------------------------------------------------------------------
// Functions for getting/setting parameters and state values.
Expand Down Expand Up @@ -409,13 +434,25 @@ private:
* @note Excluded lower and upper bounds are defined as MIN_, MAX_.
* Excluding port 0 avoids accidental connections.
**/
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
static const size_t MIN_SPIKE_RECEPTOR = 1;
{%- else %}
static const nest::port MIN_SPIKE_RECEPTOR = 1;
{%- endif %}
{%- set ns = namespace(count=1) %}
{%- else %}
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
static const size_t MIN_SPIKE_RECEPTOR = 0;
{%- else %}
static const nest::port MIN_SPIKE_RECEPTOR = 0;
{%- endif %}
{%- set ns = namespace(count=0) %}
{%- endif %}
{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
static const size_t PORT_NOT_AVAILABLE = -1;
{%- else %}
static const nest::port PORT_NOT_AVAILABLE = -1;
{%- endif %}

enum SynapseTypes
{
Expand Down Expand Up @@ -817,7 +854,11 @@ private:

}; /* neuron {{neuronName}} */

{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
inline size_t {{neuronName}}::send_test_event(nest::Node& target, size_t receptor_type, nest::synindex, bool)
{%- else %}
inline nest::port {{neuronName}}::send_test_event(nest::Node& target, nest::rport receptor_type, nest::synindex, bool)
{%- endif %}
{
// You should usually not change the code in this function.
// It confirms that the target of connection @c c accepts @c {{ output_event.OutputEvent() }} on
Expand All @@ -828,7 +869,11 @@ inline nest::port {{neuronName}}::send_test_event(nest::Node& target, nest::rpor
}
{%- if has_spike_input %}

{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
inline size_t {{neuronName}}::handles_test_event(nest::SpikeEvent&, size_t receptor_type)
{%- else %}
inline nest::port {{neuronName}}::handles_test_event(nest::SpikeEvent&, nest::port receptor_type)
{%- endif %}
{
{%- if (neuron.get_multiple_receptors())|length > 1 or neuron.is_multisynapse_spikes() %}
assert( B_.spike_inputs_.size() == NUM_SPIKE_RECEPTORS );
Expand All @@ -852,7 +897,11 @@ inline nest::port {{neuronName}}::handles_test_event(nest::SpikeEvent&, nest::po
{%- endif %}
{%- if has_continuous_input %}

{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
inline size_t {{neuronName}}::handles_test_event(nest::CurrentEvent&, size_t receptor_type)
{%- else %}
inline nest::port {{neuronName}}::handles_test_event(nest::CurrentEvent&, nest::port receptor_type)
{%- endif %}
{
// You should usually not change the code in this function.
// It confirms to the connection management system that we are able
Expand All @@ -866,7 +915,11 @@ inline nest::port {{neuronName}}::handles_test_event(nest::CurrentEvent&, nest::
}
{%- endif %}

{%- if not (nest_version.startswith("v2") or nest_version.startswith("v3.0") or nest_version.startswith("v3.1") or nest_version.startswith("v3.2") or nest_version.startswith("v3.3") or nest_version.startswith("v3.4")) %}
inline size_t {{neuronName}}::handles_test_event(nest::DataLoggingRequest& dlr, size_t receptor_type)
{%- else %}
inline nest::port {{neuronName}}::handles_test_event(nest::DataLoggingRequest& dlr, nest::port receptor_type)
{%- endif %}
{
// You should usually not change the code in this function.
// It confirms to the connection management system that we are able
Expand Down
Loading

0 comments on commit db76555

Please sign in to comment.