'Getting an error when trying to record in OpenMDAO

I am trying to set up, run and record a model. The first section of the code works flawlessly, hence I provided the generalized lines of code for the subsystems, connections, design variables, constraints and objectives I use.

import openmdao.api as om

prob = om.Problem()

prob.model.add_subsystem(...)

prob.model.connect(...)

prob.model.add_design_var(...)
prob.model.add_objective(...)
prob.model.add_constraint(...)

prob.driver = om.ScipyOptimizeDriver(optimizer='SLSQP', tol=1e-9, disp=False)

However, if I try to connect the recorder such as:

recorder = om.SqliteRecorder('cases.sql')
prob.add_recorder(recorder)

prob.setup()
prob.set_solver_print(0)
prob.run_driver()
prob.record("after_run_driver")

cr = om.CaseReader("cases.sql")
driver_cases = cr.list_cases('problem', out_stream=None)
case = cr.get_case('after_run_driver')

const = case['con1']
print(const)

const_K = case.get_val("con1", units='K')
print(const_K)

I get an error:

  File "C:\Users\philipp\Anaconda3\envs\Repo Philipp\lib\site-packages\openmdao\recorders\case_reader.py", line 26, in CaseReader
    return SqliteCaseReader(filename, pre_load, metadata_filename)
  File "C:\Users\philipp\Anaconda3\envs\Repo Philipp\lib\site-packages\openmdao\recorders\sqlite_reader.py", line 84, in __init__
    check_valid_sqlite3_db(filename)
  File "C:\Users\philipp\Anaconda3\envs\Repo Philipp\lib\site-packages\openmdao\utils\record_util.py", line 121, in check_valid_sqlite3_db
    raise IOError('File does not exist({0})'.format(filename))
OSError: File does not exist(cases.sql)

Can someone please explain what I am missing? I thought that the cases.sql file get created and written to during the execution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source