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

Avoid Unnecessary Julia Operations + Optional RMS Installation #2631

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ jobs:
activate-environment: rmg_env
use-mamba: true

# installs the extra RMS conda dependencies
- name: Add RMS dependencies
run: |
mamba install -c conda-forge julia=1.9.1 pyjulia>=0.6
mamba install -c rmg pyrms diffeqpy

# list the environment for debugging purposes
- name: mamba info
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
activate-environment: rmg_env
use-mamba: true

# installs the extra RMS conda dependencies
- name: Add RMS dependencies
run: |
mamba install -c conda-forge julia=1.9.1 pyjulia>=0.6
mamba install -c rmg pyrms diffeqpy

- name: Install sphinx
run: mamba install -y sphinx

Expand Down
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh &
rm Miniconda3-latest-Linux-x86_64.sh
ENV PATH="$PATH:/miniconda/bin"

# Set solver backend to mamba for speed
RUN conda install -n base conda-libmamba-solver && \
conda config --set solver libmamba

# Set Bash as the default shell for following commands
SHELL ["/bin/bash", "-c"]

Expand All @@ -44,8 +40,7 @@ RUN git clone --single-branch --branch main --depth 1 https://github.com/Reactio

WORKDIR /rmg/RMG-Py
# build the conda environment
RUN conda env create --file environment.yml && \
conda clean --all --yes
hwpang marked this conversation as resolved.
Show resolved Hide resolved
RUN conda env create --file environment.yml

# This runs all subsequent commands inside the rmg_env conda environment
#
Expand All @@ -54,6 +49,10 @@ RUN conda env create --file environment.yml && \
# in a Dockerfile build script)
SHELL ["conda", "run", "--no-capture-output", "-n", "rmg_env", "/bin/bash", "-c"]

RUN conda install -c conda-forge julia=1.9.1 pyjulia>=0.6 && \
conda install -c rmg pyrms diffeqpy && \
conda clean --all --yes

# Set environment variables as directed in the RMG installation instructions
ENV RUNNER_CWD=/rmg
ENV PYTHONPATH="$RUNNER_CWD/RMG-Py:$PYTHONPATH"
Expand Down
24 changes: 12 additions & 12 deletions documentation/source/users/rmg/installation/anacondaDeveloper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Installation by Source Using Anaconda Environment for Unix-based Systems: Linux

Note that you should reinitialize or restart your terminal in order for the changes to take effect, as the installer will tell you.

#. If your `conda` version is older than 23.10.0, switch the solver backend to `libmamba` ::

conda install -n base conda-libmamba-solver
conda config --set solver libmamba

#. There are a few system-level dependencies which are required and should not be installed via Conda. These include
`Git <https://git-scm.com/>`_ for version control, `GNU Make <https://www.gnu.org/software/make/>`_, and the C and C++ compilers from the `GNU Compiler Collection (GCC) <https://gcc.gnu.org/>`_ for compiling RMG.

Expand Down Expand Up @@ -71,11 +76,6 @@ Installation by Source Using Anaconda Environment for Unix-based Systems: Linux

For information on using ``ssh`` with GitHub see the `Connecting to GitHub with SSH <https://docs.github.com/en/authentication/connecting-to-github-with-ssh>`_

#. Switch the conda solver backend to speed up creation of the RMG environment ::

conda install -n base conda-libmamba-solver
conda config --set solver libmamba

#. Navigate to the RMG-Py directory ::

cd RMG-Py
Expand Down Expand Up @@ -110,16 +110,11 @@ Installation by Source Using Anaconda Environment for Unix-based Systems: Linux

conda activate rmg_env

#. Switch the conda solver to libmamba again, to accelerate any changes you might make to this conda environment in the future::

conda config --set solver libmamba

#. Compile RMG-Py after activating the conda environment ::

make

#. Modify environment variables. Add RMG-Py to the PYTHONPATH to ensure that you can access RMG modules from any folder.
*This is important before the next step in which julia dependencies are installed.*
Also, add your RMG-Py folder to PATH to launch ``rmg.py`` from any folder.

In general, these commands should be placed in the appropriate shell initialization file.
Expand All @@ -134,16 +129,21 @@ Installation by Source Using Anaconda Environment for Unix-based Systems: Linux

Be sure to either close and reopen your terminal to refresh your environment variables (``source ~/.bashrc`` or ``source ~/.zshrc``).

#. Install and Link Julia dependencies: ::
#. **Optional (Recommended)**: Install and Link Julia dependencies. Ensure that you have modified your environment variables as described above, and then run the following: ::

julia -e 'using Pkg; Pkg.add("PyCall");Pkg.build("PyCall");Pkg.add(PackageSpec(name="ReactionMechanismSimulator",rev="main")); using ReactionMechanismSimulator;'

python -c "import julia; julia.install(); import diffeqpy; diffeqpy.install()"

Installing these dependencies will allow using ``method='ode'`` when solving the Master Equation with Arkane and using ``ReactionMechanismSimulator.jl``-based reactors in RMG.

#. Finally, you can run RMG from any location by typing the following (given that you have prepared the input file as ``input.py`` in the current folder). ::

python-jl replace/with/path/to/rmg.py input.py
python-jl rmg.py input.py

or, if the Julia dependencies are not installed: ::

python rmg.py input.py

You may now use RMG-Py, Arkane, as well as any of the :ref:`Standalone Modules <modules>` included in the RMG-Py package.

Expand Down
28 changes: 14 additions & 14 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# made dependency list more explicit (@JacksonBurns).
# - October 16, 2023 Switched RDKit and descripatastorus to conda-forge,
# moved diffeqpy to pip and (temporarily) removed chemprop
# - Mar 11, 2024 Removed Julia dependencies, now considered optional
#
name: rmg_env
channels:
Expand Down Expand Up @@ -48,10 +49,6 @@ dependencies:
- conda-forge::openbabel >= 3
- conda-forge::rdkit >=2022.09.1

# general-purpose external software tools
- conda-forge::julia=1.9.1
- conda-forge::pyjulia >=0.6

# Python tools
- python >=3.7
- coverage
Expand Down Expand Up @@ -88,21 +85,24 @@ dependencies:
# packages we maintain
- rmg::pydas >=1.0.3
- rmg::pydqed >=1.0.3
- rmg::pyrms
- rmg::symmetry

# packages we would like to stop maintaining (and why)
- rmg::diffeqpy
JacksonBurns marked this conversation as resolved.
Show resolved Hide resolved
# we should use the official verison https://github.com/SciML/diffeqpy),
# rather than ours (which is only made so that we can get it from conda)
# It is only on pip, so we will need to do something like:
# https://stackoverflow.com/a/35245610
# Note that _some other_ dep. in this list requires diffeqpy in its recipe
# which will cause it to be downloaded from the rmg conda channel

# conda mutex metapackage
- nomkl

# optional dependencies for using ReactionMechanismSimulator
# remove the leading '#' to install the required dependencies
# - conda-forge::julia=1.9.1
# - conda-forge::pyjulia >=0.6
# - rmg::pyrms
# - rmg::diffeqpy

# Note about diffeqpy:
# we should use the official verison https://github.com/SciML/diffeqpy),
# rather than ours (which is only made so that we can get it from conda)
# It is only on pip, so we will need to do something like:
# https://stackoverflow.com/a/35245610

# additional packages that are required, but not specified here (and why)
# pydqed, pydas, mopac, and likely others require a fortran compiler (specifically gfortran)
# in the environment. Normally we would add this to the environment file with
Expand Down
19 changes: 17 additions & 2 deletions rmgpy/pdep/sls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
and implementing the SLS master equation reduction method
"""
import sys
import logging

from diffeqpy import de
from julia import Main
import scipy.sparse as sparse
import numpy as np
import scipy.linalg
Expand All @@ -46,6 +45,17 @@
from rmgpy.pdep.me import generate_full_me_matrix, states_to_configurations
from rmgpy.statmech.translation import IdealGasTranslation

NO_JULIA = False
try:
from diffeqpy import de
from julia import Main
except Exception as e:
logging.info(
f"Unable to import Julia dependencies, original error: {str(e)}"
". Master equation method 'ode' will not be available on this execution."
)
NO_JULIA = True


def get_initial_condition(network, x0, indices):
"""
Expand Down Expand Up @@ -150,6 +160,11 @@ def get_rate_coefficients_SLS(network, T, P, method="mexp", neglect_high_energy_
tau = np.abs(1.0 / fastest_reaction)

if method == "ode":
if NO_JULIA:
raise RuntimeError(
"Required Julia dependencies for method 'ode' are not installed.\n"
"Please follow the steps to install Julia dependencies at https://reactionmechanismgenerator.github.io/RMG-Py/users/rmg/installation/anacondaDeveloper.html."
)
f = Main.eval(
"""
function f(u,M,t)
Expand Down
8 changes: 7 additions & 1 deletion rmgpy/rmg/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
from rmgpy.solver.surface import SurfaceReactor
from rmgpy.util import as_list
from rmgpy.data.surface import MetalDatabase
from rmgpy.rmg.reactors import Reactor, ConstantVIdealGasReactor, ConstantTLiquidSurfaceReactor, ConstantTVLiquidReactor, ConstantTPIdealGasReactor
from rmgpy.data.vaporLiquidMassTransfer import liquidVolumetricMassTransferCoefficientPowerLaw
from rmgpy.molecule.fragment import Fragment
from rmgpy.rmg.reactionmechanismsimulator_reactors import Reactor, ConstantVIdealGasReactor, ConstantTLiquidSurfaceReactor, ConstantTVLiquidReactor, ConstantTPIdealGasReactor, NO_JULIA


################################################################################

Expand Down Expand Up @@ -1558,6 +1559,11 @@ def read_input_file(path, rmg0):
exec(f.read(), global_context, local_context)
except (NameError, TypeError, SyntaxError) as e:
logging.error('The input file "{0}" was invalid:'.format(full_path))
if NO_JULIA:
logging.error(
"During runtime, import of Julia dependencies failed. To use phase systems and RMS reactors, install RMG-Py with RMS."
" (https://reactionmechanismgenerator.github.io/RMG-Py/users/rmg/installation/anacondaDeveloper.html)"
)
logging.exception(e)
raise
finally:
Expand Down
Loading
Loading