Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TestDeepPotAPBCExcludeTypes #2680

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions source/tests/test_model_compression_se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,29 @@ def _init_models():
return INPUT, frozen_model, compressed_model


def _init_models_exclude_types():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original-exclude-types.pb")
compressed_model = str(tests_path / "dp-compressed-exclude-types.pb")
INPUT = str(tests_path / "input.json")
jdata = j_loader(str(tests_path / os.path.join("model_compression", "input.json")))
jdata["model"]["descriptor"]["exclude_types"] = [[0, 1]]
jdata["training"]["training_data"]["systems"] = data_file
jdata["training"]["validation_data"]["systems"] = data_file
with open(INPUT, "w") as fp:
json.dump(jdata, fp, indent=4)

ret = run_dp("dp train " + INPUT)
np.testing.assert_equal(ret, 0, "DP train failed!")
ret = run_dp("dp freeze -o " + frozen_model)
np.testing.assert_equal(ret, 0, "DP freeze failed!")
ret = run_dp("dp compress " + " -i " + frozen_model + " -o " + compressed_model)
np.testing.assert_equal(ret, 0, "DP model compression failed!")
return INPUT, frozen_model, compressed_model


INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
INPUT_ET, FROZEN_MODEL_ET, COMPRESSED_MODEL_ET = _init_models_exclude_types()


class TestDeepPotAPBC(unittest.TestCase):
Expand Down Expand Up @@ -410,8 +432,8 @@ def test_ase(self):
class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.dp_original = DeepPot(FROZEN_MODEL_ET)
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
self.coords = np.array(
[
12.83,
Expand Down Expand Up @@ -439,9 +461,9 @@ def setUpClass(self):

@classmethod
def tearDownClass(self):
_file_delete(INPUT)
_file_delete(FROZEN_MODEL)
_file_delete(COMPRESSED_MODEL)
_file_delete(INPUT_ET)
_file_delete(FROZEN_MODEL_ET)
_file_delete(COMPRESSED_MODEL_ET)
_file_delete("out.json")
_file_delete("compress.json")
_file_delete("checkpoint")
Expand Down