Skip to content

Commit

Permalink
Merge branch 'develop' into pickle_tallies
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Sep 10, 2024
2 parents 41598be + 5a12a28 commit a1de63d
Show file tree
Hide file tree
Showing 36 changed files with 18,384 additions and 1,601 deletions.
32 changes: 31 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,38 @@ jobs:
python-version: 3.12
- run: pip install . montepy[format]
- run: black --check montepy/ tests/


profile:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: set up python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- run: pip install . montepy[test]
- run: pytest --profile
name: Profile test suite
- run: python prof/dump_results.py
name: Display pytest profiling data
- run: python prof/profile_big_model.py
name: Profile against big model

benchmark:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: set up python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- run: pip install . montepy[test]
- run: python benchmark/benchmark_big_model.py
name: Benchmark against big model


changelog-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist/*
.coverage
.idea/*
*.*.sw*
*.prof
doc/build/*
.coverage
.idea/
Expand Down
77 changes: 49 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![PyPI version](https://badge.fury.io/py/montepy.svg)](https://badge.fury.io/py/montepy)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)

MontePy is a python library to read, edit, and write MCNP input files.
MontePy is the most user friendly Python library for reading, editing, and writing MCNP input files.

## Installing

Expand All @@ -24,35 +24,56 @@ see the [Installing section in the user guide](https://www.montepy.org/starting.

## User Documentation

MontePy has a [sphinx website](https://www.montepy.org/).
This has a getting started guide for users,
as well as API documentation.
There is also a developer's guide covering the design and approach of MontePy, and how to contribute.
MontePy has a website [documenting how to work with MCNP in python with MontePy](https://www.montepy.org/).
The website contains a user's guide for getting started,
a developer's guide covering the design and approach of MontePy,
instructions for contributing,
and the Python API documentation.

## Features

* Handles almost all MCNP input syntax including: message blocks, & continue, comments, etc.
* Parses Cells, surfaces, materials, and transforms very well.
* Can parse the following surfaces exactly P(X|Y|Z), C(X|Y|Z), C/(X|Y|Z) (I mean it can do PX, and PY, etc.)
* Can read in all other inputs but not understand them
* Can write out full MCNP problem even if it doesn't fully understand an input.
* Can write out the MCNP problem verbatim, and try to match the original user formatting.
* Can quickly access cells, surfaces, and materials by their numbers. For example: `cell = problem.cells[105]`.
* Can quickly update cell importances. For example `cell.importance.neutron = 2.0`.
* Has over 240 test cases right now
* Handles almost all MCNP input syntax.
* Parses Cells, Surfaces, Materials, and Transforms very well.
* Can parse all surface types except macrobody facets ([Issue #354](https://github.com/idaholab/MontePy/issues/354)).
* Can read and write out all other MCNP inputs, even if it doesn't not understand them
* Attempts to write out the MCNP problem verbatim, even matching the original user formatting. (See some of the [open issues](https://github.com/idaholab/MontePy/issues).)
* Can quickly [access cells, surfaces, and materials by their numbers](https://www.montepy.org/starting.html#collections-are-accessible-by-number). For example: `cell = problem.cells[105]`.
* Can quickly update cell parameters, [such as importances](https://www.montepy.org/starting.html#setting-cell-importances). For example `cell.importance.neutron = 2.0`.
* Can easily [create universes, and fill other cells with universes](https://www.montepy.org/starting.html#universes).
* Currently has over 430 test cases.


Quick example for renumbering all of the cells in a problem:
Here is a quick example showing multiple tasks in MontePy:

```python
import montepy
foo = montepy.read_input("foo.imcnp")
i = 9500
for cell in foo.cells:
cell.number = i
i = i + 5
# read in file
problem = montepy.read_input("foo.imcnp")

foo.write_to_file("foo_update.imcnp")
# set photon importance for multiple cells
importances = {1: 0.005,
2: 0.1,
3: 1.0,
99: 1.235
}
for cell_num, importance in importances.items():
problem.cells[cell_num].importance.photon = importance

#create a universe and fill another cell with it
universe = montepy.Universe(123)
problem.univeres.append(universe)
# add all cells with numbers between 1 and 4
universe.claim(problem.cells[1:5])
# fill cell 99 with universe 123
problem.cells[99].fill.universe = universe

# update all surfaces numbers by adding 1000 to them
for surface in problem.surfaces:
surface.number += 1000
# all cells using these surfaces will be automatically updated as well

#write out an updated file
problem.write_problem("foo_update.imcnp")

```

Expand All @@ -62,16 +83,16 @@ Here a few of the known bugs and limitations:


* Cannot handle vertical input mode.
* Does not support tallies in an easy way.
* Does not support source definition in an easy way.
* Does not support editing tallies in a user-friendly way.
* Does not support editing source definition in a user-friendly way.

## Bugs, Requests and Development

So MontePy doesn't do what you want? Right now development is done with a Just-In-Time development approach, as in features are added JIT for a developer to use them on my current projects.
If there's a feature you want add an issue here with the feature request tag.
If you want to add a feature on your own talk to Micah Gale (but still add the issue).
So MontePy doesn't do what you want?
Add an issue here with the "feature request" tag.
The system is very modular and you should be able to develop it pretty quickly.
Also read the [developer's guide](https://www.montepy.org/developing.html).
Read the [developer's guide](https://www.montepy.org/developing.html) for more details.
If you have any questions feel free to ask [@micahgale](mailto:mgale@montepy.org).


# Finally: make objects not regexes!
# Finally: make objects, not regexes!
21 changes: 21 additions & 0 deletions benchmark/benchmark_big_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import montepy

import time
import tracemalloc

FAIL_THRESHOLD = 30

tracemalloc.start()
start = time.time()

problem = montepy.read_input("benchmark/big_model.imcnp")

stop = time.time()

print(f"Took {stop - start} seconds")
print(f"Memory usage report: {tracemalloc.get_traced_memory()}")

if (stop - start) > FAIL_THRESHOLD:
raise RuntimeError(
f"Benchmark took too long to complete. It must be faster than: {FAIL_THRESHOLD} s."
)
Loading

0 comments on commit a1de63d

Please sign in to comment.