-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
214f214
commit d0496ec
Showing
11 changed files
with
2,325 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Copyright 2024, EPFL/Blue Brain Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
import logging | ||
|
||
import pandas as pd | ||
from numpy.testing import assert_allclose | ||
from pandas.testing import assert_frame_equal | ||
|
||
from bluepyemodel.evaluation.evaluation import get_evaluator_from_access_point | ||
|
||
|
||
def test_protocols(db_from_nexus, tmp_path): | ||
logging.basicConfig(level=logging.DEBUG) | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
|
||
params = db_from_nexus.get_emodel().parameters | ||
evaluator = get_evaluator_from_access_point(access_point=db_from_nexus) | ||
|
||
responses = evaluator.run_protocols( | ||
protocols=evaluator.fitness_protocols.values(), param_values=params | ||
) | ||
|
||
# FIXME: remove print after clarifying the different result when executing the test alone | ||
print(responses) | ||
assert_allclose(responses["bpo_rmp"], -82.61402706564716, rtol=1e-06) | ||
assert_allclose(responses["bpo_holding_current"], -0.05, rtol=1e-06) | ||
assert_allclose(responses["bpo_rin"], 41.13626022273351, rtol=1e-06) | ||
assert_allclose(responses["bpo_threshold_current"], 0.3757011543411314, rtol=1e-06) | ||
|
||
for prot_name in [ | ||
"APWaveform_280.soma.v", | ||
"IDrest_150.soma.v", | ||
"IDrest_250.soma.v", | ||
"IV_-100.soma.v", | ||
"RinProtocol.soma.v", | ||
"RMPProtocol.soma.v", | ||
"SearchHoldingCurrent.soma.v", | ||
"SearchThresholdCurrent.soma.v", | ||
]: | ||
output_path = f"{tmp_path}/test_{prot_name}.csv" | ||
responses[prot_name].response.to_csv(output_path, index=False) | ||
expected_df = pd.read_csv(output_path) | ||
response = responses[prot_name].response | ||
assert_frame_equal(response, expected_df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Copyright 2024, EPFL/Blue Brain Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
import logging | ||
|
||
from bluepyemodel.validation.validation import define_validation_function, validate | ||
|
||
|
||
def _always_true_validation(model, threshold=5.0, validation_protocols_only=False): | ||
return True | ||
|
||
|
||
def test_define_validation_function(db_from_nexus): | ||
|
||
model = { | ||
"scores": {"a": 0.0, "b": 4.9, "c": 0.5, "d": 9.9}, | ||
"scores_validation": {"c": 0.5, "d": 9.9}, | ||
} | ||
|
||
db_from_nexus.pipeline_settings.validation_function = _always_true_validation | ||
|
||
validation_function = define_validation_function(db_from_nexus) | ||
|
||
validated = bool( | ||
validation_function( | ||
model, | ||
db_from_nexus.pipeline_settings.validation_threshold, | ||
False, | ||
) | ||
) | ||
|
||
assert validated | ||
|
||
|
||
def test_validation(db_from_nexus): | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
|
||
def _get_final_content(lock_file=True): | ||
# enforce validated to None to ensure that the validation is run | ||
result = get_final_content(lock_file=lock_file) | ||
for key, value in result.items(): | ||
assert "validated" in value | ||
value["validated"] = None | ||
return result | ||
|
||
get_final_content = db_from_nexus.get_final_content | ||
db_from_nexus.get_final_content = _get_final_content | ||
db_from_nexus.get_mechanisms_directory = lambda: None | ||
emodels = validate( | ||
access_point=db_from_nexus, | ||
mapper=map, | ||
) | ||
|
||
assert len(emodels) == 1 | ||
assert emodels[0].passed_validation is True |
Oops, something went wrong.