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

Add EPANET MSX enhancements #426

Open
wants to merge 97 commits into
base: main
Choose a base branch
from
Open

Add EPANET MSX enhancements #426

wants to merge 97 commits into from

Conversation

dbhart
Copy link
Collaborator

@dbhart dbhart commented May 20, 2024

This provides updates to WNTR that integrate EPANET-MSX into the EpanetSimulator.

In addition to the new simulation options, this provides MSX model objects, such as species, terms, etc., that can be added to a water network model in a similar way to how WNTR works currently.

Demonstration is located in examples/demos/

dbhart and others added 30 commits August 17, 2023 14:37
The class will be similar to the WaterNetworkModel in terms of its
structure and options.
Merge main into development branch
Update to add basic citation class
* Update to exception documentation

* Update documentation for EN errors
@kaklise kaklise requested a review from kbonney June 7, 2024 21:03
Copy link
Collaborator

@kbonney kbonney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, PR is well organized and well written. The MSX code and API follows the current WNTR style and is integrated clearly with the existing code base. Documentation and examples are provided to help users learn to use the new MSX features. A test suite is provided, but should be expanded to cover more of the code and common use cases.

I have commented on some minor items throughout. Aside from a typo preventing correct code execution in the example, nothing is of high importance. I recommend that we expand the test suite before merging, which I'd be happy to help with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these options changing?


The EpanetSimulator can use EPANET-MSX 2.0 :cite:p:`shang2023` to run
multi-species water quality simulations.
Additional multi-species simulation options are discussed in :ref:`advanced_simulation`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could link directly to the "Building MSX models" section here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:class:`~wntr.msx.library.ReactionLibrary`.
This includes the following models:

* `Arsenic oxidation/adsorption <https://github.com/dbhart/WNTR/blob/msx/wntr/msx/_library_data/arsenic_chloramine.json>`_ :cite:p:`shang2023`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These links are broken. I assume we will want to update these to point to the corresponding files in the USEPA main branch.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbhart update links

and **parameters**. Constants have a single value in every expression. Parameters have a global value
that is used by default, but which can be modified on a per-pipe or per-tank basis.

Pre-defined hydraulic variable can be found in
Copy link
Collaborator

@kbonney kbonney Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable -> variables

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbhart typo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Suggest adding a direct link to epa msx user manual.
  • Suggest making T/T1 consistent (choose one or the other instead of having both throughout) .
  • In Cell 11, recommend removal of leftover testing comment.
  • Suggest adding axes labels for last figure from cell 9 .
  • Cell 17 naming error, need to lowercase mutlisource-cl.

If `variable_or_name` is not a term in the model
"""
name = str(variable_or_name)
# FIXME: validate deletion
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here

raise SyntaxError("Unknown first word in [QUALITY] section")
if spec not in self.rxn.reaction_system.species:
raise ValueError("Undefined species in [QUALITY] section: {}".format(spec))
# FIXME: check for existence
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

raise ValueError("%s is not a valid member of MsxSolverOptions")
self.__dict__[name] = value

def to_dict(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest providing this for MsxReportOptions as well. Alternatively, could be added to _OptionsBase since it is generic enough and would be useful for all subclasses.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbhart bump up to OptionsBase

@@ -575,8 +589,8 @@ class Registry(MutableMapping):
"""

def __init__(self, wn):
if not isinstance(wn, AbstractModel):
raise ValueError('Registry must be initialized with a model')
# if not isinstance(wn, AbstractModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this removed to allow use with MSX classes? If so, I suggest keeping and extending the allowed instance types to cover MSX.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbhart remove this change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding additional checks for options, pipes, tanks, sources, and initial conditions.

logger = logging.getLogger(__name__)


class MsxLibrary:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth abstracting part of the MsxLibrary interface to allow for extensions to librarys for other purposes (eg demand pattern library). Not sure how this might look but I'd be interested in discussing it further.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbhart TODO remove these settings

raise TypeError('Expected QualityModelBase (or derived), got {}'.format(type(model)))
self._msx = model

def add_msx_model(self, msx_filename=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest changing keyword arg from msx_filename to msx_file_name to follow WNTR convention (eg wn model constructor uses inp_file_name). @dbhart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants