Description
Describe the bug
When switching from nest-server
to nset-server-mpi
, the simulation crashes with the error
TypeError: Object of type int64 is not JSON serializable
The exact conditions when this error appears is unclear for me. I have an experiment, which works in both nest-server
and nest-server-mpi
, but the experiment I am currently working on produces this error, what holds me from launching it on HPC.
Since I cannot give a simple instruction on how to reproduce the error, I prepared the truncated version of the experiment, which crashes https://github.com/vvorobjov/nest-simulator-nest-server-mpi-demo
There are instructions how I generate nestml module, how the experiment can be launched with the nest-server
and nest-server-mpi
. The experiment uses NRP.
To Reproduce
- Generate nestml module
- Launch the experiment with
nest-server
- Launch the experiment with
nest-server-mpi
- In docker compose output there is the error
nest-server-1 | Traceback (most recent call last):
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/app.py", line 2070, in wsgi_app
nest-server-1 | response = self.full_dispatch_request()
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/app.py", line 1515, in full_dispatch_request
nest-server-1 | rv = self.handle_user_exception(e)
nest-server-1 | File "/usr/lib/python3/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
nest-server-1 | return cors_after_request(app.make_response(f(*args, **kwargs)))
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/app.py", line 1513, in full_dispatch_request
nest-server-1 | rv = self.dispatch_request()
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/app.py", line 1499, in dispatch_request
nest-server-1 | return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
nest-server-1 | File "/opt/nest/lib/python3.10/site-packages/nest/server/hl_api_server.py", line 310, in route_api_call
nest-server-1 | return jsonify(response)
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/json/__init__.py", line 348, in jsonify
nest-server-1 | f"{dumps(data, indent=indent, separators=separators)}\n",
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/json/__init__.py", line 129, in dumps
nest-server-1 | rv = _json.dumps(obj, **kwargs)
nest-server-1 | File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
nest-server-1 | **kw).encode(obj)
nest-server-1 | File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
nest-server-1 | chunks = self.iterencode(o, _one_shot=True)
nest-server-1 | File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
nest-server-1 | return _iterencode(o, 0)
nest-server-1 | File "/usr/lib/python3/dist-packages/flask/json/__init__.py", line 56, in default
nest-server-1 | return super().default(o)
nest-server-1 | File "/usr/lib/python3.10/json/encoder.py", line 179, in default
nest-server-1 | raise TypeError(f'Object of type {o.__class__.__name__} '
nest-server-1 | TypeError: Object of type int64 is not JSON serializable
nest-server-1 | [2025-04-25 12:16:28,508] INFO in _internal: 172.24.0.3 - - [25/Apr/2025 12:16:28] "POST /api/GetStatus HTTP/1.1" 500 -
Expected behavior
Both nest-server
and nest-server-mpi
work the same
Desktop/Environment (please complete the following information):
- OS: Ubuntu 24
- Shell: bash
- NEST-Version: master
- Installation: Docker
Additional context
I have digged into it a bit, and I think that the problem can be solved by changing
jsonify(response)
to
jsonify(nest.serialize_data(response))
in nest/server/hl_api_server.py
and adding the following (or a shorter list of types)
if isinstance(data, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
numpy.uint16, numpy.uint32, numpy.uint64)):
return int(data)
to serialize_data
in nest/lib/hl_api_types.py
But maybe the core issue is different and this is just a dummy patch
UPD
I was brave enough to propose the PR #3488