modelx module

The top-level module modelx includes API functions. By convention, modelx is assigned to the name mx in the global namespace:

>> import modelx as mx

Attributes defined in the top level module.

models

Alias for get_models(). Available for Python 3.7 or newer

Type

dict

Getting objects

get_models()

Returns a dict that maps model names to models.

get_object(name[, as_proxy])

Get a modelx object from its full name.

cur_model([model])

Get and/or set the current model.

cur_space([space])

Get and/or set the current space of the current model.

Creating objects

new_model([name])

Create and return a new model.

new_space([name, bases, formula])

Create and return a new space in the current model.

defcells([space, name])

Decorator/function to create/update cells from Python functions.

Saving Models

write_model(model, model_path[, backup, …])

Write model to files.

zip_model(model, model_path[, backup, …])

Archive model to a zip file

read_model(model_path[, name])

Read model from files.

restore_model(path[, name, datapath])

Restore a model and return it.

open_model(path[, name, datapath])

Load a model saved from a file and return it.

Recursion limit

get_recursion()

Returns formula recursion limit

set_recursion([maxdepth])

Set formula recursion limit.

Recalculation mode

get_recalc()

Return True if dependent values are recalculated, False if they are cleared.

set_recalc(recalc)

Set the recalculation option.

IPython configuration

setup_ipython()

Set up IPython shell for modelx.

restore_ipython()

Restore IPython’ default error message.

Tracing the call stack

start_stacktrace([maxlen])

Activate stack tracing.

stop_stacktrace()

Deactivate stack tracing.

get_stacktrace()

Get stack trace.

clear_stacktrace()

Clear stack trace.

Error reporting

get_error()

Returns exception raised during last formula execution

get_traceback()

Returns traceback of exception raised during last formula execution

use_formula_error([use])

Specifies whether to replace error raised during formula execution