def test_empty_group_size(): 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: grp = h5f["nodes/default/"].create_group("3") with pytest.raises(BluepySnapError): test_module._get_group_size(grp)
def test_invalid_edge_node_ids(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / "edges.h5" with h5py.File(edges_file, "r+") as h5f: h5f["edges/default/source_node_id"][0] = 99999 h5f["edges/default/target_node_id"][0] = 99999 errors = test_module.validate(str(config_copy_path)) assert errors == { Error( Error.FATAL, "/edges/default/source_node_id misses node ids in its node population: [99999]", ), Error( Error.FATAL, "/edges/default/target_node_id misses node ids in its node population: [99999]", ), Error( Error.FATAL, "Population {} edges [99999] have node ids [0 1] instead of " "single id 2".format(edges_file), ), Error( Error.FATAL, "Population {} edges [99999] have node ids [0 1] instead of " "single id 0".format(edges_file), ), }
def test_no_edge_group(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/0'] errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_empty_group_size(): 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: grp = h5f['nodes/default/'].create_group('3') with pytest.raises(BluepySnapError): test_module._get_group_size(grp)
def test_ok_nonbio_node_group_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: h5f['nodes/default/0/model_type'][:] = '' errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_ok_node_ids_dataset(): 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: h5f['nodes/default/node_id'] = list(range(len(h5f['nodes/default/node_type_id']))) errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_invalid_edge_node_ids(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: h5f['edges/default/source_node_id'][0] = 99999 h5f['edges/default/target_node_id'][0] = 99999 errors = test_module.validate(str(config_copy_path)) assert errors == { Error( Error.FATAL, '/edges/default/source_node_id misses node ids in its node population: [99999]' ), Error( Error.FATAL, '/edges/default/target_node_id misses node ids in its node population: [99999]' ), Error( Error.FATAL, 'Population {} edges [99999] have node ids [0 1] instead of ' 'single id 2'.format(edges_file)), Error( Error.FATAL, 'Population {} edges [99999] have node ids [0 1] instead of ' 'single id 0'.format(edges_file)), }
def test_no_morph_files(): 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: h5f["nodes/default/0/morphology"][0] = "noname" errors = test_module.validate(str(config_copy_path)) assert errors == { Error( Error.WARNING, "missing 1 files in group morphology: default/0[{}]:\n\tnoname.swc\n".format( nodes_file ), ) } with h5py.File(nodes_file, "r+") as h5f: morph = h5f["nodes/default/0/morphology"] morph[:] = ["noname" + str(i) for i in range(len(morph))] errors = test_module.validate(str(config_copy_path)) assert errors == { Error( Error.WARNING, "missing 3 files in group morphology: default/0[{}]:\n\tnoname0.swc\n\t...\n".format( nodes_file ), ) }
def test_no_edges_h5(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges'] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'No "edges" in {}.'.format(edges_file))}
def test_invalid_edge_population_type(): with copy_circuit() as (_, config_copy_path): fake_type = "fake_type" with edit_config(config_copy_path) as config: config["networks"]["edges"][0]["populations"]["default"]["type"] = fake_type errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == {Error(Error.WARNING, "Invalid edge type: {}".format(fake_type))}
def test_edge_population_missing_edge_group_index_one_group(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/edge_group_index'] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Population default of {} misses dataset {}'. format(edges_file, {"edge_group_index"}))}
def test_edge_population_missing_edge_group_id_index_one_group(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/edge_group_index'] del h5f['edges/default/edge_group_id'] errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_no_config_edges(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['networks']['edges'] errors = test_module.validate(str(config_copy_path)) assert errors == { Error(Error.FATAL, 'No "edges" in config "networks"') }
def test_no_required_bbp_edge_group_datasets(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/0/syn_weight'] errors = test_module.validate(str(config_copy_path), True) assert errors == {BbpError(Error.WARNING, 'Group default/0 of {} misses fields: {}'. format(edges_file, ['syn_weight']))}
def test_ok_virtual_node_group_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: h5f["nodes/default/0/model_type"][:] = "virtual" del h5f["nodes/default/0/model_template"] errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_nodes_multi_group_wrong_group_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: h5f.copy('nodes/default/0', 'nodes/default/1') h5f['nodes/default/node_group_id'][-1] = 2 errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Population /nodes/default of {} misses group(s): {}'. format(nodes_file, {2}))}
def test_ok_circuit(): errors = test_module.validate(str(TEST_DATA_DIR / 'circuit_config.json')) assert errors == set() with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: config['networks']['nodes'][0]['node_types_file'] = None errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_explicit_edges_no_node_population_attr(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/source_node_id'].attrs['node_population'] errors = test_module.validate(str(config_copy_path)) assert errors == { Error(Error.FATAL, 'Missing "node_population" attribute for "/edges/default/source_node_id"')}
def test_no_edge_source_to_target(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/indices/source_to_target'] del h5f['edges/default/indices/target_to_source'] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'No "source_to_target" in {}'.format(edges_file)), Error(Error.FATAL, 'No "target_to_source" in {}'.format(edges_file))}
def test_edge_population_wrong_group_index(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/edge_group_index'] h5f.create_dataset('edges/default/edge_group_index', data=[0, 1, 2, 12]) errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Group default/0 in file {} should have ids up to {}'. format(edges_file, 12))}
def test_edge_population_multiple_groups(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: h5f.create_group('edges/default/1') errors = test_module.validate(str(config_copy_path), bbp_check=True) assert BbpError(Error.WARNING, 'Population default of {} have multiple groups. ' 'Cannot be read via bluepysnap or libsonata'. format(edges_file)) in errors
def test_edge_population_wrong_group_id(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/edge_group_id'] h5f.create_dataset('edges/default/edge_group_id', data=[0, 1, 0, 0]) errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Population /edges/default of {} misses group(s): {}'. format(edges_file, {1}))}
def test_missing_optional_edge_population_datasets_one_group(): optional_datasets = sorted(['edge_group_id', 'edge_group_index']) with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: for ds in optional_datasets: del h5f['edges/default/' + ds] errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_no_edge_group_no_optional_datasets(): with copy_circuit() as (circuit_copy_path, config_copy_path): optional_datasets = sorted(["edge_group_id", "edge_group_index"]) edges_file = circuit_copy_path / "edges.h5" with h5py.File(edges_file, "r+") as h5f: del h5f["edges/default/0"] for ds in optional_datasets: del h5f["edges/default/" + ds] errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_edge_population_edge_group_different_length(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / 'edges.h5' with h5py.File(edges_file, 'r+') as h5f: del h5f['edges/default/edge_group_index'] h5f.create_dataset('edges/default/edge_group_index', data=[0, 1, 2, 3, 4]) errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Population {} of {} has different sizes of "group_id" and "group_index"'. format('/edges/default', edges_file))}
def test_no_rotation_bio_node_group_datasets(): angle_datasets = ['rotation_angle_xaxis', 'rotation_angle_yaxis', 'rotation_angle_zaxis'] 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 angle_datasets: del h5f['nodes/default/0/' + ds] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.WARNING, 'Group default/0 of {} has no rotation fields'.format(nodes_file))}
def test_no_bio_component_dirs(): dirs = ['morphologies_dir', 'biophysical_neuron_models_dir'] for dir_ in dirs: with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['components'][dir_] errors = test_module.validate(str(config_copy_path), True) # multiplication by 2 because we have 2 populations, each produces the same error. assert errors == {BbpError(Error.FATAL, 'Invalid components "{}": {}'.format(dir_, None))}
def test_no_template_files(): 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: h5f['nodes/default/0/model_template'][0] = 'hoc:noname' errors = test_module.validate(str(config_copy_path)) assert errors == { Error(Error.WARNING, 'missing 1 files in group model_template: default/0[{}]:\n\tnoname.hoc\n' .format(nodes_file))}
def test_invalid_config_edges_file(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['networks']['edges'][0]['edges_file'] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "edges_file": None')} with edit_config(config_copy_path) as config: config['networks']['edges'][0]['edges_file'] = '/' errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "edges_file": /')}
def test_no_edge_all_node_ids(): 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/default/0'] errors = test_module.validate(str(config_copy_path)) assert errors == { Error(Error.FATAL, '/edges/default/source_node_id does not have node ids in its node population'), Error(Error.FATAL, '/edges/default/target_node_id does not have node ids in its node population')}