Skip to content

Instantly share code, notes, and snippets.

@matthewfeickert
Last active September 19, 2025 19:10
Show Gist options
  • Save matthewfeickert/c7d114990d3708f4e485cd53be5f7c1b to your computer and use it in GitHub Desktop.
Save matthewfeickert/c7d114990d3708f4e485cd53be5f7c1b to your computer and use it in GitHub Desktop.
OpenMC install recipe

Use Pixi to get OpenMC installed

  1. Install Pixi
    • Do NOT use Homebrew
  2. Clone this repository
  3. Navigate to the top level of the repository
  4. Run
pixi run install-openmc
  1. Uncomment the lines in pixi.toml
# [pypi-dependencies]
# openmc = { path = "./openmc_src" }

and save the file

  1. Run
pixi install
  1. Run
pixi run start

and you're in a Jupyter Lab session with both the C++ and Python library of openMC installed.

Note

The first time your run Python code in an environment on osx-arm64 it will be slow as it needs to recompile the .pyc files. After this it should be fast again.

Showing you what happened

We installed the C++ library into the Pixi environment and so it is located under .pixi/envs/default/

% find .pixi -type f -iname "libopenmc*"
.pixi/envs/default/lib/libopenmc.dylib
.pixi/envs/default/lib/python3.13/site-packages/openmc/lib/libopenmc.dylib

as we managed the install of the Python bindings with Pixi itself we can query Pixi for that info

% pixi list openmc
Package  Version                           Build  Size  Kind  Source
openmc   0.15.3.dev0+ge23760b02.d20250919               pypi

Use in general

If you want to execute one-off tasks with the Pixi environment you can use pixi run

pixi run <whatever you want here>

which will get executed in the Pixi environment.

If you want the interactive experience of a Conda environment you can get that with pixi shell

% pixi shell

(openmc-dan) %
[workspace]
# NIST is blocking all of https://anaconda domain
# channels = ["conda-forge"]
channels = ["https://prefix.dev/conda-forge"]
name = "openmc-dan"
platforms = ["osx-arm64", "linux-64"]
version = "0.1.0"
[tasks.download]
cmd = """
rm -rf openmc_src && \
git clone --recurse-submodules --branch master https://github.com/openmc-dev/openmc.git openmc_src && \
sed -i 's/cmake_minimum_required(VERSION 3.16 FATAL_ERROR)/cmake_minimum_required(VERSION 3.16...4.1)/g' openmc_src/CMakeLists.txt
"""
[tasks.build]
cmd = """
rm -rf build && \
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCPP17=ON -S openmc_src -B build && \
cmake build -LH && \
cmake --build build --clean-first --parallel "$(nproc --ignore=2)"
"""
[tasks.install]
cmd = "cmake --install build"
[tasks.install-openmc]
depends-on = ["download", "build", "install"]
[tasks.example]
description = "Download the Modeling a Pin-Cell example"
cmd = "curl -sLO https://raw.githubusercontent.com/openmc-dev/openmc-notebooks/main/pincell.ipynb"
[tasks.start]
cmd = "jupyter lab"
depends-on = ["example"]
[dependencies]
git = ">=2.51.0,<3"
sed = ">=4.9,<5"
curl = ">=8.14.1,<9"
cxx-compiler = ">=1.10.0,<2"
cmake = ">=4.1.1,<5"
make = ">=4.4.1,<5"
python = ">=3.13.7,<3.14"
zlib = ">=1.3.1,<2"
hdf5 = ">=1.14.6,<2"
llvm-openmp = ">=21.1.0,<22"
libpng = ">=1.6.50,<2"
# Python library dependencies
scipy = ">=1.16.2,<2"
h5py = ">=3.14.0,<4"
ipython = ">=9.5.0,<10"
matplotlib = ">=3.10.6,<4"
pandas = ">=2.3.2,<3"
lxml = ">=6.0.1,<7"
uncertainties = ">=3.2.3,<4"
endf = ">=0.1.4,<0.2"
notebook = ">=7.4.5,<8"
jupyterlab = ">=4.4.7,<5"
# OpenMC fails to compile using clang v19.x which catches
# vendor/xtensor/include/xtensor/xutils.hpp:896:31: error: ambiguous partial specializations of 'rebind_container<long, xt::svector<unsigned long>>'
# which should be addressed upstream
[target.osx-arm64.dependencies]
cxx-compiler = ">=1.10.0,<2"
clang = ">=18.1.8,<19"
# Requires the download task to run first so uncomment this after the build
# and run 'pixi install' and leave this uncommented unless you need to remove the openmc_src directory
# [pypi-dependencies]
# openmc = { path = "./openmc_src" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment