Summary of Issue
SqliteRecorder
crashes when using om.slicer
in e.g. a constraint.
Issue Type
- [x ] Bug
Description
Traceback:
Traceback (most recent call last):
File "test_slicer.py", line 38, in <module>
p.run_model()
File "/Users/frza/git/OpenMDAO/openmdao/core/problem.py", line 610, in run_model
self.final_setup()
File "/Users/frza/git/OpenMDAO/openmdao/core/problem.py", line 959, in final_setup
self._setup_recording()
File "/Users/frza/git/OpenMDAO/openmdao/core/problem.py", line 728, in _setup_recording
self._rec_mgr.startup(self)
File "/Users/frza/git/OpenMDAO/openmdao/recorders/recording_manager.py", line 91, in startup
recorder.startup(recording_requester)
File "/Users/frza/git/OpenMDAO/openmdao/recorders/sqlite_recorder.py", line 394, in startup
var_settings_json = json.dumps(var_settings)
File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type slice is not JSON serializable
Example
Example taken from openmdao/core/tests/test_group.py
import numpy as np
import openmdao.api as om
from openmdao.api import SqliteRecorder
arr_order_1x1 = np.array([1, 2, 3, 4])
class SlicerComp(om.ExplicitComponent):
def setup(self):
self.add_input('x', np.ones(4))
self.add_output('y', 1.0)
def compute(self, inputs, outputs):
outputs['y'] = np.sum(inputs['x'])**2.0
p = om.Problem()
p.model.add_subsystem('indep', om.IndepVarComp('x', arr_order_1x1))
p.model.add_subsystem('C1', SlicerComp())
p.model.connect('indep.x', 'C1.x')
p.model.add_constraint('indep.x', indices=om.slicer[2:])
p.model.add_objective('C1.y')
p.setup()
p.run_model()
precorder = SqliteRecorder('poptimization.sqlite')
p.recording_options['record_desvars'] = True
p.recording_options['record_constraints'] = True
p.recording_options['record_objectives'] = True
p.add_recorder(precorder)
p.setup()
p.run_model()
p.cleanup()
Environment
Operating System: OS X 10.15.5, CentOS
Python environment: Python 3.6.1, 3.8.5
Packages: OpenMDAO master branch