例如在使用om.slicer时SqliteRecorder崩溃约束 问题摘要问题类型说明示例环境

问题描述

问题摘要

例如,在使用sqliteRecorder

om.slicer崩溃约束。

问题类型

说明

跟踪:

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

示例

示例取自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()

环境

操作系统:OS X 10.15.5,CentOS

Python环境:Python 3.6.1、3.8.5

软件包:OpenMDAO master分支

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)