Parallel Plots using JSON files

[1]:
import sys
sys.path.append('../')

import numpy as np
from opal.parser.OptimizerParser import OptimizerParser

import plotly
import plotly.plotly as py
import plotly.graph_objs as go

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 8
      5 from opal.parser.OptimizerParser import OptimizerParser
      7 import plotly
----> 8 import plotly.plotly as py
      9 import plotly.graph_objs as go

File /usr/local/lib/python3.8/dist-packages/plotly/plotly/__init__.py:4
      1 from __future__ import absolute_import
      2 from _plotly_future_ import _chart_studio_error
----> 4 _chart_studio_error("plotly")

File /usr/local/lib/python3.8/dist-packages/_plotly_future_/__init__.py:43, in _chart_studio_error(submodule)
     42 def _chart_studio_error(submodule):
---> 43     raise ImportError(
     44         """
     45 The plotly.{submodule} module is deprecated,
     46 please install the chart-studio package and use the
     47 chart_studio.{submodule} module instead. 
     48 """.format(
     49             submodule=submodule
     50         )
     51     )

ImportError:
The plotly.plotly module is deprecated,
please install the chart-studio package and use the
chart_studio.plotly module instead.

[2]:
files = './json-reader/data/'

#Find all .json files in a directory
optjson = OptimizerParser(files)
optjson.readGeneration(1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 4
      1 files = './json-reader/data/'
      3 #Find all .json files in a directory
----> 4 optjson = OptimizerParser(files)
      5 optjson.readGeneration(1)

TypeError: __init__() takes 1 positional argument but 2 were given

Load names of design variables and objectives

[3]:
dvars = optjson.getDesignVariables()
print ( "Design variables: ", dvars)
print ( "number of design variables = ", np.size(dvars))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 dvars = optjson.getDesignVariables()
      2 print ( "Design variables: ", dvars)
      3 print ( "number of design variables = ", np.size(dvars))

NameError: name 'optjson' is not defined
[4]:
objs = optjson.getObjectives()
print ( "Objectives: ", objs)
print ( "number of objectives", np.size(objs))

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 objs = optjson.getObjectives()
      2 print ( "Objectives: ", objs)
      3 print ( "number of objectives", np.size(objs))

NameError: name 'optjson' is not defined

Find number of generations run by optimizer

This should match number of files found by json reader.

[5]:
n = optjson.getNumOfGenerations()
print('Number of generations = ', n)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 n = optjson.getNumOfGenerations()
      2 print('Number of generations = ', n)

NameError: name 'optjson' is not defined

Load all data in first generation

[6]:
optjson.readGeneration(1)
dvarsall = optjson.getAllInput()
objsall  = optjson.getAllOutput()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 optjson.readGeneration(1)
      2 dvarsall = optjson.getAllInput()
      3 objsall  = optjson.getAllOutput()

NameError: name 'optjson' is not defined

Assign labels, data, and plot paralllel coord

I will try to add a function (in visualize script) to do this without explicitly making Parcoord obj.

You can adjust data range by changing min and max: range = [1.5,10]
You can adjust tick marks as well: tickvals = [1.5,3,4.5],
[7]:
pardata = [go.Parcoords(
                line = dict(color = 'blue'),
                dimensions = list([
                    dict(#range = [1.5,10],
                         label = dvars[0], values = dvarsall[:,0]),

                    dict(#range = [-30,0],
                         label = dvars[1], values = dvarsall[:,1]),

                    dict(#range = [200,500],
                         #tickvals = [1.5,3,4.5],
                         label = dvars[2], values = dvarsall[:,2]),

                    dict(#range = [170,260],
                         #tickvals = [1,2,4,5],
                         label = objs[0], values = objsall[:,0]),
                         #ticktext = ['text 1', 'text 2', 'text 3', 'text 4']),

                    dict(#range = [-8.0, 8.0],
                         label = objs[1], values = objsall[:,1]),

                    dict(#range = [-8.0,8.0],
                         label = objs[2], values = objsall[:,2])

                ]))]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 pardata = [go.Parcoords(
      2                 line = dict(color = 'blue'),
      3                 dimensions = list([
      4                     dict(#range = [1.5,10],
      5                          label = dvars[0], values = dvarsall[:,0]),
      6
      7                     dict(#range = [-30,0],
      8                          label = dvars[1], values = dvarsall[:,1]),
      9
     10                     dict(#range = [200,500],
     11                          #tickvals = [1.5,3,4.5],
     12                          label = dvars[2], values = dvarsall[:,2]),
     13
     14                     dict(#range = [170,260],
     15                          #tickvals = [1,2,4,5],
     16                          label = objs[0], values = objsall[:,0]),
     17                          #ticktext = ['text 1', 'text 2', 'text 3', 'text 4']),
     18
     19                     dict(#range = [-8.0, 8.0],
     20                          label = objs[1], values = objsall[:,1]),
     21
     22                     dict(#range = [-8.0,8.0],
     23                          label = objs[2], values = objsall[:,2])
     24
     25                 ]))]

NameError: name 'go' is not defined

Plot parallel coord plot and open in new tab:

[8]:
plotly.offline.plot(pardata, filename = 'testParallel.html')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 plotly.offline.plot(pardata, filename = 'testParallel.html')

NameError: name 'pardata' is not defined
[ ]: