From eb5467e71bbfb7a019b5c3470885638a28cf5e98 Mon Sep 17 00:00:00 2001 From: "Travis J. Labossiere-Hickman" Date: Fri, 2 Aug 2024 14:52:08 -0600 Subject: [PATCH 1/6] Add simple tallies to break the tests. --- tests/inputs/test.imcnp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/inputs/test.imcnp b/tests/inputs/test.imcnp index 1718b45e..dda8b8d9 100644 --- a/tests/inputs/test.imcnp +++ b/tests/inputs/test.imcnp @@ -44,6 +44,16 @@ C foo m3 1001.80c 2 8016.80c 1 MT3 lwtr.23t h-zr.20t h/zr.28t +C tallies +fc1 Surface current +f1:n,p 1000 +fc2 Average surface flux +f2:p 1005 +fc4 2-group flux +f4:n 1 2 3 +e4 0.625e-6 +f6:p 1 +f7:n 1 C execution ksrc 0 0 0 kcode 100000 1.000 50 1050 From 0e988bf9f55f9880955f14e9cffc3d0e4ccdddf2 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 29 Oct 2024 17:11:39 -0500 Subject: [PATCH 2/6] Made sure tokens generator don't persist. --- montepy/data_inputs/data_input.py | 3 +++ montepy/input_parser/parser_base.py | 1 + 2 files changed, 4 insertions(+) diff --git a/montepy/data_inputs/data_input.py b/montepy/data_inputs/data_input.py index f6cf97f9..3beb8290 100644 --- a/montepy/data_inputs/data_input.py +++ b/montepy/data_inputs/data_input.py @@ -187,6 +187,9 @@ def update_pointers(self, data_inputs): def __str__(self): return f"DATA INPUT: {self._tree['classifier']}" + def __repr__(self): + return str(self) + def __split_name(self, input): """ Parses the name of the data input as a prefix, number, and a particle classifier. diff --git a/montepy/input_parser/parser_base.py b/montepy/input_parser/parser_base.py index ecf313ab..d725cc24 100644 --- a/montepy/input_parser/parser_base.py +++ b/montepy/input_parser/parser_base.py @@ -157,6 +157,7 @@ def gen_wrapper(): # treat any previous errors as being fatal even if it recovered. if len(self.log) > 0: return None + self.tokens = {} return tree precedence = (("left", SPACE), ("left", TEXT)) From f77b1fa1d148a02779725dc13df338fd1e0d9430 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 29 Oct 2024 17:28:29 -0500 Subject: [PATCH 3/6] updated tests to handle updated model with tallies. --- tests/test_integration.py | 24 +++++++++++++++++++++--- tests/test_syntax_parsing.py | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index c5fa2194..2920cd60 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -44,7 +44,7 @@ def data_universe_problem(): def test_original_input(simple_problem): - cell_order = [Message, Title] + [Input] * 17 + cell_order = [Message, Title] + [Input] * 26 for i, input_ob in enumerate(simple_problem.original_inputs): assert isinstance(input_ob, cell_order[i]) @@ -97,7 +97,25 @@ def test_surface_parsing(simple_problem): def test_data_card_parsing(simple_problem): M = material.Material V = volume.Volume - cards = [M, M, M, "KSRC", "KCODE", "PHYS:P", "MODE", V] + cards = [ + M, + M, + M, + "FC1 SURFACE CURRENT", + "F1:N,P", + "FC2 AVERAGE SURFACE FLUX", + "F2:P", + "FC4 2-GROUP FLUX", + "F4:N", + "E4", + "F6:P", + "F7:N", + "KSRC", + "KCODE", + "PHYS:P", + "MODE", + V, + ] for i, card in enumerate(simple_problem.data_inputs): if isinstance(cards[i], str): assert card.classifier.format().upper().rstrip() == cards[i] @@ -178,7 +196,7 @@ def test_write_to_file(simple_problem): else: print("Rewritten data", data.data) print("Original input data", test_problem.data_inputs[i].data) - assert data.data == test_problem.data_inputs[i].data + assert str(data.data) == str(test_problem.data_inputs[i].data) finally: if os.path.exists(out): os.remove(out) diff --git a/tests/test_syntax_parsing.py b/tests/test_syntax_parsing.py index 2596209c..4ad93926 100644 --- a/tests/test_syntax_parsing.py +++ b/tests/test_syntax_parsing.py @@ -1347,7 +1347,7 @@ def testReadInput(self): ) mcnp_in = montepy.input_parser.mcnp_input input_order = [mcnp_in.Message, mcnp_in.Title] - input_order += [mcnp_in.Input] * 17 + input_order += [mcnp_in.Input] * 26 for i, input in enumerate(generator): print(input.input_lines) print(input_order[i]) From 06137b49616b0b8eb258a7f4c16c991cf1da3592 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 29 Oct 2024 17:29:19 -0500 Subject: [PATCH 4/6] Update syntax tree to be as expected in tallies. --- montepy/input_parser/tally_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/montepy/input_parser/tally_parser.py b/montepy/input_parser/tally_parser.py index a5468863..00867dee 100644 --- a/montepy/input_parser/tally_parser.py +++ b/montepy/input_parser/tally_parser.py @@ -20,7 +20,7 @@ def tally(self, p): ret = {} for key, node in p.introduction.nodes.items(): ret[key] = node - ret["tally"] = p.tally_specification + ret["data"] = p.tally_specification return syntax_node.SyntaxNode("data", ret) @_("tally_numbers", "tally_numbers end_phrase") From 6163536acff82b68ea3e7d969210a4fc62a7de94 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 29 Oct 2024 17:43:54 -0500 Subject: [PATCH 5/6] Just forbidding the sly Parser objects. They are just sloppy. --- montepy/mcnp_object.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/montepy/mcnp_object.py b/montepy/mcnp_object.py index 95cb51d9..35e68844 100644 --- a/montepy/mcnp_object.py +++ b/montepy/mcnp_object.py @@ -450,9 +450,10 @@ def allowed_keywords(self): # pragma: no cover def __getstate__(self): state = self.__dict__.copy() - weakref_key = "_problem_ref" - if weakref_key in state: - del state[weakref_key] + bad_keys = {"_problem_ref", "_parser"} + for key in bad_keys: + if key in state: + del state[key] return state def __setstate__(self, crunchy_data): From 9ac5fed71f8050ab1d735649ec08c8bdf35457c7 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 29 Oct 2024 17:49:40 -0500 Subject: [PATCH 6/6] Added #468 to changelog. --- doc/source/changelog.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 2fa0ddc8..ff82c582 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -5,6 +5,13 @@ MontePy Changelog 0.5 releases ============ +#Next version# +-------------- + +**Bug Fixes** + +* Fixed bug where tally inputs in a file prevented the file from being pickled or copied (:issue:`463`). + 0.5.0 --------------