Skip to content

Commit

Permalink
ModelExplorer: download buttons #232
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Mar 20, 2024
1 parent 0d98044 commit 73b9167
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGES.mp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Summary of recent updates to the AMPL MP Library
================================================


## 20240319
## 20240320
- *SOS constraints*.
- Fixed handling of SOS2 constraints created by AMPL
as reformulations of PL expressions (`option
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ endif() ## NOT SKIP_BUILD_MP
include_directories(include)

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(MP_DATE 20240319)
set(MP_DATE 20240320)

set(MP_SYSINFO "${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}")

Expand Down
21 changes: 19 additions & 2 deletions support/modelexplore/modelexplore.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,43 @@ def MatchSelection(m, srch, fwd, bwd):
return MatchSubmodel(m, srch, fwd, bwd)

# Write dictionary of entries
@st.cache_data
def WriteDict(d):
whole = ""
for k, v in d.items():
if len(v):
whole = whole + '\n\n## ' + k + ' (' + str(v.count('\n')) + ')\n'
whole = whole + v
with st.expander("""### """ + k + ' (' + \
str(v.count('\n')) + ')'):
with st.container(height=200):
st.code(v, language='ampl')
return whole


filename_upl = ""
modelNL = ""
modelFlat = ""

# Or even better, call Streamlit functions inside a "with" block:
if uploader is not None:
model = ReadModel(uploader)
filename_upl = uploader.name
subm1, subm2 = MatchSelection(model, srch, fwd, bwd)
bytes1_data = subm1.GetData()
bytes2_data = subm2.GetData()
with left_column:
st.write("""## NL model""")
WriteDict(bytes1_data)
modelNL = WriteDict(bytes1_data)
with right_column:
st.write("""## Flat model""")
WriteDict(bytes2_data)
modelFlat = WriteDict(bytes2_data)
else:
with left_column:
st.write("No file selected.")


st.sidebar.download_button("Download NL Model", modelNL, filename_upl + '_NL.mod',
disabled = ("" == modelNL))
st.sidebar.download_button("Download Solver Model", modelFlat, filename_upl + '_solver.mod',
disabled = ("" == modelFlat))

0 comments on commit 73b9167

Please sign in to comment.