Skip to content

Fix merging responses in nest-server-mpi #3492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pynest/nest/server/hl_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ def combine(call_name, response):
return None

# return the master response if all responses are known to be the same
if call_name in ("exec", "Create", "GetDefaults", "GetKernelStatus", "SetKernelStatus", "SetStatus"):
if call_name == "exec":
return merge_response(response)[0]
elif call_name in ("Create", "GetDefaults", "GetKernelStatus", "SetKernelStatus", "SetStatus"):
return response[0]

# return a single response if there is only one which is not None
Expand Down Expand Up @@ -674,5 +676,23 @@ def merge_dicts(response):
return result


def merge_response(response: list):
if "events" in response[0]["data"]:
events = [res["data"]["events"] for res in response]
merged = [_merge_event([e[idx] for e in events]) for idx in range(len(events[0]))]
return [{"data": {"events": merged}}]
else:
return response


def _flatten(xss):
return [x for xs in xss for x in xs]


def _merge_event(event: list):
eventKeys = list(set(_flatten([e for e in event])))
return dict([(eKey, _flatten([e[eKey] for e in event])) for eKey in eventKeys])


if __name__ == "__main__":
app.run()
Loading