Skip to content

Commit

Permalink
Merge pull request #1070 from DKilkenny/mm_view
Browse files Browse the repository at this point in the history
Added ability user to set resolution of view_mm in command line
  • Loading branch information
swryan committed Oct 4, 2019
2 parents f07c4bf + 79525b6 commit cce8885
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 50 deletions.
9 changes: 6 additions & 3 deletions openmdao/utils/om.py
Expand Up @@ -255,6 +255,9 @@ def _meta_model_parser(parser):
parser.add_argument('file', nargs=1, help='Python file containing the model.')
parser.add_argument('-m', '--metamodel_pathname', action='store', dest='pathname',
help='pathname of the metamodel component.')
parser.add_argument('-r', '--resolution', default=50, type=int,
action='store', dest='resolution',
help='Number of points to create contour grid')
parser.add_argument('-p', '--port_number', default=5007, action='store', dest='port_number',
help='Port number to open viewer')

Expand Down Expand Up @@ -285,11 +288,12 @@ def _view_metamodel(prob):

pathname = options.pathname
port_number = options.port_number
resolution = options.resolution

if pathname:
comp = prob.model._get_subsystem(pathname)
if comp and isinstance(comp, mm_types):
view_metamodel(comp, port_number)
view_metamodel(comp, resolution, port_number)
exit()
else:
comp = None
Expand All @@ -305,8 +309,7 @@ def _view_metamodel(prob):

elif mm_count == 1 and not pathname:
comp = metamodels[mm_names[0]]
view_metamodel(comp, port_number)
exit()
view_metamodel(comp, resolution, port_number)

else:
try_str = "Try one of the following: {}.".format(mm_names)
Expand Down
Expand Up @@ -886,22 +886,24 @@ def _output_value_update(self, attr, old, new):
self._update_all_plots()


def view_metamodel(meta_model_comp, port_number):
def view_metamodel(meta_model_comp, resolution, port_number):
"""
Visualize a metamodel.
Parameters
----------
meta_model_comp : MetaModelStructuredComp or MetaModelUnStructuredComp
The metamodel component.
resolution : int
Number of points to control contour plot resolution.
port_number : int
Bokeh plot port number.
"""
from bokeh.application.application import Application
from bokeh.application.handlers import FunctionHandler

def make_doc(doc):
MetaModelVisualization(meta_model_comp, doc=doc)
MetaModelVisualization(meta_model_comp, resolution, doc=doc)

# print('Opening Bokeh application on http://localhost:5006/')
server = Server({'/': Application(FunctionHandler(make_doc))}, port=int(port_number))
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions openmdao/visualization/meta_model_viewer/tests/test_structured.py
Expand Up @@ -188,23 +188,6 @@ def test_working_multipoint_scipy_cubic(self):

MetaModelVisualization(interp)

def test_unspecified_metamodel(self):
script = os.path.join(os.path.dirname(__file__), 'example.py')
cmd = 'openmdao view_mm {}'.format(script)
output = subprocess.check_output(cmd.split()).decode('utf-8', 'ignore')
expected_output = "Metamodel not specified. Try one of the following: ['interp1', 'interp2']."
self.assertTrue(expected_output in output)

def test_invalid_metamodel(self):
script = os.path.abspath(example.__file__).replace('.pyc', '.py') # PY2
cmd = 'openmdao view_mm {} -m {}'.format(script, 'interp')
output = subprocess.check_output(cmd.split()).decode('utf-8', 'ignore')
expected_output = '\n'.join([
"Metamodel 'interp' not found.",
" Try one of the following: ['mm']."
])
self.assertTrue(expected_output in output.replace('\r', ''))

def test_aligned_training_points(self):

known_points_right = np.array([[ 10. , 0. , 0. , 10.96088904],
Expand Down
@@ -0,0 +1,35 @@
""" Unit tests for structured metamodels in view_mm. """
import unittest
import subprocess
import os

try:
import bokeh
except ImportError:
bokeh = None
import openmdao.test_suite.test_examples.meta_model_examples.structured_meta_model_example as example

@unittest.skipUnless(bokeh, "Bokeh is required")
class ViewMMCommandLineTest(unittest.TestCase):

def test_unspecified_metamodel(self):
script = os.path.join(os.path.dirname(__file__), 'example.py')
cmd = 'openmdao view_mm {}'.format(script)
output = subprocess.check_output(cmd.split()).decode('utf-8', 'ignore')
expected_output = ("Metamodel not specified. "
"Try one of the following: ['interp1', 'interp2'].")
self.assertTrue(
expected_output in output,
msg='Metamodel was specified when it should not have been. Check example.')

def test_invalid_metamodel(self):
script = os.path.abspath(example.__file__).replace('.pyc', '.py') # PY2
cmd = 'openmdao view_mm {} -m {}'.format(script, 'interp')
output = subprocess.check_output(cmd.split()).decode('utf-8', 'ignore')
expected_output = '\n'.join([
"Metamodel 'interp' not found.",
" Try one of the following: ['mm']."
])
self.assertTrue(
expected_output in output.replace('\r', ''),
msg='Metamodel was found when it should not have. Check example.')

0 comments on commit cce8885

Please sign in to comment.