Hello Pablo,

I apologize for the late response.

there is many facets of issue. Please correct me if I understand your intention wrongly.
You want to use NEST container to generate NESTML models and use them for the simulation on Docker images, right?

I developed NEST Server [1] and NESTML Server [2], primarily for NEST Desktop [3].
Both are implemented in NEST image but for different purposes.

On one hand, NESTML Server only generates NESTML models and not to execute code.
Thus is not compatible with NESTClient because NESTML Server has no '/exec' URL.
Please ask me for more details if you want to learn more about NESTML Server.

On other hand, NEST Server is designed to execute Python code (simulation script) and is compatible with NESTClient [4].
We added some restrictions to secure NEST Server. These restriction can be configured by the environment variables e.g. NEST_SERVER_ENABLE_EXEC_CALL [5].

----

For your purpose I would like to motivate you to use docker-compose to run multiple docker containers [6].
However, we did not prepared client side for NESTML Server but I can show you some sample Python code.

First, start docker containers with docker compose (without NEST Desktop).
```
wget https://github.com/nest-desktop/nest-desktop-docker/blob/main/examples/nest-single-image/docker-compose.yml
docker-compose up
```

Next, use this code to generate models on server side.
```
import requests

def get_script_from_file(filename):
    with open(filename, 'r') as f:
        lines = f.readlines()
    script = "".join(lines)
    return script

models = []
models.append({'name': 'my_neuron', 'script': get_script_from_file('my_neuron.nestml')})
models.append({'name': 'my_synapse, 'script': get_script_from_file('my_synapse.nestml')})

# Send them to generate on server side.
requests.post('http://localhost:52426/generateModels', data={
   'module': 'nestmlmodule',
   'models': models
})
```

------

Then execute simulation code with NESTML module with NESTServerClient [7]:
```
from NESTServerClient import NESTServerClient

nestsc = NESTServerClient()
n_events = nestsc.from_file('NESTClient_script.py', 'n_events')['data']
print(n_events)
```

and the NESTClient_scripy.py looks:
```
import nest

nest.ResetKernel()
nest.Install('nestmlmodule')

pg = nest.Create("poisson_generator", params={"rate": 6500})
neurons = nest.Create("my_neuron", 100)
sr = nest.Create("spike_recorder")

nest.Connect(pg, neurons, syn_spec={"weight": 10})
nest.Connect(neurons[::10], sr)

nest.Simulate(1000)
n_events = sr.get("n_events")
```


This is a long instruction. I hope I can help you to fix your issue.
Please feel free to ask me if unclear.


Best
Sebastian


[1] - https://github.com/nest/nest-simulator/blob/master/pynest/nest/server/hl_api_server.py
[2] - https://github.com/babsey/nestml-server
[3] - https://github.com/nest-desktop/nest-desktop
[4] - https://nest-simulator.readthedocs.io/en/latest/interface_nest/nest_server.html#the-nest-client
[5] - https://github.com/nest/nest-docker/blob/master/src/3.8/entrypoint.sh
[6] - https://github.com/nest-desktop/nest-desktop-docker/blob/main/examples/nest-single-image/docker-compose.yml
[7] - https://github.com/nest/nest-client

On 1/15/25 01:13, Pablo Alejandro wrote:

Hi Everyone,

Apologies for sending the message below again. I think my last post was done incorrectly and no one got notifications.

-----------------------------------------

Does nest server currently support nestml models? I couldn't find examples in the documentation (even though `nestml-server` binary exists in nest3.8 docker image). Ideally, I would like to run it with MPI too.

I can run a simple example (`python test.py`) with `nest-server` running from a docker container, but the same code fails if I use `nestml-server`:

``` docker run -it --rm -e LOCAL_USER_ID=`id -u $USER` -p 52425:52425 nest/nest-simulator:3.8 nest-server start ```

works, but

``` docker run -it --rm -e LOCAL_USER_ID=`id -u $USER` -p 52426:52426 nest/nest-simulator:3.8 nestml-server start ```

fails with

``` Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 199, in _new_conn sock = connection.create_connection( File "/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py", line 85, in create_connection raise err File "/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py", line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 789, in urlopen response = self._make_request( File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 495, in _make_request conn.request( File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 441, in request self.endheaders() File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output self.send(msg) File "/usr/lib/python3.10/http/client.py", line 976, in send self.connect() File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 279, in connect self.sock = self._new_conn() File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 214, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fb8b63ea440>: Failed to establish a new connection: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 843, in urlopen retries = retries.increment( File "/usr/local/lib/python3.10/dist-packages/urllib3/util/retry.py", line 519, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=52425): Max retries exceeded with url: /exec (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb8b63ea440>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pablo/git/nest-client/test_server.py", line 4, in <module> response = nsc.from_file('examples/NESTClient_script.py', return_vars='n_events') File "/home/pablo/git/nest-client/nest_client/nest_client.py", line 68, in from_file return self.exec_script(script, return_vars) File "/home/pablo/git/nest-client/nest_client/nest_client.py", line 56, in exec_script response = requests.post(self.url + 'exec', json=params, headers=self.headers) File "/usr/lib/python3/dist-packages/requests/api.py", line 119, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/lib/python3/dist-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 544, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 657, in send r = adapter.send(request, **kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=52425): Max retries exceeded with url: /exec (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb8b63ea440>: Failed to establish a new connection: [Errno 111] Connection refused')) ```

The simple python code used is shown below. ``` from nest_client import NESTClient nsc = NESTClient()

response = nsc.from_file('examples/NESTClient_script.py', return_vars='n_events') n_events = response['data']

print('Number of events:', n_events) ```

No nestml models are being tested for now because I don't know which functions should be used to generate code with `nest-client` e.g.

``` from pynestml.codegeneration.nest_code_generator_utils import NESTCodeGeneratorUtils

module_name, neuron_model_name, synapse_model_name = \ NESTCodeGeneratorUtils.generate_code_for( "neuron.nestml", "synapse.nestml", post_ports=["post_spikes"], codegen_opts=codegen_opts ) ```

should be rewritten to use `from nest_client import NESTClient`.

Thanks in advance, Pablo Alejandro


_______________________________________________
NEST Users mailing list -- users@nest-simulator.org
To unsubscribe send an email to users-leave@nest-simulator.org