Skip to content

Commit

Permalink
Optview dash (#200)
Browse files Browse the repository at this point in the history
* Updated requirements to support dash

* Created new dash optview version

* Revert "Updated requirements to support dash"

This reverts commit 64e5a3d.

* Revert "Created new dash optview version"

This reverts commit e6466e3.

* Added env to gitignore

* Added OptView folder

* Documented  addMaxMinTraces

* Fixed linting errors

* Enabled space for longer var names

* undo commented out NSGA2

* deleted old dash file

* moved OptViewDash files

* added optview dash to setup.py

* fixed some typos

* moved OptViewIcon to assets directory

* updated CRLF to LF endings

* added tests for optview and optview_dash

* updated travis

* removed optview test since cannot test in headless

* forgot to add reason for skipTest

* added docs

* Revert "updated CRLF to LF endings"

This reverts commit 19f0346.

* Delete .flake8

* Revert "Delete .flake8"

This reverts commit 89813cc.

Co-authored-by: Marco Mangano <36549388+marcomangano@users.noreply.github.com>
Co-authored-by: Neil Wu <neilwu@umich.edu>
Co-authored-by: Neil Wu <602725+nwu63@users.noreply.github.com>
  • Loading branch information
4 people committed Feb 9, 2021
1 parent 3d51f4c commit 939640f
Show file tree
Hide file tree
Showing 13 changed files with 1,338 additions and 605 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ build/*
*.hst
*.gz
*.c
*.cpp
*.cpp
env
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install:
docker exec -it app /bin/bash -c "cp -r \$HOME/NLPQLP/* $NLPQLP_DIR/ && cp -r \$HOME/SNOPT/* $SNOPT_DIR/";
fi
# Build and install
- docker exec -it app /bin/bash -c ". $BASHRC && cd $DOCKER_WORKING_DIR && pip install -e ."
- docker exec -it app /bin/bash -c ". $BASHRC && cd $DOCKER_WORKING_DIR && pip install -e .[optview]"

script:
- |
Expand Down
11 changes: 11 additions & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Simply comment out the corresponding lines in ``pyoptsparse/pyoptsparse/setup.py
The corresponding lines in ``pyoptsparse/__init__.py`` must be commented out as well.

Python dependencies are automatically handled by ``pip``, so they do not need to be installed separately.
The only exception is ``numpy``, which is required as part of the build process and therefore must be present before installing.

.. note::
* In Linux, the python header files (python-dev) are also required.
Expand Down Expand Up @@ -46,6 +47,16 @@ It is also possible to install pyOptSparse by calling ``python setup.py install`

For those who intend to use pyOptSparse with IPOPT, OpenMDAO developers provide a `bash script <https://github.com/OpenMDAO/build_pyoptsparse>`_ that simplifies the installation of the optimizer with different linear solvers.

.. _install_optview:

Installing OptView
------------------
OptView and OptView-Dash have separate dependencies that must be installed.
To install pyOptSparse including those dependencies, run::

pip install .[optview]


Testing
-------
pyOptSparse provides a set of unit and regression tests to verify the installation.
Expand Down
62 changes: 32 additions & 30 deletions doc/postprocessing.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Post-processing
===============
There are two post-processing utilities that are provided with pyOptSparse.
There are three post-processing utilities that are provided with pyOptSparse.

- OptView is a GUI designed to quickly and interactively visualize optimization histories
- OptView-Dash is a `Dash <https://plotly.com/dash/>`_ implementation of OptView
- ``History`` is a Python class that can be used to read in the history file, and provide API for programmatically extracting data.

OptView
Expand All @@ -23,11 +24,8 @@ Requirements
\-axisartist (OptView)
numpy (OptView)

If you are successfully running pyOptSparse, these packages are most likely
already installed.

Although not necessary for most usage, the ``dill`` package is needed
if you wish to save an editable version of the graph produced in ``OptView``.
For installation instructions, see :ref:`install_optview`.
Although not necessary for most usage, the ``dill`` package is needed if you wish to save an editable version of the graph produced in ``OptView``.
``dill`` can be installed via ``pip`` in a terminal using::

pip install dill
Expand All @@ -40,18 +38,15 @@ Usage

optview histFile

Here, ``histFile`` is the name of the history file to be examined
(default is ``opt_hist.hst``).
Here, ``histFile`` is the name of the history file to be examined (default is ``opt_hist.hst``).


Additionally, you can open multiple history files in the same ``OptView`` instance
by calling them via the command line::
Additionally, you can open multiple history files in the same ``OptView`` instance by calling them via the command line::

optview histFile1 histFile2 histFile3

Each file's contents will be loaded into ``OptView`` with a flag appended to the end
of each variable or function name corresponding to the history file. The first one
listed will have '_A' added to the name, the second will have '_B' added, etc.
Each file's contents will be loaded into ``OptView`` with a flag appended to the end of each variable or function name corresponding to the history file.
The first one listed will have '_A' added to the name, the second will have '_B' added, etc.
There is currently no limit to the number of history files than can be loaded.

Optionally, if you want to save the generated figures, there is an optional argument::
Expand All @@ -72,23 +67,18 @@ Features
* saving the figure to an image or pickling it for later formatting
* refreshing the optimization history on the fly

Although some of these are self-explanatory, the layout and usage of ``OptView``
will be explained below.
Although some of these are self-explanatory, the layout and usage of ``OptView`` will be explained below.

GUI Layout
~~~~~~~~~~
The window is divided into two sections.
The top is the canvas where the figure and graphs will be produced,
while the bottom grayed section contains user-selectable options.
The top is the canvas where the figure and graphs will be produced, while the bottom grayed section contains user-selectable options.
Here, we will focus on the user options.

The selectable variables are contained on the left hand
side of the options panel in scrollable listboxes.
You can select multiple items from the listboxes using the normal selection
operators such as control and shift.
If a selected variable is an array, a third listbox should appear on the
right hand side of the options panel, allowing you to select specific
sub-variables within the single array variable.
The selectable variables are contained on the left hand side of the options panel in scrollable listboxes.
You can select multiple items from the listboxes using the normal selection operators such as control and shift.
If a selected variable is an array, a third listbox should appear on the right hand side of the options panel,
allowing you to select specific sub-variables within the single array variable.

There are three main options when selecting how to produce the graph(s):

Expand All @@ -97,8 +87,7 @@ There are three main options when selecting how to produce the graph(s):
* Stacked plots - each variable gets its own individual plot and the set is stacked vertically

Most checkbox options should play well with any of these three main options,
though there are known issues with using the 'multiple axes'
option and delta values or for displaying arrays.
though there are known issues with using the 'multiple axes' option and delta values or for displaying arrays.

There are seven checkbox options:

Expand All @@ -124,10 +113,23 @@ Lastly, there are some miscellaneous features:
* Hoverable tooltips when the cursor is on a plot line
* A variable called `actual_iteration_number` that gives a translation between history file iteration number and run file iteration number. This is especially useful for debugging specific steps of an optimization or comparing values across different histories.

More features are being developed on an as-needed basis.
Feel free to edit the code as you see fit and submit a pull request if you
would like to see a feature added.
Alternatively, you can submit an issue ticket to discuss possible features.

OptView-Dash
------------
This is a Dash_ implementation of OptView, and has many of the same features offered by OptView.
For installation instructions, see :ref:`install_optview`.
To run, use this command::

optview_dash <filename>

Similar to OptView, you can invoke it with multiple history files.
To view the dash app, you will have to manually open the server in your browser that is listed in the terminal after running the above command.

Auto-refresh: This follows the same functionality as OptView, allowing you to see the changes of an optimization as it is running.

- If you toggle this checklist button, it will cause the program to default update every 10 seconds, however you may modify this refresh rate using the input box underneath
- Make sure to toggle off this button when you are done or the optimization is complete so it does not add lag.
- This feature also works with multiple history files/optimizations running!

Directly Accessing the History Object
-------------------------------------
Expand Down
16 changes: 3 additions & 13 deletions pyoptsparse/postprocessing/OptView.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
import os
import argparse
import shelve

import sys

major_python_version = sys.version_info[0]

if major_python_version == 2:
import tkFont
import Tkinter as Tk
else:
import tkinter as Tk
from tkinter import font as tkFont

import tkinter as Tk
from tkinter import font as tkFont
import re
import warnings

Expand All @@ -47,7 +38,6 @@
pass
import numpy as np
from sqlitedict import SqliteDict
import traceback
from .OptView_baseclass import OVBaseClass


Expand All @@ -69,7 +59,7 @@ def __init__(self, histList, outputDir, figsize):
try:
icon_dir = os.path.dirname(os.path.abspath(__file__))
icon_name = "OptViewIcon.gif"
icon_dir_full = os.path.join(icon_dir, icon_name)
icon_dir_full = os.path.join(icon_dir, "assets", icon_name)
img = Tk.PhotoImage(file=icon_dir_full)
self.root.tk.call("wm", "iconphoto", self.root._w, img)
except: # bare except because error is not in standard Python
Expand Down

0 comments on commit 939640f

Please sign in to comment.