From 64e34b7506e711e15bafe24d3f56ff22ab4b03e6 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 29 Nov 2022 13:27:01 +0800 Subject: [PATCH 1/2] fix issue #381. The returned system should be of the same type as the perturbed system --- dpdata/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpdata/system.py b/dpdata/system.py index 5451e22ae..53745c685 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -810,7 +810,7 @@ def perturb(self, perturbed_system : System The perturbed_system. It contains `pert_num` * frame_num of the input system frames. """ - perturbed_system = System() + perturbed_system = type(self)() nframes = self.get_nframes() for ii in range(nframes): for jj in range(pert_num): From 3acea37abcfd27115e8e46d275c006bd9742d86b Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 30 Nov 2022 11:24:09 +0800 Subject: [PATCH 2/2] raise run time error when the labeled system is perturbed --- dpdata/system.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dpdata/system.py b/dpdata/system.py index 53745c685..6089db46d 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -810,7 +810,12 @@ def perturb(self, perturbed_system : System The perturbed_system. It contains `pert_num` * frame_num of the input system frames. """ - perturbed_system = type(self)() + if type(self) is not dpdata.System: + raise RuntimeError( + f'Using method perturb() of an instance of {type(self)}. ' + f'Must use method perturb() of the instance of class dpdata.System.' + ) + perturbed_system = System() nframes = self.get_nframes() for ii in range(nframes): for jj in range(pert_num):