From ac80d601b784d5a09de8cabed9fe09e2edfa440d Mon Sep 17 00:00:00 2001 From: Eric Sivonxay Date: Fri, 5 Jan 2024 17:37:25 -0800 Subject: [PATCH 1/2] Fix species test --- src/NanoParticleTools/species_data/species.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NanoParticleTools/species_data/species.py b/src/NanoParticleTools/species_data/species.py index dc209e9..788b10e 100644 --- a/src/NanoParticleTools/species_data/species.py +++ b/src/NanoParticleTools/species_data/species.py @@ -204,7 +204,7 @@ def species_data(self) -> dict[str, tuple[list[str], list[float]]]: with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'), 'r') as f: species_data = json.load(f) - except FileNotFoundError: + except FileNotFoundError as e: # File was not found, check if it is a legacy calc if self.symbol in self.LEGACY_SURFACE_NAMES: # This is a legacy calc. Load the corresponding calc @@ -212,6 +212,8 @@ def species_data(self) -> dict[str, tuple[list[str], list[float]]]: with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'), 'r') as f: species_data = json.load(f) + else: + raise e return species_data From 69293d2a1ba17b7805a5725918f8cb17a8afb2b3 Mon Sep 17 00:00:00 2001 From: Eric Sivonxay Date: Fri, 5 Jan 2024 17:43:25 -0800 Subject: [PATCH 2/2] Fix failing graph data tests --- .../models/gnn_model/test_graph_data.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/machine_learning/models/gnn_model/test_graph_data.py b/tests/machine_learning/models/gnn_model/test_graph_data.py index fe3c88a..74a9880 100644 --- a/tests/machine_learning/models/gnn_model/test_graph_data.py +++ b/tests/machine_learning/models/gnn_model/test_graph_data.py @@ -166,9 +166,9 @@ def test_graph_interaction_feature_processor(doc_one): data = feature_processor.data_cls(**_data_dict) assert data.radii.shape == (3, ) assert data.constraint_radii_idx.shape == (2, 2) - assert torch.allclose(data.constraint_indices, torch.tensor([0, 0, 1, 1])) - assert data.x.shape == (4, ) - assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0.2, 0.1])) + assert torch.allclose(data.dopant_constraint_indices, torch.tensor([0, 0, 1, 1])) + assert data.dopant_concs.shape == (4, ) + assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0.2, 0.1])) assert data.edge_index.shape == (2, 32) @@ -180,10 +180,10 @@ def test_graph_interaction_feature_processor_zeros(doc_one): data = feature_processor.data_cls(**_data_dict) assert data.radii.shape == (3, ) assert data.constraint_radii_idx.shape == (2, 2) - assert torch.allclose(data.constraint_indices, + assert torch.allclose(data.dopant_constraint_indices, torch.tensor([0, 0, 0, 1, 1, 1])) - assert data.x.shape == (6, ) - assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0])) + assert data.dopant_concs.shape == (6, ) + assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0])) assert data.edge_index.shape == (2, 72) @@ -195,10 +195,10 @@ def test_invalid_doc(doc_one_invalid): data = feature_processor.data_cls(**_data_dict) assert data.radii.shape == (3, ) assert data.constraint_radii_idx.shape == (2, 2) - assert torch.allclose(data.constraint_indices, + assert torch.allclose(data.dopant_constraint_indices, torch.tensor([0, 0, 0, 1, 1, 1])) - assert data.x.shape == (6, ) - assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0])) + assert data.dopant_concs.shape == (6, ) + assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0])) assert data.edge_index.shape == (2, 72) feature_processor = GraphInteractionFeatureProcessor( @@ -207,9 +207,9 @@ def test_invalid_doc(doc_one_invalid): data = feature_processor.data_cls(**_data_dict) assert data.radii.shape == (3, ) assert data.constraint_radii_idx.shape == (2, 2) - assert torch.allclose(data.constraint_indices, torch.tensor([0, 0, 1, 1])) - assert data.x.shape == (4, ) - assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0.2, 0.1])) + assert torch.allclose(data.dopant_constraint_indices, torch.tensor([0, 0, 1, 1])) + assert data.dopant_concs.shape == (4, ) + assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0.2, 0.1])) assert data.edge_index.shape == (2, 32) @@ -220,7 +220,7 @@ def test_grad(doc_four): _data_dict = feature_processor.process_doc(doc_four) data = feature_processor.data_cls(**_data_dict) assert data.radii.requires_grad - assert data.x.requires_grad + assert data.dopant_concs.requires_grad feature_processor = GraphInteractionFeatureProcessor( possible_elements=['Yb', 'Er', 'Mg'], input_grad=False) @@ -228,4 +228,4 @@ def test_grad(doc_four): _data_dict = feature_processor.process_doc(doc_four) data = feature_processor.data_cls(**_data_dict) assert not data.radii.requires_grad - assert not data.x.requires_grad + assert not data.dopant_concs.requires_grad