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

[WIP] Adding JPOF Contrib Package #2762

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

[WIP] Adding JPOF Contrib Package #2762

wants to merge 3 commits into from

Conversation

whart222
Copy link
Member

@whart222 whart222 commented Mar 6, 2023

Fixes NONE

Summary/Motivation:

Adds a contrib package, jpof, that contains a new Pyomo writer. This write generates a JSON formatted file that describes the problem representation in the Pyomo model. This file format is like LP and NL files, which represent the Pyomo optimization model in a concise format. The JPOF format has several features:

  • It is in a standard format that is easily parsed.
  • It captures Pyomo expressions with fixed variables and parameterized constant values. These values are explicit, which allows for downstream tools to modify these values as intended by the user.

The Coek software includes a JPOF reader.

Changes proposed in this PR:

  • Initial commit of JPOF writer logic, with tests and examples.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@blnicho blnicho changed the title Adding JPOF Contrib Package [WIP] Adding JPOF Contrib Package Mar 14, 2023
@whart222
Copy link
Member Author

whart222 commented Apr 6, 2023

@jsiirola @blnicho I recall discussing this PR, but we didn't add TODOs in the PR. Do you recall what changes we wanted to make?

@jsiirola
Copy link
Member

jsiirola commented Apr 6, 2023

I believe the biggest thing was getting the tests to pass (I believe the failing test is due to missing __init__.py files)

Comments on the writer implementation:

  • I would advocate adding a write(model, ostream, ..., **options) method (see pyomo/repn/plugins/nl_writer.py), and then have the "legacy" __call__() interface wrap / call write(). That gives us an interface that can avoid the filesystem (you can now write to StringIO or pipe or socket objects). Beyond flexibility, that also allows us to implement tests that completely avoid the need to interact with the filesystem.

Then other comments:

  • It looks like the "small*_testCase.pyare all copied (verbatim?) frompyomo.repn.tests.ampl`. Instead of duplicating them, they should just be imported from that location.
  • I think it would be better if the baselines are actually python data structures and not text files: that way they would be automatically distributed as part of Pyomo (we are trying to fix issues where out test suite fails when pyomo is pip installed - in part because of missing test files / baselines, and in part because some assumptions about directory structure break when the package is installed). I am more ambivalent as to if the baseline data structures should all be in the main test_json_comparison.py driver or in separate modules.
  • There are several files with either missing or out-of-date copyright blocks

@mrmundt mrmundt marked this pull request as draft April 3, 2024 18:25
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.

None yet

2 participants