Otter Configuration Files

Otter Configuration Files#

In many use cases, the use of the otter.Notebook class by students requires some configurations to be set. These configurations are stored in a simple JSON-formatted file ending in the .otter extension. When otter.Notebook is instantiated, it globs all .otter files in the working directory and, if any are present, asserts that there is only 1 and loads this as the configuration. If no .otter config is found, it is assumed that there is no configuration file and, therefore, only features that don’t require a config file are available.

The available keys in a .otter file are listed below, along with their default values. The only required key is notebook (i.e. if you use .otter file it must specify a value for notebook).

    "notebook": "",            # the notebook filename
    "save_environment": false, # whether to serialize the environment in the log during checks
    "ignore_modules": [],      # a list of modules whose functions to ignore during serialization
    "variables": {}            # a mapping of variable names -> types to resitrct during serialization

Configuring the Serialization of Environments#

If you are using logs to grade assignemtns from serialized environments, the save_environment key must be set to true. Any module names in the ignore_modules list will have their functions ignored during serialization. If variables is specified, it should be a dictionary mapping variables names to fully-qualified types; variables will only be serialized if they are present as keys in this dictionary and their type matches the specified type. An example of this use would be:

    "notebook": "hw00.ipynb",
    "save_environment": true,
    "variables": {
        "df": "pandas.core.frame.DataFrame",
        "fn": "builtins.function",
        "arr": "numpy.ndarray"

The function otter.utils.get_variable_type when called on an object will return this fully-qualified type string.

In [1]: from otter.utils import get_variable_type

In [2]: import numpy as np

In [3]: import pandas as pd

In [4]: get_variable_type(np.array([]))
Out[4]: 'numpy.ndarray'

In [5]: get_variable_type(pd.DataFrame())
Out[5]: 'pandas.core.frame.DataFrame'

In [6]: fn = lambda x: x

In [7]: get_variable_type(fn)
Out[7]: 'builtins.function'

More information about grading from serialized environments can be found in Logging.