Spyder plugin for modelx enriches user interface to modelx in Spyder. The plugin adds custom IPython consoles and GUI widgets for using modelx in Spyder.
The plugin is under active development, and currently comes with a primary version of components, including:
MxConsole appears as tabs in Spyder’s default IPython console, and runs custom IPython shells. Users should use these shells instead of Spyder’s default shells in order for the other plugin widgets to interface with the user’s Python sessions. The plugin widgets do not interface with Python running in default IPython consoles.
MxExplorer is the main plugin widgets, and it shows the object tree of the current modelx model in the active MxConsole. It can also lists formulas of cells in a selected space next to the tree.
MxDataView shows data in modelx objects in a spreadsheet-like tabular format.
MxAnalyzer is for tracking dependency of calculations. The user enter a Cell node, a combination of a Cell and arguments, and MxAnalyzer currently shows a tree of Cell nodes directly or indirectly used in calculating the value of the specified node.
The plugin widgets are “dockable” as Spyder’s default widgets, meaning you can detach those widgets from the Spyder’s main window to have their own separate windows, and “dock” them back in the main window at different positions to rearrange the widgets positions in the main window as you like.
Disable User Module Reloader
When you use modelx with Spyder, sometimes you may want to re-run the same file in the editor window multiple times in the same IPython session. You don’t want to reload modelx because reloading modelx module creates multiple instances of modelx systems within the same Python process, causing models created before and after a reload to reside in different modelx systems. To avoid that, you need to change User Module Rloader (UMR) setting.
From the Spyder menu, select Tools->Preferences to bring up Preferences window. Choose Python interpreter in the left pane, and you’ll find an area titled User Module Reloader (UMR) on the bottom right side of the Preferences window. Leave Enable UMR option checked, click Set UMR excluded(not reloaded) modules and then UMR dialog box pops up as the figure blow. Enter “modelx” in the dialog box. This prevents Spyder from reloading the modelx module every time you re-run the same script from Run menu, while allowing other modules to be reloaded.
Note that you need to restart Spyder to bring the change into effect.
Installing Spyder plugin for modelx¶
The plugin is available as a separate Python package named
The supported version of Spyder is 3.2.5 or newer. The plugin does not work with Spyder versions older than 3.2.5.
spyder-modelx package is available on PyPI, and
can be installed using
If you’re using Anaconda distribution,
run the following command in Anaconda command prompt to install the plugin
$ pip install --no-deps spyder-modelx
If Spyder is running while the plugin gets installed, close Spyder once and restart it to bring the plugin into effect.
MxExplorer and MxConsole¶
To enable the modelx plugin, start Spyder, and go to View->Panes menu, and check MxExplorer.
Then the Modelx explorer tab appears in the upper right pane.
Right-click ont the IPython console tab in the lower right pane, then click Open a MxConsole menu.
A modelx console named MxConsole starts. The modelx console works exactly the same as a regular IPython console, except that the modelx explorer shows the components of the current model in the IPython session of this console. To test the behaviour, create a new model and space in the modelx console like this:
>>> import modelx as mx >>> model, space = mx.new_model(), mx.new_space() >>> cells = space.new_cells()
The modelx explorer shows the component tree of the created space.
MxExplorer can also list the formulas of all cells in a selected space. To see the formulas in a space, select the space in the tree, right-click to bring up the context menu, and the click Show Formulas. The list of the formulas appears to the right of the model tree in MxExplorer.
MxDataView widget lets you see a DataFrame object in a spreadsheet-like tabular format.
If MxDataView widget is not shown, Go to View->Panes menu as you did with MxExploer, and check MxDataView.
To specify a DataFrame object to display, enter a Python expression that returns the DataFrame object, in the text box labeled Expression. The Python expression is evaluated in the global namespace of the Python session in the active MxConsole. The expression is re-evaluated every time MxConsole execute a Python command.
MxAnalyzer is used for checking calculation dependency.
If MxDataView widget is not shown, Go to View->Panes menu as you did with MxExploer, and check MxAnalyzer.
Enter an expression that returns a Cell object in the top-left box, and arguments to the Cell in the to-right box. The Python expression is evaluated in the global namespace of the Python session in the active MxConsole. Then MxAnalyzer shows a tree of Cell nodes directly or indirectly used in calculating the value of the specified node.