Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
objects = {'dae_residual': None, 'initial_residual': None, 'variable_metadata': None, 'delay_arguments': None}
for o in objects.keys():
f = getattr(model, o + '_function')
if compiler_options['codegen']:
objects[o] = _codegen_model(model_folder, f, '{}_{}'.format(model_name, o))
else:
objects[o] = f
# Output metadata
db_file = os.path.join(model_folder, model_name + ".pymoca_cache")
with open(db_file, 'wb') as f:
db = {}
# Store version
db['version'] = __version__
# Include references to the shared libraries (codegen) or pickled functions (cache)
db.update(objects)
db['library_os'] = os.name
db['options'] = compiler_options
# Describe variables per category
for key in ['states', 'der_states', 'alg_states', 'inputs', 'parameters', 'constants']:
db[key] = [e.to_dict() for e in getattr(model, key)]
# Caching using CasADi functions will lead to constants seemingly
# depending on MX variables. Figuring out that they do not is slow,
# especially when doing it on a lazy function call, as would be the