From d34f465f13bcf6256828350c4880355e9dc2a093 Mon Sep 17 00:00:00 2001 From: "eduard.subert" Date: Tue, 28 Nov 2023 11:08:49 +0100 Subject: [PATCH 1/7] return circuit node ids --- bluepysnap/edges/edge_population.py | 14 ++- bluepysnap/edges/edges.py | 38 ++----- tests/test_edge_population.py | 153 +++++++++++++++++++++++++--- 3 files changed, 155 insertions(+), 50 deletions(-) diff --git a/bluepysnap/edges/edge_population.py b/bluepysnap/edges/edge_population.py index 32854b88..e405963b 100644 --- a/bluepysnap/edges/edge_population.py +++ b/bluepysnap/edges/edge_population.py @@ -26,7 +26,7 @@ from more_itertools import first from bluepysnap import query, utils -from bluepysnap.circuit_ids import CircuitEdgeIds +from bluepysnap.circuit_ids import CircuitEdgeIds, CircuitNodeId from bluepysnap.circuit_ids_types import IDS_DTYPE, CircuitEdgeId from bluepysnap.exceptions import BluepySnapError from bluepysnap.sonata_constants import DYNAMICS_PREFIX, ConstContainer, Edge @@ -554,7 +554,17 @@ def iter_connections( source_node_ids = self._resolve_node_ids(self.source, source) target_node_ids = self._resolve_node_ids(self.target, target) - it = self._iter_connections(source_node_ids, target_node_ids, unique_node_ids, shuffle) + # completing CircuitNodeIds + it = ( + ( + CircuitNodeId(population=self.source.name, id=x[0]), + CircuitNodeId(population=self.target.name, id=x[1]), + x[2], + ) + for x in self._iter_connections( + source_node_ids, target_node_ids, unique_node_ids, shuffle + ) + ) if return_edge_count: return it diff --git a/bluepysnap/edges/edges.py b/bluepysnap/edges/edges.py index 8d3da1bb..840b7550 100644 --- a/bluepysnap/edges/edges.py +++ b/bluepysnap/edges/edges.py @@ -21,7 +21,6 @@ from bluepysnap._doctools import AbstractDocSubstitutionMeta from bluepysnap.circuit_ids import CircuitEdgeIds, CircuitNodeIds -from bluepysnap.circuit_ids_types import CircuitNodeId from bluepysnap.edges.edge_population import EdgePopulation from bluepysnap.exceptions import BluepySnapError from bluepysnap.network import NetworkObject @@ -222,38 +221,17 @@ def pair_edges(self, source_node_id, target_node_id, properties=None): ) @staticmethod - def _add_circuit_ids(its, source, target): - """Generator comprehension adding the CircuitIds to the iterator. - - Notes: - Using closures or lambda functions would result in override functions and so the - source and target would be the same for all the populations. - """ - return ( - (CircuitNodeId(source, source_id), CircuitNodeId(target, target_id), count) - for source_id, target_id, count in its - ) - - @staticmethod - def _add_edge_ids(its, source, target, pop_name): + def _add_edge_ids(its, pop_name): """Generator comprehension adding the CircuitIds to the iterator.""" return ( ( - CircuitNodeId(source, source_id), - CircuitNodeId(target, target_id), + source_id, + target_id, CircuitEdgeIds.from_dict({pop_name: edge_id}), ) for source_id, target_id, edge_id in its ) - @staticmethod - def _omit_edge_count(its, source, target): - """Generator comprehension adding the CircuitIds to the iterator.""" - return ( - (CircuitNodeId(source, source_id), CircuitNodeId(target, target_id)) - for source_id, target_id in its - ) - def iter_connections( self, source=None, target=None, return_edge_ids=False, return_edge_count=False ): @@ -283,14 +261,10 @@ def iter_connections( return_edge_ids=return_edge_ids, return_edge_count=return_edge_count, ) - source_pop = pop.source.name - target_pop = pop.target.name - if return_edge_count: - yield from self._add_circuit_ids(it, source_pop, target_pop) - elif return_edge_ids: - yield from self._add_edge_ids(it, source_pop, target_pop, name) + if return_edge_ids: + yield from self._add_edge_ids(it, name) else: - yield from self._omit_edge_count(it, source_pop, target_pop) + yield from it def __getstate__(self): """Make Edges pickle-able, without storing state of caches.""" diff --git a/tests/test_edge_population.py b/tests/test_edge_population.py index 0d110b9b..3504bf2e 100644 --- a/tests/test_edge_population.py +++ b/tests/test_edge_population.py @@ -13,7 +13,7 @@ from bluepysnap.bbp import Synapse from bluepysnap.circuit import Circuit from bluepysnap.circuit_ids import CircuitEdgeIds, CircuitNodeIds -from bluepysnap.circuit_ids_types import IDS_DTYPE, CircuitEdgeId +from bluepysnap.circuit_ids_types import IDS_DTYPE, CircuitEdgeId, CircuitNodeId from bluepysnap.exceptions import BluepySnapError from bluepysnap.sonata_constants import DEFAULT_EDGE_TYPE, Edge @@ -519,18 +519,29 @@ def test_pathway_edges_6(self): def test_iter_connections_1(self): it = self.test_obj.iter_connections([0, 2], [1]) - assert next(it) == (0, 1) - assert next(it) == (2, 1) + assert next(it) == ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + ) + assert next(it) == ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=1), + ) with pytest.raises(StopIteration): next(it) def test_iter_connections_2(self): it = self.test_obj.iter_connections([0, 2], [1], unique_node_ids=True) - assert list(it) == [(0, 1)] + assert list(it) == [ + (CircuitNodeId(population="default", id=0), CircuitNodeId(population="default", id=1)), + ] def test_iter_connections_3(self): it = self.test_obj.iter_connections([0, 2], [1], shuffle=True) - assert sorted(it) == [(0, 1), (2, 1)] + assert sorted(it) == [ + (CircuitNodeId(population="default", id=0), CircuitNodeId(population="default", id=1)), + (CircuitNodeId(population="default", id=2), CircuitNodeId(population="default", id=1)), + ] def test_iter_connections_4(self): it = self.test_obj.iter_connections(None, None) @@ -539,11 +550,17 @@ def test_iter_connections_4(self): def test_iter_connections_5(self): it = self.test_obj.iter_connections(None, [1]) - assert list(it) == [(0, 1), (2, 1)] + assert list(it) == [ + (CircuitNodeId(population="default", id=0), CircuitNodeId(population="default", id=1)), + (CircuitNodeId(population="default", id=2), CircuitNodeId(population="default", id=1)), + ] def test_iter_connections_6(self): it = self.test_obj.iter_connections([2], None) - assert list(it) == [(2, 0), (2, 1)] + assert list(it) == [ + (CircuitNodeId(population="default", id=2), CircuitNodeId(population="default", id=0)), + (CircuitNodeId(population="default", id=2), CircuitNodeId(population="default", id=1)), + ] def test_iter_connections_7(self): it = self.test_obj.iter_connections([], [0, 1, 2]) @@ -551,11 +568,36 @@ def test_iter_connections_7(self): def test_iter_connections_8(self): it = self.test_obj.iter_connections([0, 2], [1], return_edge_ids=True) - npt.assert_equal(list(it), [(0, 1, [1, 2]), (2, 1, [3])]) + npt.assert_equal( + list(it), + [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + [1, 2], + ), + ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=1), + [3], + ), + ], + ) def test_iter_connections_9(self): it = self.test_obj.iter_connections([0, 2], [1], return_edge_count=True) - assert list(it) == [(0, 1, 2), (2, 1, 1)] + assert list(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + 2, + ), + ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=1), + 1, + ), + ] def test_iter_connections_10(self): with pytest.raises(BluepySnapError): @@ -577,25 +619,104 @@ def test_iter_connection_unique(self): test_obj = TestEdgePopulation.get_edge_population(config_path, "default") it = test_obj.iter_connections([0, 1, 2], [0, 1, 2]) - assert sorted(it) == [(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + ), + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=2), + ), + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=0), + ), + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=2), + ), + ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=0), + ), + ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=1), + ), + ] it = test_obj.iter_connections([0, 1, 2], [0, 1, 2], unique_node_ids=True) - assert sorted(it) == [(0, 1), (1, 0)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + ), + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=0), + ), + ] it = test_obj.iter_connections([0, 1, 2], [0, 2], unique_node_ids=True) - assert sorted(it) == [(0, 2), (1, 0)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=2), + ), + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=0), + ), + ] it = test_obj.iter_connections([0, 2], [0, 2], unique_node_ids=True) - assert sorted(it) == [(0, 2), (2, 0)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=2), + ), + ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=0), + ), + ] it = test_obj.iter_connections([0, 1, 2], [0, 2, 1], unique_node_ids=True) - assert sorted(it) == [(0, 1), (1, 0)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + ), + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=0), + ), + ] it = test_obj.iter_connections([1, 2], [0, 1, 2], unique_node_ids=True) - assert sorted(it) == [(1, 0), (2, 1)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=0), + ), + ( + CircuitNodeId(population="default", id=2), + CircuitNodeId(population="default", id=1), + ), + ] it = test_obj.iter_connections([0, 1, 2], [1, 2], unique_node_ids=True) - assert sorted(it) == [(0, 1), (1, 2)] + assert sorted(it) == [ + ( + CircuitNodeId(population="default", id=0), + CircuitNodeId(population="default", id=1), + ), + ( + CircuitNodeId(population="default", id=1), + CircuitNodeId(population="default", id=2), + ), + ] def test_h5_filepath_from_config(self): assert self.test_obj.h5_filepath == str(TEST_DATA_DIR / "edges.h5") From 1992fed20876949bbc161da112fe6bf3aa3171b9 Mon Sep 17 00:00:00 2001 From: "eduard.subert" Date: Tue, 28 Nov 2023 11:19:16 +0100 Subject: [PATCH 2/7] version --- CHANGELOG.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c44809f1..5e178e84 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,14 @@ Changelog ========= +Version v2.2.0~dev0 +-------------- + +Breaking Changes +~~~~~~~~~~~~~~~~ +- Edge populations' ``iter_connections`` returns ``CircuitNodeId``s instead of ``int``s + + Version v2.1.0 -------------- From c499dbed9184a23e48e02f1d12457ec239cafc27 Mon Sep 17 00:00:00 2001 From: "eduard.subert" Date: Fri, 1 Dec 2023 13:34:12 +0100 Subject: [PATCH 3/7] simplify --- bluepysnap/edges/edge_population.py | 26 +++++++++++++++----------- bluepysnap/edges/edges.py | 20 ++------------------ tests/test_edge_population.py | 4 ++-- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/bluepysnap/edges/edge_population.py b/bluepysnap/edges/edge_population.py index e405963b..594b1202 100644 --- a/bluepysnap/edges/edge_population.py +++ b/bluepysnap/edges/edge_population.py @@ -518,6 +518,14 @@ def _optimal_direction(): secondary_node_ids_used.add(conn_node_id) break + def _complete_circuit_node_ids(self, connections): + for connection in connections: + yield ( + CircuitNodeId(population=self.source.name, id=connection[0]), + CircuitNodeId(population=self.target.name, id=connection[1]), + connection[2], + ) + def iter_connections( self, source=None, @@ -554,22 +562,18 @@ def iter_connections( source_node_ids = self._resolve_node_ids(self.source, source) target_node_ids = self._resolve_node_ids(self.target, target) - # completing CircuitNodeIds - it = ( - ( - CircuitNodeId(population=self.source.name, id=x[0]), - CircuitNodeId(population=self.target.name, id=x[1]), - x[2], - ) - for x in self._iter_connections( - source_node_ids, target_node_ids, unique_node_ids, shuffle - ) + it = self._complete_circuit_node_ids( + self._iter_connections(source_node_ids, target_node_ids, unique_node_ids, shuffle) ) if return_edge_count: return it elif return_edge_ids: - add_edge_ids = lambda x: (x[0], x[1], self.pair_edges(x[0], x[1])) + add_edge_ids = lambda x: ( + x[0], + x[1], + CircuitEdgeIds.from_dict({self.name: self.pair_edges(x[0], x[1])}), + ) return map(add_edge_ids, it) else: omit_edge_count = lambda x: x[:2] diff --git a/bluepysnap/edges/edges.py b/bluepysnap/edges/edges.py index 840b7550..1f000942 100644 --- a/bluepysnap/edges/edges.py +++ b/bluepysnap/edges/edges.py @@ -220,18 +220,6 @@ def pair_edges(self, source_node_id, target_node_id, properties=None): source=source_node_id, target=target_node_id, properties=properties ) - @staticmethod - def _add_edge_ids(its, pop_name): - """Generator comprehension adding the CircuitIds to the iterator.""" - return ( - ( - source_id, - target_id, - CircuitEdgeIds.from_dict({pop_name: edge_id}), - ) - for source_id, target_id, edge_id in its - ) - def iter_connections( self, source=None, target=None, return_edge_ids=False, return_edge_count=False ): @@ -254,17 +242,13 @@ def iter_connections( raise BluepySnapError( "`return_edge_count` and `return_edge_ids` are mutually exclusive" ) - for name, pop in self.items(): - it = pop.iter_connections( + for pop in self.values(): + yield from pop.iter_connections( source=source, target=target, return_edge_ids=return_edge_ids, return_edge_count=return_edge_count, ) - if return_edge_ids: - yield from self._add_edge_ids(it, name) - else: - yield from it def __getstate__(self): """Make Edges pickle-able, without storing state of caches.""" diff --git a/tests/test_edge_population.py b/tests/test_edge_population.py index 3504bf2e..6b33e5b5 100644 --- a/tests/test_edge_population.py +++ b/tests/test_edge_population.py @@ -574,12 +574,12 @@ def test_iter_connections_8(self): ( CircuitNodeId(population="default", id=0), CircuitNodeId(population="default", id=1), - [1, 2], + CircuitEdgeIds.from_dict({"default": [1, 2]}), ), ( CircuitNodeId(population="default", id=2), CircuitNodeId(population="default", id=1), - [3], + CircuitEdgeIds.from_dict({"default": [3]}), ), ], ) From ed8c0656e1341a18c8e48514c1c1ee97a7ab46b8 Mon Sep 17 00:00:00 2001 From: "eduard.subert" Date: Fri, 1 Dec 2023 18:29:56 +0100 Subject: [PATCH 4/7] use previous formating --- bluepysnap/edges/edge_population.py | 52 +++++++++++++++++++---------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/bluepysnap/edges/edge_population.py b/bluepysnap/edges/edge_population.py index 594b1202..d5f5ff8b 100644 --- a/bluepysnap/edges/edge_population.py +++ b/bluepysnap/edges/edge_population.py @@ -518,13 +518,37 @@ def _optimal_direction(): secondary_node_ids_used.add(conn_node_id) break - def _complete_circuit_node_ids(self, connections): - for connection in connections: - yield ( - CircuitNodeId(population=self.source.name, id=connection[0]), - CircuitNodeId(population=self.target.name, id=connection[1]), - connection[2], + def _add_circuit_ids(self, its): + """Generator comprehension adding the CircuitIds to the iterator.""" + return ( + ( + CircuitNodeId(self.source.name, source_id), + CircuitNodeId(self.target.name, target_id), + count, ) + for source_id, target_id, count in its + ) + + def _add_edge_ids(self, its): + """Generator comprehension adding the CircuitIds to the iterator.""" + return ( + ( + CircuitNodeId(self.source.name, source_id), + CircuitNodeId(self.target.name, target_id), + CircuitEdgeIds.from_dict({self.name: self.pair_edges(source_id, target_id)}), + ) + for source_id, target_id, _ in its + ) + + def _omit_edge_count(self, its): + """Generator comprehension adding the CircuitIds to the iterator.""" + return ( + ( + CircuitNodeId(self.source.name, source_id), + CircuitNodeId(self.target.name, target_id), + ) + for source_id, target_id, _ in its + ) def iter_connections( self, @@ -562,22 +586,14 @@ def iter_connections( source_node_ids = self._resolve_node_ids(self.source, source) target_node_ids = self._resolve_node_ids(self.target, target) - it = self._complete_circuit_node_ids( - self._iter_connections(source_node_ids, target_node_ids, unique_node_ids, shuffle) - ) + it = self._iter_connections(source_node_ids, target_node_ids, unique_node_ids, shuffle) if return_edge_count: - return it + return self._add_circuit_ids(it) elif return_edge_ids: - add_edge_ids = lambda x: ( - x[0], - x[1], - CircuitEdgeIds.from_dict({self.name: self.pair_edges(x[0], x[1])}), - ) - return map(add_edge_ids, it) + return self._add_edge_ids(it) else: - omit_edge_count = lambda x: x[:2] - return map(omit_edge_count, it) + return self._omit_edge_count(it) @property def h5_filepath(self): From 76be0bdb6126db2b9c26d2da368bc5252a9fedae Mon Sep 17 00:00:00 2001 From: "eduard.subert" Date: Mon, 4 Dec 2023 17:45:23 +0100 Subject: [PATCH 5/7] review --- CHANGELOG.rst | 4 ++-- bluepysnap/edges/edge_population.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5e178e84..bf75d7a7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,12 +1,12 @@ Changelog ========= -Version v2.2.0~dev0 +Version v3.0.0 -------------- Breaking Changes ~~~~~~~~~~~~~~~~ -- Edge populations' ``iter_connections`` returns ``CircuitNodeId``s instead of ``int``s +- Edge populations' ``iter_connections`` returns ``CircuitNodeId`` instead of ``int`` Version v2.1.0 diff --git a/bluepysnap/edges/edge_population.py b/bluepysnap/edges/edge_population.py index d5f5ff8b..c32cce72 100644 --- a/bluepysnap/edges/edge_population.py +++ b/bluepysnap/edges/edge_population.py @@ -519,7 +519,7 @@ def _optimal_direction(): break def _add_circuit_ids(self, its): - """Generator comprehension adding the CircuitIds to the iterator.""" + """Generator comprehension completing the CircuitNodeId.""" return ( ( CircuitNodeId(self.source.name, source_id), @@ -530,7 +530,8 @@ def _add_circuit_ids(self, its): ) def _add_edge_ids(self, its): - """Generator comprehension adding the CircuitIds to the iterator.""" + """Generator comprehension completing the CircuitNodeId + and adding the CircuitEdgeIds to the iterator.""" return ( ( CircuitNodeId(self.source.name, source_id), @@ -541,7 +542,8 @@ def _add_edge_ids(self, its): ) def _omit_edge_count(self, its): - """Generator comprehension adding the CircuitIds to the iterator.""" + """Generator comprehension completing the CircuitNodeId + and removing the edge count.""" return ( ( CircuitNodeId(self.source.name, source_id), From 431cd93c11c97e0947d1a0571bba8ced7f3eb5a3 Mon Sep 17 00:00:00 2001 From: "eduard.subert" Date: Mon, 4 Dec 2023 18:07:35 +0100 Subject: [PATCH 6/7] lint --- bluepysnap/edges/edge_population.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bluepysnap/edges/edge_population.py b/bluepysnap/edges/edge_population.py index c32cce72..db8c675a 100644 --- a/bluepysnap/edges/edge_population.py +++ b/bluepysnap/edges/edge_population.py @@ -519,7 +519,8 @@ def _optimal_direction(): break def _add_circuit_ids(self, its): - """Generator comprehension completing the CircuitNodeId.""" + """Completes the CircuitNodeId.""" + return ( ( CircuitNodeId(self.source.name, source_id), @@ -530,8 +531,8 @@ def _add_circuit_ids(self, its): ) def _add_edge_ids(self, its): - """Generator comprehension completing the CircuitNodeId - and adding the CircuitEdgeIds to the iterator.""" + """Completes the CircuitNodeId and adds the CircuitEdgeIds.""" + return ( ( CircuitNodeId(self.source.name, source_id), @@ -542,8 +543,8 @@ def _add_edge_ids(self, its): ) def _omit_edge_count(self, its): - """Generator comprehension completing the CircuitNodeId - and removing the edge count.""" + """Completes the CircuitNodeId and removes the edge count.""" + return ( ( CircuitNodeId(self.source.name, source_id), From 9cd14bc37bb38ce54fb653fd4c61c0390bf598cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20=C5=A0ubert?= <6988280+edasubert@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:23:04 +0100 Subject: [PATCH 7/7] 3.0.0 release (#253) changelog tuning --- CHANGELOG.rst | 17 +++----------- bluepysnap/circuit_validation.py | 1 + bluepysnap/cli.py | 24 +------------------- bluepysnap/query.py | 1 + bluepysnap/schemas/__init__.py | 1 + bluepysnap/schemas/schemas.py | 1 + bluepysnap/simulation_validation.py | 1 + tests/data/reporting/create_reports.py | 1 + tests/test_cli.py | 31 +++++++++----------------- tests/test_schemas.py | 4 ++-- 10 files changed, 23 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bf75d7a7..2bd7b4ae 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,26 +4,15 @@ Changelog Version v3.0.0 -------------- -Breaking Changes -~~~~~~~~~~~~~~~~ -- Edge populations' ``iter_connections`` returns ``CircuitNodeId`` instead of ``int`` - - -Version v2.1.0 --------------- - New Features ~~~~~~~~~~~~ - Added simulation config validation -- Added a new commandline subcommand: ``validate-simulation`` -- Added an alias ``validate-circuit`` for the old ``validate`` subcommand - - - deprecated ``validate`` - +- Added a new commandline subcommands: ``validate-simulation``, ``validate-circuit`` Breaking Changes ~~~~~~~~~~~~~~~~ -- Deprecated the commandline subcommand ``validate`` in favor of new ``validate-circuit`` command +- Edge populations' ``iter_connections`` returns ``CircuitNodeId`` instead of ``int`` +- Removed the commandline subcommand ``validate`` in favor of new ``validate-circuit`` command Version v2.0.2 diff --git a/bluepysnap/circuit_validation.py b/bluepysnap/circuit_validation.py index f7af2b07..0040e412 100644 --- a/bluepysnap/circuit_validation.py +++ b/bluepysnap/circuit_validation.py @@ -2,6 +2,7 @@ The idea here is to not depend on libsonata if possible, so we can use this in all situations """ + import logging from pathlib import Path diff --git a/bluepysnap/cli.py b/bluepysnap/cli.py index e77da4ad..669e8172 100644 --- a/bluepysnap/cli.py +++ b/bluepysnap/cli.py @@ -1,12 +1,11 @@ """The project's command line launcher.""" + import functools import logging -import warnings import click from bluepysnap import circuit_validation, simulation_validation -from bluepysnap.utils import Deprecate CLICK_EXISTING_FILE = click.Path(exists=True, file_okay=True, dir_okay=False) @@ -43,27 +42,6 @@ def wrapper(*args, **kwargs): return wrapper -@cli.command() -@circuit_validation_params -def validate(config_file, skip_slow, only_errors): - """[DEPRECATED] Validate Sonata circuit based on config file. - - Args: - config_file (str): path to Sonata circuit config file - skip_slow (bool): skip slow tests - only_errors (bool): only print fatal errors - """ - with warnings.catch_warnings(): - # Making sure the warning is shown - warnings.simplefilter("always", DeprecationWarning) - Deprecate.warn( - "Calling circuit validation with 'validate' is deprecated. " - "Please use 'validate-circuit' instead." - ) - - circuit_validation.validate(config_file, skip_slow, only_errors) - - @cli.command() @circuit_validation_params def validate_circuit(config_file, skip_slow, only_errors): diff --git a/bluepysnap/query.py b/bluepysnap/query.py index 079b62c5..eed9a3c3 100644 --- a/bluepysnap/query.py +++ b/bluepysnap/query.py @@ -1,4 +1,5 @@ """Module to process search queries of nodes/edges.""" + import operator from collections.abc import Mapping from copy import deepcopy diff --git a/bluepysnap/schemas/__init__.py b/bluepysnap/schemas/__init__.py index 62cb5d4c..0df785bd 100644 --- a/bluepysnap/schemas/__init__.py +++ b/bluepysnap/schemas/__init__.py @@ -1,4 +1,5 @@ """Schemas and schema parser.""" + from bluepysnap.schemas.schemas import ( validate_circuit_schema, validate_edges_schema, diff --git a/bluepysnap/schemas/schemas.py b/bluepysnap/schemas/schemas.py index 222ee90b..1531b6aa 100644 --- a/bluepysnap/schemas/schemas.py +++ b/bluepysnap/schemas/schemas.py @@ -1,4 +1,5 @@ """Functions for schema based validation of circuit files.""" + from pathlib import Path import h5py diff --git a/bluepysnap/simulation_validation.py b/bluepysnap/simulation_validation.py index 6f8b217f..63a23aa8 100644 --- a/bluepysnap/simulation_validation.py +++ b/bluepysnap/simulation_validation.py @@ -1,4 +1,5 @@ """Standalone module that validates Sonata simulation. See ``validate-simulation`` function.""" + import contextlib import io import os diff --git a/tests/data/reporting/create_reports.py b/tests/data/reporting/create_reports.py index 401ec433..761da564 100644 --- a/tests/data/reporting/create_reports.py +++ b/tests/data/reporting/create_reports.py @@ -1,4 +1,5 @@ """Taken from the libsonata lib.""" + import h5py import numpy as np diff --git a/tests/test_cli.py b/tests/test_cli.py index dc939351..5e363262 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,36 +14,20 @@ @patch("bluepysnap.schemas.validate_nodes_schema", Mock(return_value=[])) @patch("bluepysnap.schemas.validate_edges_schema", Mock(return_value=[])) @patch("bluepysnap.schemas.validate_circuit_schema", Mock(return_value=[])) -def test_cli_correct(): +def test_cli_validate_circuit_correct(): runner = CliRunner() - - with pytest.warns( - BluepySnapDeprecationWarning, - match="Calling circuit validation with 'validate' is deprecated", - ): - result = runner.invoke(cli, ["validate", str(TEST_DATA_DIR / "circuit_config.json")]) - + result = runner.invoke(cli, ["validate-circuit", str(TEST_DATA_DIR / "circuit_config.json")]) assert result.exit_code == 0 assert click.style("No Error: Success.", fg="green") in result.stdout -def test_cli_no_config(): +def test_cli_validate_circuit_no_config(): runner = CliRunner() - result = runner.invoke(cli, ["validate"]) + result = runner.invoke(cli, ["validate-circuit"]) assert result.exit_code == 2 assert "Missing argument 'CONFIG_FILE'" in result.stdout -@patch("bluepysnap.schemas.validate_nodes_schema", Mock(return_value=[])) -@patch("bluepysnap.schemas.validate_edges_schema", Mock(return_value=[])) -@patch("bluepysnap.schemas.validate_circuit_schema", Mock(return_value=[])) -def test_cli_validate_circuit_correct(): - runner = CliRunner() - result = runner.invoke(cli, ["validate-circuit", str(TEST_DATA_DIR / "circuit_config.json")]) - assert result.exit_code == 0 - assert click.style("No Error: Success.", fg="green") in result.stdout - - def test_cli_validate_simulation_correct(): runner = CliRunner() result = runner.invoke( @@ -51,3 +35,10 @@ def test_cli_validate_simulation_correct(): ) assert result.exit_code == 0 assert click.style("No Error: Success.", fg="green") in result.stdout + + +def test_cli_validate_simulation_no_config(): + runner = CliRunner() + result = runner.invoke(cli, ["validate-simulation"]) + assert result.exit_code == 2 + assert "Missing argument 'CONFIG_FILE'" in result.stdout diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 0bbc393b..47e7c7bd 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -187,8 +187,8 @@ def test_validate_config_ok_missing_optional_fields(to_remove): [["networks", "edges", 0, "populations"]], "networks.edges[0]: 'populations' is a required property", ), - ([["networks", "nodes", 0]], "networks.nodes: [] is too short"), - ([["networks", "edges", 0]], "networks.edges: [] is too short"), + ([["networks", "nodes", 0]], "networks.nodes: [] should be non-empty"), + ([["networks", "edges", 0]], "networks.edges: [] should be non-empty"), ([["networks", "nodes"]], "networks: 'nodes' is a required property"), ([["networks", "edges"]], "networks: 'edges' is a required property"), ([["networks"]], "'networks' is a required property"),