Getting Started with MontePy#

MontePy is a Python API for reading, editing, and writing MCNP input files. The library provides a semantic interface for working with input files (“MCNP problems”). It does not run MCNP, nor does it parse MCNP output files. It understands that the second entry on a cell card is the material number, and will link the cell with its material object.

Note

MontePy is built primarily to support MCNP 6.2, and MCNP 6.3. Some success maybe achieved with MCNP 6.1, and 5.1.60, but there may be issues due to new features in MCNP 6.2, not being backwards compatible. Use earlier versions of MCNP with MontePy at your own risk.

MCNP 6.3 is not fully supported yet either. An MCNP 6.3 file that is backwards compatible with 6.2 should work fine, but when using the new syntaxes in 6.3, especially for materials, MontePy will likely break.

Due to the manuals for these earlier versions of MCNP being export controlled, these versions will likely never be fully supported.

Run Interactively in your Browser#

You can run python and MontePy straight from your browser below:

Try MontePy

Installing#

System Wide (for the current user)#

Note

If you are planning to use this in a jupyter notebook on an HPC, the HPC may use modules for python, which may make it so the installed MontePy package doesn’t show up in the jupyter environment. In this case the easiest way to deal with this is to open a teminal inside of jupyter lab and to install the package there.

  1. Install it from PyPI by running pip install montepy. You may need to run pip install --user montepy if you are not allowed to install the package.

Installing Optional Dependencies#

MontePy offers multiple optional dependencies which some users may desire, though this is mostly intended for developers. Pip can install these through the following command:

pip install montepy[<extras>]

Where <extras> is one of the following options:

  1. demos: installs the dependencies for running the demo problems in jupyter.

  2. doc: installs the dependencies for building the website using sphinx.

  3. build: installs the dependencies for building the source distribution packages.

  4. format: install the dependencies for formatting the code with black.

  5. test: installs the dependencies for testing the software.

  6. demo-test: installs the dependencies for testing the demos.

  7. develop: installs everything a developer may need, specifically: montepy[test,doc,format,demo-test].

Install specific version for a project#

The best way maybe to setup a project-specific conda, Mamba, or a venv environment. The steps for installing inside one of those environments are the same as the previous steps. You can specify a specific version from PyPI be installed using:

pip install montepy==<version>

Or using conda-forge:

conda install conda-forge::montepy==<version>

Tutorials and Demonstrations#

We have presented a workshop for using MontePy in the past. The demonstration Jupyter notebooks are now available in our git repository.

These can be ran in your browser using jupyter lite.

These tutorial can be launched here:

To access these demonstrations locally you can run:

git clone https://github.com/idaholab/MontePy.git
pip install montepy[demos]
cd MontePy/demos
jupyter lab

These notebooks are not complete, and have missing code you need to fill in. If you get stuck there are complete notebooks in the answers folder, that you can refer to.

Finally if you want to present these notebooks in a workshop, we use RISE to turn the notebooks into a slideshow. You can install this with pip install montepy[demo-present].