forked from nest/nestml
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'clinssen/symboltable_checks' into nestm…
…l_include
- Loading branch information
Showing
46 changed files
with
2,037 additions
and
1,291 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
on: | ||
pull_request_target: | ||
types: [opened, reopened, edited, synchronize] | ||
|
||
jobs: | ||
fork_pr_requires_review: | ||
environment: ${{ (github.event.pull_request.head.repo.full_name == github.repository && 'internal') || 'external' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: true | ||
|
||
benchmark_fork_pr_branch: | ||
needs: fork_pr_requires_review | ||
name: Continuous Benchmarking Fork PRs with Bencher | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
persist-credentials: false | ||
|
||
- uses: bencherdev/bencher@main | ||
|
||
# Setup Python version | ||
- name: Setup Python 3.8 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.8 | ||
|
||
# Install dependencies | ||
- name: Install apt dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install libltdl7-dev libgsl0-dev libncurses5-dev libreadline6-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 pandas pytest-benchmark | ||
python -m pip install -r requirements.txt | ||
# Install NEST simulator | ||
- name: NEST simulator | ||
run: | | ||
python -m pip install cython | ||
echo "GITHUB_WORKSPACE = $GITHUB_WORKSPACE" | ||
NEST_SIMULATOR=$(pwd)/nest-simulator | ||
NEST_INSTALL=$(pwd)/nest_install | ||
echo "NEST_SIMULATOR = $NEST_SIMULATOR" | ||
echo "NEST_INSTALL = $NEST_INSTALL" | ||
git clone --depth=1 https://github.com/nest/nest-simulator | ||
mkdir nest_install | ||
echo "NEST_INSTALL=$NEST_INSTALL" >> $GITHUB_ENV | ||
cd nest_install | ||
cmake -DCMAKE_INSTALL_PREFIX=$NEST_INSTALL $NEST_SIMULATOR | ||
make && make install | ||
cd .. | ||
# Install NESTML (repeated) | ||
- 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: Track Fork PR Benchmarks with Bencher | ||
env: | ||
LD_LIBRARY_PATH: ${{ env.NEST_INSTALL }}/lib/nest | ||
run: | | ||
echo "NEST_INSTALL = $NEST_INSTALL" | ||
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{ env.NEST_INSTALL }}/lib/nest bencher run \ | ||
--project nestml \ | ||
--token '${{ secrets.BENCHER_API_TOKEN }}' \ | ||
--branch '${{ github.event.number }}/merge' \ | ||
--branch-start-point '${{ github.base_ref }}' \ | ||
--branch-start-point-hash '${{ github.event.pull_request.base.sha }}' \ | ||
--branch-reset \ | ||
--github-actions "${{ secrets.GITHUB_TOKEN }}" \ | ||
--testbed ubuntu-latest \ | ||
--adapter python_pytest \ | ||
--file results.json \ | ||
--err \ | ||
'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{ env.NEST_INSTALL }}/lib/nest python3 -m pytest --benchmark-json results.json -s $GITHUB_WORKSPACE/tests/nest_continuous_benchmarking/test_nest_continuous_benchmarking.py' | ||
- name: Setup tmate session | ||
if: ${{ failure() }} | ||
uses: mxschmitt/action-tmate@v3 |
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
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
73 changes: 73 additions & 0 deletions
73
pynestml/cocos/co_co_nest_random_functions_legally_used.py
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# co_co_nest_random_functions_legally_used.py | ||
# | ||
# This file is part of NEST. | ||
# | ||
# Copyright (C) 2004 The NEST Initiative | ||
# | ||
# NEST is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# NEST is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# 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.cocos.co_co import CoCo | ||
from pynestml.meta_model.ast_model import ASTModel | ||
from pynestml.meta_model.ast_node import ASTNode | ||
from pynestml.meta_model.ast_on_condition_block import ASTOnConditionBlock | ||
from pynestml.meta_model.ast_on_receive_block import ASTOnReceiveBlock | ||
from pynestml.meta_model.ast_update_block import ASTUpdateBlock | ||
from pynestml.symbols.predefined_functions import PredefinedFunctions | ||
from pynestml.utils.logger import LoggingLevel, Logger | ||
from pynestml.utils.messages import Messages | ||
from pynestml.visitors.ast_visitor import ASTVisitor | ||
|
||
|
||
class CoCoNestRandomFunctionsLegallyUsed(CoCo): | ||
""" | ||
This CoCo ensure that the random functions are used only in the ``update``, ``onReceive``, and ``onCondition`` blocks. | ||
This CoCo is only checked for the NEST Simulator target. | ||
""" | ||
|
||
@classmethod | ||
def check_co_co(cls, node: ASTNode): | ||
""" | ||
Checks the coco. | ||
:param node: a single node (typically, a neuron or synapse) | ||
""" | ||
visitor = CoCoNestRandomFunctionsLegallyUsedVisitor() | ||
visitor.neuron = node | ||
node.accept(visitor) | ||
|
||
|
||
class CoCoNestRandomFunctionsLegallyUsedVisitor(ASTVisitor): | ||
def visit_function_call(self, node): | ||
""" | ||
Visits a function call | ||
:param node: a function call | ||
""" | ||
function_name = node.get_name() | ||
if function_name == PredefinedFunctions.RANDOM_NORMAL or function_name == PredefinedFunctions.RANDOM_UNIFORM \ | ||
or function_name == PredefinedFunctions.RANDOM_POISSON: | ||
parent = node | ||
while parent: | ||
parent = parent.get_parent() | ||
|
||
if isinstance(parent, ASTUpdateBlock) or isinstance(parent, ASTOnReceiveBlock) \ | ||
or isinstance(parent, ASTOnConditionBlock): | ||
# the random function is correctly defined, hence return | ||
return | ||
|
||
if isinstance(parent, ASTModel): | ||
# the random function is defined in other blocks (parameters, state, internals). Hence, an error. | ||
code, message = Messages.get_random_functions_legally_used(function_name) | ||
Logger.log_message(node=self.neuron, code=code, message=message, error_position=node.get_source_position(), | ||
log_level=LoggingLevel.ERROR) |
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
Oops, something went wrong.