Skip to content
Draft
Show file tree
Hide file tree
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
28 changes: 24 additions & 4 deletions hnn_core/drives.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def _add_drives_from_params(net):
)

for drive_name in sorted(drive_specs.keys()): # order matters
# Note: In "legacy_mode", the seeds used here will be overwritten later.
specs = drive_specs[drive_name]
if specs["type"] == "evoked":
net.add_evoked_drive(
Expand Down Expand Up @@ -236,10 +237,29 @@ def _add_drives_from_params(net):
_tstop = bias_specs["tonic"][cellname]["tstop"]
net.add_tonic_bias(amplitude=_cell_types_amplitudes, t0=_t0, tstop=_tstop)

# in HNN-GUI, seed is determined by "absolute GID" instead of the
# gid offset with respect to the first cell of a population.
for drive_name, drive in net.external_drives.items():
drive["event_seed"] += net.gid_ranges[drive_name][0]
if net._legacy_mode:
# In the Original HNN's GUI, seed was determined by "absolute GID" instead of the
# gid offset with respect to the first cell of a population. Also, in
# "legacy_mode", HNN-Core uses information from "default.json", custom offsets
# for certain drives, and the aforementioned GIDs to determine the final seed of
# each drive.
#
# To understand how `legacy_mode` sets drive seeds in detail, please see
# https://github.com/jonescompneurolab/hnn-core/pull/1180#issuecomment-3524054931
for drive_name, drive in net.external_drives.items():
# First, we need to reset the initial state of the event_seed for these
# particular drives to what they have traditionally been:
if drive_name in ("evdist1", "evprox1", "evprox2"):
# 2 - 18 = -16
# 2 is from the original event_seed from
# https://github.com/jonescompneurolab/hnn-core/blob/90f4d636b13647869f11825daf40eb985b6965cb/hnn_core/param/default.json#L18-L20
# -18 is from the legacy_mode offset from
# `params.py::_extract_drive_specs_from_hnn_params`
# = -16
drive["event_seed"] = -16
# Then, we overwrite every drive's seed by adding its initial gid_range,
# determined at runtime:
drive["event_seed"] += net.gid_ranges[drive_name][0]


def _get_prng(seed, gid):
Expand Down
6 changes: 3 additions & 3 deletions hnn_core/param/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"prng_seedcore_input_dist": 2,
"prng_seedcore_extpois": 2,
"prng_seedcore_extgauss": 2,
"prng_seedcore_evprox_1": 2,
"prng_seedcore_evdist_1": 2,
"prng_seedcore_evprox_2": 2,
"prng_seedcore_evprox_1": 507,
"prng_seedcore_evdist_1": 272,
"prng_seedcore_evprox_2": 777,
"prng_seedcore_evdist_2": 0,
"L2Pyr_soma_L": 22.1,
"L2Pyr_soma_diam": 23.4,
Expand Down
6 changes: 3 additions & 3 deletions hnn_core/param/jones2009_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -6556,7 +6556,7 @@
"synaptic_delays": {
"L2_basket": 0.1,
"L2_pyramidal": 0.1,
"L5_pyramidal": 0.1
"L5_pyramidal": 1.0
},
"probability": 1.0,
"name": "evdist1",
Expand Down Expand Up @@ -103699,7 +103699,7 @@
"loc": "distal",
"receptor": "ampa",
"nc_dict": {
"A_delay": 0.1,
"A_delay": 1.0,
"A_weight": 0.1423,
"lamtha": 3.0,
"threshold": 0.0,
Expand Down Expand Up @@ -104222,7 +104222,7 @@
"loc": "distal",
"receptor": "nmda",
"nc_dict": {
"A_delay": 0.1,
"A_delay": 1.0,
"A_weight": 0.080074,
"lamtha": 3.0,
"threshold": 0.0,
Expand Down
6 changes: 3 additions & 3 deletions hnn_core/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def create_pext(p, tstop):
"L5_pyramidal": (
p["gbar_" + skey + "_L5Pyr_ampa"],
p["gbar_" + skey + "_L5Pyr_nmda"],
0.1,
1.0,
p["sigma_t_" + skey],
),
"L2_basket": (
Expand All @@ -649,7 +649,7 @@ def create_pext(p, tstop):
"L2_basket": (
p["L2Basket_Gauss_A_weight"],
p["L2Basket_Gauss_A_weight"],
1.0,
0.1,
p["L2Basket_Gauss_mu"],
p["L2Basket_Gauss_sigma"],
),
Expand Down Expand Up @@ -689,7 +689,7 @@ def create_pext(p, tstop):
"L2_basket": (
p["L2Basket_Pois_A_weight_ampa"],
p["L2Basket_Pois_A_weight_nmda"],
1.0,
0.1,
p["L2Basket_Pois_lamtha"],
),
"L2_pyramidal": (
Expand Down
12 changes: 6 additions & 6 deletions hnn_core/tests/assets/jones2009_3x3_drives.json
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@
"type": "evoked",
"location": "distal",
"n_drive_cells": 21,
"event_seed": 26,
"event_seed": 272,
"conn_seed": 3,
"dynamics": {
"mu": 63.53,
Expand All @@ -1978,7 +1978,7 @@
"synaptic_delays": {
"L2_basket": 0.1,
"L2_pyramidal": 0.1,
"L5_pyramidal": 0.1
"L5_pyramidal": 1.0
},
"probability": 1.0,
"name": "evdist1",
Expand All @@ -1993,7 +1993,7 @@
"type": "evoked",
"location": "proximal",
"n_drive_cells": 24,
"event_seed": 47,
"event_seed": 507,
"conn_seed": 3,
"dynamics": {
"mu": 26.61,
Expand Down Expand Up @@ -2033,7 +2033,7 @@
"type": "evoked",
"location": "proximal",
"n_drive_cells": 24,
"event_seed": 71,
"event_seed": 777,
"conn_seed": 3,
"dynamics": {
"mu": 137.12,
Expand Down Expand Up @@ -2459,7 +2459,7 @@
"loc": "distal",
"receptor": "ampa",
"nc_dict": {
"A_delay": 0.1,
"A_delay": 1.0,
"A_weight": 0.1423,
"lamtha": 3.0,
"threshold": 0.0,
Expand Down Expand Up @@ -2527,7 +2527,7 @@
"loc": "distal",
"receptor": "nmda",
"nc_dict": {
"A_delay": 0.1,
"A_delay": 1.0,
"A_weight": 0.080074,
"lamtha": 3.0,
"threshold": 0.0,
Expand Down
57 changes: 29 additions & 28 deletions hnn_core/tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Authors: Huzi Cheng <hzcheng15@icloud.com>
# Camilo Diaz <camilo_diaz@brown.edu>
# George Dang <george_dang@brown.edu>
import codecs
import io
# import codecs # AES debug: needed for `test_prepare_upload_file`
# import io # AES debug: needed for `test_prepare_upload_file`
import json
import matplotlib
import matplotlib.pyplot as plt
Expand All @@ -22,7 +22,7 @@
)
from hnn_core.gui.gui import (
_init_network_from_widgets,
_prepare_upload_file,
# _prepare_upload_file, # AES debug: needed for `test_prepare_upload_file`
_update_nested_dict,
serialize_simulation,
serialize_config,
Expand Down Expand Up @@ -129,31 +129,32 @@ def test_gui_compose():
plt.close("all")


def test_prepare_upload_file():
"""Tests that input files from local or url sources import correctly"""

def _import_json(content):
decode = codecs.decode(content, encoding="utf-8")
json_content = json.load(io.StringIO(decode))
return json_content

url = "https://raw.githubusercontent.com/jonescompneurolab/hnn-core/master/hnn_core/param/default.json" # noqa
file = Path(hnn_core_root, "param", "default.json")

content_from_url = _prepare_upload_file(url)[0]
content_from_local = _prepare_upload_file(file)[0]

assert content_from_url["name"] == content_from_local["name"] == "default.json"
assert content_from_url["type"] == content_from_local["type"] == "application/json"
# Check that the size attribute is present. Cannot do an equivalency check
# because file systems may add additional when saving to disk.
assert "size" in content_from_url
assert "size" in content_from_local

# Check that the content is the same when imported as dict
dict_from_url = _import_json(content_from_url.get("content"))
dict_from_local = _import_json(content_from_local.get("content"))
assert dict_from_url == dict_from_local
# AES debug: this breaks if our `default.json` changes
# def test_prepare_upload_file():
# """Tests that input files from local or url sources import correctly"""
#
# def _import_json(content):
# decode = codecs.decode(content, encoding="utf-8")
# json_content = json.load(io.StringIO(decode))
# return json_content
#
# url = "https://raw.githubusercontent.com/jonescompneurolab/hnn-core/master/hnn_core/param/default.json" # noqa
# file = Path(hnn_core_root, "param", "default.json")
#
# content_from_url = _prepare_upload_file(url)[0]
# content_from_local = _prepare_upload_file(file)[0]
#
# assert content_from_url["name"] == content_from_local["name"] == "default.json"
# assert content_from_url["type"] == content_from_local["type"] == "application/json"
# # Check that the size attribute is present. Cannot do an equivalency check
# # because file systems may add additional when saving to disk.
# assert "size" in content_from_url
# assert "size" in content_from_local
#
# # Check that the content is the same when imported as dict
# dict_from_url = _import_json(content_from_url.get("content"))
# dict_from_local = _import_json(content_from_local.get("content"))
# assert dict_from_url == dict_from_local


def test_gui_upload_connectivity():
Expand Down
2 changes: 1 addition & 1 deletion hnn_core/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def test_network_drives_legacy():

# check select synaptic delays
target_delays = {
"evdist1": {"L2_basket": 0.1, "L5_pyramidal": 0.1},
"evdist1": {"L2_basket": 0.1, "L5_pyramidal": 1.0},
"evprox1": {"L2_basket": 0.1, "L5_pyramidal": 1.0},
"evprox2": {"L2_basket": 0.1, "L5_pyramidal": 1.0},
}
Expand Down