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

Release 0.5.1 #585

Merged
merged 52 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
eb5467e
Add simple tallies to break the tests.
tjlaboss Aug 2, 2024
9b4d15d
Merge branch 'develop' into pickle_tallies
MicahGale Aug 14, 2024
41598be
Merge branch 'develop' into pickle_tallies
MicahGale Aug 17, 2024
a1de63d
Merge branch 'develop' into pickle_tallies
MicahGale Sep 10, 2024
dd01894
Merge branch 'develop' into pickle_tallies
MicahGale Sep 10, 2024
298a4a6
Merge branch 'develop' into pickle_tallies
MicahGale Oct 9, 2024
66ff283
Merge branch 'develop' into pickle_tallies
MicahGale Oct 10, 2024
dda72f4
Merge branch 'develop' into pickle_tallies
MicahGale Oct 15, 2024
8d256f7
Moved test_version to pytest.
MicahGale Oct 16, 2024
5fee5d7
Ensured _version is always available in tests.
MicahGale Oct 16, 2024
72e4dd5
Setup git archive to work well with setuptools scm.
MicahGale Oct 17, 2024
524d3c4
Started an archive test.
MicahGale Oct 17, 2024
dce154c
Improved archive test
MicahGale Oct 17, 2024
0b89d07
Did final test of archive version.
MicahGale Oct 17, 2024
b095356
Update main.yml
MicahGale Oct 17, 2024
ac2ac60
Added pip install step.
MicahGale Oct 17, 2024
5b9f522
Made deep checkout.
MicahGale Oct 17, 2024
2e5c6bf
Made more verbose and actually fail on error.
MicahGale Oct 17, 2024
8332739
Update main.yml
MicahGale Oct 17, 2024
0fa943d
debugging.
MicahGale Oct 18, 2024
21675aa
debug
MicahGale Oct 18, 2024
8205595
debug
MicahGale Oct 18, 2024
f4bb540
Converted to manual archive.
MicahGale Oct 18, 2024
cccf9cc
Update main.yml
MicahGale Oct 18, 2024
ee06768
Update main.yml
MicahGale Oct 18, 2024
ee075ec
Try deleting arhcive tests
MicahGale Oct 18, 2024
da04fdc
Updated test to replicate #580
MicahGale Oct 23, 2024
237ba09
Implemented _grab_beginning_comment for all SyntaxNode.
MicahGale Oct 23, 2024
ead7f45
Added #580 to changelog.
MicahGale Oct 23, 2024
34ea7e5
Started documenting how Importance works.
MicahGale Oct 24, 2024
9a468e5
Made Comment node equality work.
MicahGale Oct 24, 2024
495ecaa
Documented variables fully.
MicahGale Oct 24, 2024
12a3e65
tried to fix the craziness of importance syntax trees.
MicahGale Oct 24, 2024
f73af07
Made method to track previous object for grabbing comments. Not sure …
MicahGale Oct 24, 2024
0e988bf
Made sure tokens generator don't persist.
MicahGale Oct 29, 2024
f77b1fa
updated tests to handle updated model with tallies.
MicahGale Oct 29, 2024
06137b4
Update syntax tree to be as expected in tallies.
MicahGale Oct 29, 2024
6163536
Just forbidding the sly Parser objects. They are just sloppy.
MicahGale Oct 29, 2024
9ac5fed
Added #468 to changelog.
MicahGale Oct 29, 2024
2f9a0c1
Merge pull request #468 from idaholab/pickle_tallies
MicahGale Oct 29, 2024
1e615bd
Merge branch 'develop' into 572-unit-test-failure-test_version-v041
MicahGale Oct 29, 2024
3e546c5
Merge pull request #574 from idaholab/572-unit-test-failure-test_vers…
MicahGale Oct 29, 2024
c13b0e4
Merge branch 'develop' into 576-make-version-info-more-reliable-for-g…
MicahGale Oct 29, 2024
2850c97
Merge pull request #577 from idaholab/576-make-version-info-more-reli…
MicahGale Oct 29, 2024
2ee8e33
The integration added a 4th line.
tjlaboss Oct 29, 2024
fc0fdb9
Merge branch 'develop' into 580-syntaxnode-object-has-no-attribute-_g…
tjlaboss Oct 29, 2024
c87d7fe
----
tjlaboss Oct 29, 2024
59ac966
Fix importance integration test for new comments
tjlaboss Oct 30, 2024
92e50b3
Gave up and just suppress ending blank lines.
MicahGale Oct 30, 2024
e0f324f
Cleaned up syntax thanks to @tjlaboss.
MicahGale Oct 30, 2024
c0bbeba
Merge pull request #582 from idaholab/580-syntaxnode-object-has-no-at…
MicahGale Oct 30, 2024
9e77f4f
Updating changelog to next version: 0.5.1
MicahGale Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ jobs:
with:
file: coverage.xml
github-token: ${{ secrets.github_token }}




doc-test:
Expand Down
8 changes: 8 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ MontePy Changelog
0.5 releases
============

0.5.1
--------------

**Bug Fixes**

* Fixed ``AttributeError`` that occured when a data block ``IMP`` was preceded by a comment (:issue:`580`).
* Fixed bug where tally inputs in a file prevented the file from being pickled or copied (:issue:`463`).

0.5.0
--------------

Expand Down
7 changes: 6 additions & 1 deletion montepy/data_inputs/cell_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ def format_for_mcnp_input(self, mcnp_version, has_following=False):
# print in either block
if (self.in_cell_block != print_in_data_block) and self._is_worth_printing:
self._update_values()
return self.wrap_string_for_mcnp(self._format_tree(), mcnp_version, True)
return self.wrap_string_for_mcnp(
self._format_tree(),
mcnp_version,
True,
suppress_blank_end=not self.in_cell_block,
)
return []

@property
Expand Down
3 changes: 3 additions & 0 deletions montepy/data_inputs/data_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
66 changes: 53 additions & 13 deletions montepy/data_inputs/importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
from montepy.utilities import *
import numbers

#
# ********************* Developer Notes ********************************************
#
# How Importance handles syntax trees is complicated.
# One object holds information for N particle types.
# This can be associated with between 1 and N syntax trees (imp:n,p v. imp:n imp:p)
#
# Variables
#
# * _tree : the syntax tree from parsing. Only used on initial parsing
# * _real_tree : holds unique trees for every particle type. This is used in data block formatting.
# * _particle_importances : a dictionary of ParameterNodes that maps a particle to it's ParameterNode
# * _part_combos : a list of ParticleNode that show which particles were combined on the original input


class Importance(CellModifierInput):
"""
Expand Down Expand Up @@ -368,22 +382,48 @@ def __delete_common_trailing(self, part):
for combo_set in self._part_combos:
if part in combo_set:
to_delete |= combo_set
for part in to_delete:
self._particle_importances[part]["data"]._delete_trailing_comment()
if self._in_cell_block:
for part in to_delete:
self._particle_importances[part]["data"]._delete_trailing_comment()
else:
for part in to_delete:
self._real_tree[part]._delete_trailing_comment()

def _grab_beginning_comment(self, new_padding):
def _grab_beginning_comment(self, new_padding, last_obj=None):
last_tree = None
last_padding = None
for part, tree in self._particle_importances.items():
if last_padding is not None and last_tree is not None:
last_tree._grab_beginning_comment(last_padding)
self.__delete_common_trailing(part)
last_padding = tree.get_trailing_comment()
last_tree = tree
if new_padding:
next(iter(self._particle_importances.values()))[
"start_pad"
]._grab_beginning_comment(new_padding)
if self._in_cell_block:
if not isinstance(last_obj, Importance):
for part, tree in self._particle_importances.items():
if last_padding is not None and last_tree is not None:
last_tree._grab_beginning_comment(last_padding)
self.__delete_common_trailing(part)
last_padding = tree.get_trailing_comment()
last_tree = tree
if new_padding:
next(iter(self._particle_importances.values()))[
"start_pad"
]._grab_beginning_comment(new_padding)
else:
# if not inside a block of importances
if not isinstance(last_obj, Importance):
for part, tree in self._real_tree.items():
if tree.get_trailing_comment() == last_padding:
continue
if last_padding is not None and last_tree is not None:
last_tree._grab_beginning_comment(last_padding)
self.__delete_common_trailing(part)
last_padding = tree.get_trailing_comment()
last_tree = tree
if new_padding:
next(iter(self._real_tree.values()))[
"start_pad"
]._grab_beginning_comment(new_padding)
# otherwise keep it as is inside the block
else:
list(self._real_tree.values())[-1]["start_pad"]._grab_beginning_comment(
new_padding
)


def _generate_default_data_tree(particle):
Expand Down
1 change: 1 addition & 0 deletions montepy/input_parser/parser_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions montepy/input_parser/syntax_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ def _delete_trailing_comment(self):
if isinstance(tail, SyntaxNodeBase):
tail._delete_trailing_comment()

def _grab_beginning_comment(self, extra_padding):
"""
Consumes the provided comment, and moves it to the beginning of this node.

:param extra_padding: the padding comment to add to the beginning of this padding.
:type extra_padding: list
"""
if len(self.nodes) == 0 or extra_padding is None:
return
head = self.nodes[0]
if isinstance(head, SyntaxNodeBase):
head._grab_beginning_comment(extra_padding)

def check_for_graveyard_comments(self, has_following_input=False):
"""
Checks if there is a graveyard comment that is preventing information from being part of the tree, and handles
Expand Down Expand Up @@ -260,6 +273,19 @@ def get_trailing_comment(self):
if node:
return node.get_trailing_comment()

def _grab_beginning_comment(self, extra_padding):
"""
Consumes the provided comment, and moves it to the beginning of this node.

:param extra_padding: the padding comment to add to the beginning of this padding.
:type extra_padding: list
"""
if len(self.nodes) == 0 or extra_padding is None:
return
head = next(iter(self.nodes.values()))
if isinstance(head, SyntaxNodeBase):
head._grab_beginning_comment(extra_padding)

def _get_trailing_node(self):
if len(self.nodes) == 0:
return
Expand Down Expand Up @@ -822,6 +848,9 @@ def __repr__(self):
ret += node.format()
return ret

def __eq__(self, other):
return str(self) == str(other)


class ValueNode(SyntaxNodeBase):
"""
Expand Down
2 changes: 1 addition & 1 deletion montepy/input_parser/tally_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 14 additions & 5 deletions montepy/mcnp_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def leading_comments(self):
self._tree["start_pad"]._delete_trailing_comment()

@staticmethod
def wrap_string_for_mcnp(string, mcnp_version, is_first_line):
def wrap_string_for_mcnp(
string, mcnp_version, is_first_line, suppress_blank_end=True
):
"""
Wraps the list of the words to be a well formed MCNP input.

Expand All @@ -197,6 +199,9 @@ def wrap_string_for_mcnp(string, mcnp_version, is_first_line):
:param is_first_line: If true this will be the beginning of an MCNP input.
The first line will not be indented.
:type is_first_line: bool
:param suppress_blank_end: Whether or not to suppress any blank lines that would be added to the end.
Good for anywhere but cell modifiers in the cell block.
:type suppress_blank_end: bool
:returns: A list of strings that can be written to an input file, one item to a line.
:rtype: list
"""
Expand Down Expand Up @@ -228,6 +233,9 @@ def wrap_string_for_mcnp(string, mcnp_version, is_first_line):
LineExpansionWarning,
stacklevel=2,
)
# lazy final guard against extra lines
if suppress_blank_end:
buffer = [s for s in buffer if s.strip()]
ret += buffer
return ret

Expand Down Expand Up @@ -282,7 +290,7 @@ def trailing_comment(self):
def _delete_trailing_comment(self):
self._tree._delete_trailing_comment()

def _grab_beginning_comment(self, padding):
def _grab_beginning_comment(self, padding, last_obj=None):
if padding:
self._tree["start_pad"]._grab_beginning_comment(padding)

Expand Down Expand Up @@ -450,9 +458,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):
Expand Down
2 changes: 1 addition & 1 deletion montepy/mcnp_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def parse_input(self, check_input=False, replace=True):
if isinstance(obj, transform.Transform):
self._transforms.append(obj, False)
if trailing_comment is not None and last_obj is not None:
obj._grab_beginning_comment(trailing_comment)
obj._grab_beginning_comment(trailing_comment, last_obj)
last_obj._delete_trailing_comment()
trailing_comment = obj.trailing_comment
last_obj = obj
Expand Down
10 changes: 10 additions & 0 deletions tests/inputs/test.imcnp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ m3 1001.80c 2
8016.80c 1
plib=84p
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
Expand Down
1 change: 1 addition & 0 deletions tests/inputs/test_importance.imcnp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ m3 1001.80c 2
MT3 lwtr.23t
C execution
ksrc 0 0 0
c other special comment for #580
imp:n,p 1 1 1 0 3
c special comment related to #520
imp:e 0 2r 1 r
Expand Down
32 changes: 25 additions & 7 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -493,9 +511,9 @@ def test_importance_format_unmutated(importance_problem):
imp = importance_problem.cells._importance
output = imp.format_for_mcnp_input((6, 2, 0))
print(output)
assert len(output) == 3
assert "imp:n,p 1 1 1 0 3" == output[0]
assert "imp:e 0 2r 1 r" == output[2]
assert len(output) == 4
assert "imp:n,p 1 1 1 0 3" == output[1]
assert "imp:e 0 2r 1 r" == output[3]


def test_importance_format_mutated(importance_problem):
Expand All @@ -505,7 +523,7 @@ def test_importance_format_mutated(importance_problem):
with pytest.warns(LineExpansionWarning):
output = imp.format_for_mcnp_input((6, 2, 0))
print(output)
assert len(output) == 4
assert len(output) == 6
assert "imp:n 0.5 1 1 0 3" in output
assert "c special comment related to #520" == output[2]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_syntax_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Loading
Loading