|
| 1 | +Running NESTML |
| 2 | +############## |
| 3 | + |
| 4 | +Running NESTML causes several processing steps to occur: |
| 5 | + |
| 6 | +1. The model is parsed from file and checked (syntax, consistent physical units, and so on). |
| 7 | +2. Code is generated from the model by one of the "code generators" selected when NESTML was invoked. |
| 8 | +3. If necessary, the code is compiled and built by the "builder" that belongs to the selected code generator. |
| 9 | + |
| 10 | +Currently, the following code generators are supported: |
| 11 | + |
| 12 | +* :doc:`NEST Simulator </running/running_nest>` |
| 13 | + |
| 14 | + .. figure:: https://raw.githubusercontent.com/nest/nestml/master/doc/fig/nest-simulator-logo.png |
| 15 | + :width: 95px |
| 16 | + :height: 40px |
| 17 | + :target: #nest-simulator-target |
| 18 | + |
| 19 | +* :doc:`Python-standalone </running/running_python_standalone>` |
| 20 | + |
| 21 | + .. figure:: https://raw.githubusercontent.com/nest/nestml/master/doc/fig/python-logo.png |
| 22 | + :width: 40px |
| 23 | + :height: 40px |
| 24 | + :target: #python-standalone-target |
| 25 | + |
| 26 | +* :doc:`SpiNNaker </running/running_spinnaker>` |
| 27 | + |
| 28 | + .. figure:: https://raw.githubusercontent.com/nest/nestml/master/doc/fig/spinnaker_logo.svg |
| 29 | + :width: 40px |
| 30 | + :height: 40px |
| 31 | + :target: #spinnaker-target |
| 32 | + |
| 33 | +.. warning:: |
| 34 | + |
| 35 | + To ensure correct and reproducible results, always inspect the generated code by hand. Run comprehensive numerical testing of the model(s). |
| 36 | + |
| 37 | + In case of doubt, please create a `GitHub Issue <https://github.com/nest/nestml/issues>`_ or write in on the `NEST mailing list <https://nest-simulator.readthedocs.io/en/latest/developer_space/guidelines/mailing_list_guidelines.html#mail-guidelines>`_. |
| 38 | + |
| 39 | + |
| 40 | +Running NESTML from Python |
| 41 | +-------------------------- |
| 42 | + |
| 43 | +NESTML can be imported as a Python package, and can therefore be used from within other Python tools and scripts. After PyNESTML has been installed, the following function has to be imported: |
| 44 | + |
| 45 | +.. code-block:: python |
| 46 | +
|
| 47 | + from pynestml.frontend.pynestml_frontend import generate_target |
| 48 | +
|
| 49 | +Subsequently, it is possible to call PyNESTML from other Python tools and scripts via calls to ``generate_target()``, which generates, builds and installs code for the target platform. ``generate_target()`` can be called as follows: |
| 50 | + |
| 51 | +.. code-block:: python |
| 52 | +
|
| 53 | + generate_target(input_path, target_platform, target_path, install_path, logging_level, module_name, store_log, suffix, dev, codegen_opts) |
| 54 | +
|
| 55 | +The following default values are used, corresponding to the command line defaults. Possible values for ``logging_level`` are the same as before ("DEBUG", "INFO", "WARNING", "ERROR", "NO"). Note that only the ``input_path`` argument is mandatory: |
| 56 | + |
| 57 | +.. list-table:: |
| 58 | + :header-rows: 1 |
| 59 | + :widths: 10 10 10 |
| 60 | + |
| 61 | + * - Argument |
| 62 | + - Type |
| 63 | + - Default |
| 64 | + * - input_path |
| 65 | + - str or Sequence[str] |
| 66 | + - *no default* |
| 67 | + * - target_platform |
| 68 | + - str |
| 69 | + - "NEST" |
| 70 | + * - target_path |
| 71 | + - str |
| 72 | + - None |
| 73 | + * - install_path |
| 74 | + - str |
| 75 | + - None |
| 76 | + * - logging_level |
| 77 | + - str |
| 78 | + - "ERROR" |
| 79 | + * - module_name |
| 80 | + - str |
| 81 | + - "nestmlmodule" |
| 82 | + * - suffix |
| 83 | + - str |
| 84 | + - "" |
| 85 | + * - store_log |
| 86 | + - bool |
| 87 | + - False |
| 88 | + * - dev |
| 89 | + - bool |
| 90 | + - False |
| 91 | + * - codegen_opts |
| 92 | + - Optional[Mapping[str, Any]] |
| 93 | + - (Optional) A JSON equivalent Python dictionary containing additional options for the target platform code generator. A list of available options can be found under the section "Code generation options" for your intended target platform on the page :ref:`Running NESTML`. |
| 94 | + |
| 95 | +For a detailed description of all the arguments of ``generate_target()``, see :func:`pynestml.frontend.pynestml_frontend.generate_target`. |
| 96 | + |
| 97 | +A typical script for the NEST Simulator target could look like the following. First, import the function: |
| 98 | + |
| 99 | +.. code-block:: python |
| 100 | +
|
| 101 | + from pynestml.frontend.pynestml_frontend import generate_target |
| 102 | +
|
| 103 | + generate_target(input_path="/home/nest/work/pynestml/models", |
| 104 | + target_platform="NEST", |
| 105 | + target_path="/tmp/nestml_target") |
| 106 | +
|
| 107 | +We can also use a shorthand function for each supported target platform (here, NEST): |
| 108 | + |
| 109 | +.. code-block:: python |
| 110 | +
|
| 111 | + from pynestml.frontend.pynestml_frontend import generate_nest_target |
| 112 | +
|
| 113 | + generate_nest_target(input_path="/home/nest/work/pynestml/models", |
| 114 | + target_path="/tmp/nestml_target") |
| 115 | +
|
| 116 | +To dynamically load a module with ``module_name`` equal to ``nestmlmodule`` (the default) in PyNEST can be done as follows: |
| 117 | + |
| 118 | +.. code-block:: python |
| 119 | +
|
| 120 | + nest.Install("nestmlmodule") |
| 121 | +
|
| 122 | +The NESTML models are then available for instantiation, for example as: |
| 123 | + |
| 124 | +.. code-block:: python |
| 125 | +
|
| 126 | + pre, post = nest.Create("neuron_nestml", 2) |
| 127 | + nest.Connect(pre, post, "one_to_one", syn_spec={"synapse_model": "synapse_nestml"}) |
| 128 | +
|
| 129 | +
|
| 130 | +Running NESTML from the command line |
| 131 | +------------------------------------ |
| 132 | + |
| 133 | +The toolchain can also be executed from the command line by running: |
| 134 | + |
| 135 | +.. code-block:: bash |
| 136 | +
|
| 137 | + nestml ARGUMENTS |
| 138 | +
|
| 139 | +This will generate, compile, build, and install the code for a set of specified NESTML models. The following arguments can be given, corresponding to the arguments in the command line invocation: |
| 140 | + |
| 141 | +.. list-table:: |
| 142 | + :header-rows: 1 |
| 143 | + :widths: 10 30 |
| 144 | + |
| 145 | + * - Command |
| 146 | + - Description |
| 147 | + * - ``-h`` or ``--help`` |
| 148 | + - Print help message. |
| 149 | + * - ``--input_path`` |
| 150 | + - One or more input path(s). Each path is a NESTML file, or a directory containing NESTML files. Directories will be searched recursively for files matching "\*.nestml". |
| 151 | + * - ``--target_path`` |
| 152 | + - (Optional) Path to target directory where generated code will be written into. Default is ``target``, which will be created in the current working directory if it does not yet exist. |
| 153 | + * - ``--target_platform`` |
| 154 | + - (Optional) The name of the target platform to generate code for. Default is ``NEST``. |
| 155 | + * - ``--logging_level`` |
| 156 | + - (Optional) Sets the logging level, i.e., which level of messages should be printed. Default is ERROR, available are [DEBUG, INFO, WARNING, ERROR, NO] |
| 157 | + * - ``--module_name`` |
| 158 | + - (Optional) Sets the name of the module which shall be generated. Default is the name of the directory containing the models. The name has to end in "module". Default is `nestmlmodule`. |
| 159 | + * - ``--store_log`` |
| 160 | + - (Optional) Stores a log.txt containing all messages in JSON notation. Default is OFF. |
| 161 | + * - ``--suffix`` |
| 162 | + - (Optional) A suffix string that will be appended to the name of all generated models. |
| 163 | + * - ``--install_path`` |
| 164 | + - (Optional) Path to the directory where the generated code will be installed. |
| 165 | + * - ``--dev`` |
| 166 | + - (Optional) Enable development mode: code generation is attempted even for models that contain errors, and extra information is rendered in the generated code. Default is OFF. |
| 167 | + * - ``--codegen_opts`` |
| 168 | + - (Optional) Path to a JSON file containing additional options for the target platform code generator. A list of available options can be found under the section "Code generation options" for your intended target platform on the page :ref:`Running NESTML`. |
0 commit comments