Skip to content

Commit

Permalink
Don't raise errors when node_id is defined implicitly. (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
asanin-epfl committed Jul 14, 2020
1 parent c098e29 commit c0c6663
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
16 changes: 10 additions & 6 deletions bluepysnap/circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,19 @@ def _check_nodes_population(nodes_dict, config):
Returns:
list: List of errors, empty if no errors
"""
POPULATION_DATASET_NAMES = ['node_type_id', 'node_group_id', 'node_group_index']
required_datasets = ['node_type_id']
errors = []
nodes_file = nodes_dict.get('nodes_file')
with h5py.File(nodes_file, 'r') as h5f:
nodes = _get_h5_data(h5f, 'nodes')
if not nodes or len(nodes) == 0:
errors.append(fatal('No "nodes" in {}.'.format(nodes_file)))
return errors
if len(nodes.keys()) > 1:
required_datasets += ['node_group_id', 'node_group_index']
for population_name in nodes:
population = nodes[population_name]
missing_datasets = sorted(set(POPULATION_DATASET_NAMES) - set(population))
missing_datasets = sorted(set(required_datasets) - set(population))
if missing_datasets:
errors.append(fatal('Population {} of {} misses datasets {}'.
format(population_name, nodes_file, missing_datasets)))
Expand Down Expand Up @@ -355,10 +357,12 @@ def _get_node_ids(node_population):
if 'node_id' in node_population:
node_ids = node_population['node_id'][:]
else:
node_size_ds = _get_h5_data(node_population, 'node_type_id') \
or _get_h5_data(node_population, 'node_group_id')
if node_size_ds:
node_ids = np.arange(len(node_size_ds))
grp = _get_h5_data(node_population, '0')
if grp:
for attr in grp:
if isinstance(grp[attr], h5py.Dataset):
node_ids = np.arange(len(grp[attr]))
break
return node_ids


Expand Down
24 changes: 18 additions & 6 deletions tests/test_circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,23 @@ def test_ok_node_ids_dataset():
assert errors == []


def test_no_required_node_population_datasets():
def test_no_required_node_single_population_datasets():
with copy_circuit() as (circuit_copy_path, config_copy_path):
nodes_file = circuit_copy_path / 'nodes.h5'
with h5py.File(nodes_file, 'r+') as h5f:
del h5f['nodes/default2/']
del h5f['nodes/default/node_group_id']
del h5f['nodes/default/node_group_index']
errors = test_module.validate(str(config_copy_path))
assert errors == []
with h5py.File(nodes_file, 'r+') as h5f:
del h5f['nodes/default/node_type_id']
errors = test_module.validate(str(config_copy_path))
assert errors == [Error(Error.FATAL, 'Population default of {} misses datasets {}'.
format(nodes_file, ['node_type_id']))]


def test_no_required_node_multi_population_datasets():
required_datasets = ['node_type_id', 'node_group_id', 'node_group_index']
for ds in required_datasets:
with copy_circuit() as (circuit_copy_path, config_copy_path):
Expand Down Expand Up @@ -504,16 +520,12 @@ def test_no_edge_source_to_target():


def test_no_edge_all_node_ids():
node_ids_ds = ['node_group_id', 'node_type_id']
with copy_circuit() as (circuit_copy_path, config_copy_path):
nodes_file = circuit_copy_path / 'nodes.h5'
with h5py.File(nodes_file, 'r+') as h5f:
for ds in node_ids_ds:
del h5f['nodes/default/' + ds]
del h5f['nodes/default/0']
errors = test_module.validate(str(config_copy_path))
assert errors == [
Error(Error.FATAL,
'Population default of {} misses datasets {}'.format(nodes_file, node_ids_ds)),
Error(Error.FATAL,
'/edges/default/source_node_id does not have node ids in its node population'),
Error(Error.FATAL,
Expand Down

0 comments on commit c0c6663

Please sign in to comment.