Code documentation

SimInterface

The main API of PyTEP.

class pytep.siminterface.SimInterface(*args, **kwargs)[source]
simulate(duration=None)[source]

Start/Continue the the active simulation until it is paused or terminates.

update()[source]

Fetches current simulation data from the MATLAB workspace and updates process_data, setpoint_data, idv_data and cost_data.

reset()[source]

Resets the simulation environment to it’s initial condition. All unsaved simulation results are lost on reset. On reset, the active simulation is stopped, the MATLAB workspace is cleared fully and then reloaded from an initialization script in MATLAB. update() is called to reset the internal variables of the SimInterface.

static setup()[source]

Setup for the SimInterface. The first initialization of SimInterface should be done using this method. Any following initialization should be done using the regular constructor, which will return the already existing SimInterface object (SimInterface is a singleton class).

Returns

simulation interface – Fully initialized simulation interface for the Tennessee Eastman Simulator.

Return type

backend.siminterface.SimInterface()

save_all(save_dir)[source]

Saves the time, process data, manipulated variables, setpoint data, cost data and idv data as separate pickled dataframes in the specified save directory. Multiple saves in the same save_dir will result in older files being overwritten. :param save_dir: Directory in which the simulation data should be saved. :type save_dir: pathlib.Path, string

extend_simulation(duration=5)[source]

Sets the time in hours until the simulation is automatically paused after a call to simulate().

Parameters

duration (float) – Additional simulation time in hours.

process_data_labels()[source]

Returns the columns of the dataframe that is returned when calling process_data().

Returns

process_data_columns – List of processdata labels

Return type

list

timed_var(var_name)[source]

Returns a dataframe with columns [“time”, “var_name”], containing the time series representing the current simulation output.

Parameters

var_name (string) – process_data_labels() returns a list of feasible variable names.

Returns

timed_var – Dataframe with columns [“time”, “var_name”]

Return type

pandas dataframe

property process_data

Returns a dataframe containing the process data timeseries.

Returns

process_data

Return type

pandas dataframe

current_process_data()[source]

Returns a dataframe containing a single row representing the current simulation state (process data). :returns: process_data :rtype: pandas dataframe

property manipulated_variables

Returns a dataframe containing the manipulated variables timeseries.

Returns

manipulated_variables

Return type

pandas dataframe

current_manipulated_variables()[source]

Returns a dataframe containing a single row representing the current simulation state (manipulated_variables). :returns: manipulated_variables :rtype: pandas dataframe

current_sim_time()[source]

Getter for the current simulation time in hours.

Returns

simulation_time

Return type

float

operating_cost()[source]

Getter for the operating cost time series of the active simulation.

Returns

Operating cost – Pandas dataframe containing a “Cost” column.

Return type

pandas dataframe

current_operating_cost()[source]
get_var_unit(var_label)[source]

Returns the unit of any process variable included in the dictionary returned when calling process_data()

Parameters

var_label (Label of the process variable for which the unit will be returned.) –

Returns

var unit

Return type

string

set_idv(idv_idx, value, delay=0)[source]

Set the fault magnitude and delay in hours before the magnitude is changed from its current value for one idv (IDV1-IDV28).

Parameters
  • idv_idx (int) – Index of the idv (IDV1-IDV28) TODO: Include link to relevant paper here.

  • value (float) – Activation flag for the IDV. Value between 0 and 1.

  • delay – Delay in hours before the idv value is changed from it’s current value.

get_idv(idv_idx)[source]

Getter for the current magnitude value of one of the 28 process faults.

Parameters

idv_idx (int) – Value between 1 and 28

Returns

idv_magnitude – Value between 0 and 1

Return type

float

current_setpoint_value(setpoint_label)[source]
current_setpoints()[source]
property setpoint_labels
ramp_production(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the production setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_stripper_level(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the stripper level setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_separator_level(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the separator level setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_reactor_level(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the reactor level setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_reactor_pressure(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the reactor pressure setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_g_in_product(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the mole percent of compoent g in the product stream (indicator of process quality) setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_ya(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the yA setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_yac(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the yAC setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_reactor_temp(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the reactor temperature setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_recycle_valve_pos(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the recycle valve position setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_steam_valve_pos(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the steam valve position setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_agitator_speed(target_val=None, duration=None, slope=None)[source]

Initiates a ramp profile for the agitator speed setpoint at at the current simulation time. The ramp will start immediately, when simulate() is called. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows a ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • target_val (float, optional) – Value of the setpoint after the ramp profile is completed.

  • duration (float, optional (default: 0.0)) – Duration of the change from the current setpoint value to the target_val in (hours). Step change for duration = 0, ramp otherwise

  • slope (float, optional) – Slope of the ramp profile of the setpoint change in setpoint_change/hour. Not considered if target_val and duration are also both specified.

ramp_setpoint(setpoint_label, target_val=None, duration=None, slope=None, delay=0)[source]

Generic setpoint ramp generation. The setpoint ramp profile starts at the current simulation time and current setpoint value and follows the ramp profile specified by the target value, duration and slope. Only two of the profile defining parameters may be set simultaneously (if all three are set, ‘slope’ is ignored).

Parameters
  • setpoint_label (Label as specified in the setpoint_labels.pkl in backend/setupinfo) –

  • (float) (delay) –

  • (float)

  • (float)

  • (float)

MatlabBridge

Low level wrapper for the Matlab engine for python that enables communication with the Simulink model

class pytep.matlab_bridge.MatlabBridge(model='MultiLoop_mode3', sim_path=None)[source]
start_engine()[source]

Starts an instance of the MATLAB engine

Returns

Returns True when the MATLAB engine is started

Return type

bool

stop_engine()[source]

Terminates the running MATLAB engine

run_until_paused()[source]

Runs the Simulink Simulation until it is paused or stopped

run_simulation()[source]

Runs the Simulink simulation with the appropriate command, given the current state of the Simulink model Possible states: Stopped, Paused, Running (Warns the user that its running)

block_until_sim_paused()[source]

Waits until the Simulink simulation completes the simulation or is paused, and then returns

start_simulation()[source]

Send the start command to the active Simulink simulation

continue_simulation()[source]

Send the continue command to the active Simulink simulation

pause_simulation()[source]

Send the pause command to the active Simulink simulation

stop_simulation()[source]

Send the stop command to the active Simulink simulation

reset_workspace()[source]

Resets the MATLAB workspace to the initial values

Resets all the block parameters in the Simulink diagram to the correct initial values

add_dir_to_matlab_path(dir_path)[source]

Add a directory to the MATLAB path

Parameters

dir_path (string) – string containing the desired path, to be added to the MATLAB path

set_idv_input_block_params(values_before, values_after, step_times)[source]

Setting the parameters for the idv (faults) block

Parameters
  • values_before (float) – np.array (28 by 1) of floats for corresponding idv (faults), between 0 and 1

  • values_after (float) – np.array (28 by 1) of floats for corresponding idv (faults), between 0 and 1

  • step_times (float) – Absolute simulation time of which the idv (fault) change occurs (stepping from value_before to value_after)

get_idv_input_block_params()[source]

Gets and returns the values for the idv (faults) block

Returns

  • values_before (float) – np.array (28 by 1) of floats for corresponding idv (faults), between 0 and 1

  • values_after (float) – np.array (28 by 1) of floats for corresponding idv (faults), between 0 and 1

  • step_times (float) – Absolute simulation time of which the idv (fault) change occurs (stepping from value_before to value_after)

set_production_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Producion setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_production_sp()[source]

Gets and returns the values for the Production setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_strip_level_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Stripper Level setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_strip_level_sp()[source]

Gets and returns the values for the Stripper Level setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_sep_level_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Seperation Level setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_sep_level_sp()[source]

Gets and returns the values for the Seperation Level setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_reactor_level_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Reactor Level setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_reactor_level_sp()[source]

Gets and returns the values for the Reactor Level setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_reactor_press_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Reactor Pressure setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_reactor_press_sp()[source]

Gets and returns the values for the Reactor Pressure setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_g_in_product_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the mole percentage of component g in the product (Quality) setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_g_in_product_sp()[source]

Gets and returns the values for the mole percentage of component g in the product (Quality) setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_ya_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the YA setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_ya_sp()[source]

Gets and returns the values for the YA setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_yac_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the YAC setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_yac_sp()[source]

Gets and returns the values for the YAC setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_reactor_temp_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Reactor Temperature setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_reactor_temp_sp()[source]

Gets and returns the values for the Reactor Temperature setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_recycle_valve_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Recycle Valve setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_recycle_valve_sp()[source]

Gets and returns the values for the Recycle Valve setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_steam_valve_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Steam Valve setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_steam_valve_sp()[source]

Gets and returns the values for the Steam Valve setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

set_agitator_sp(before=None, after=None, duration=0.0, start_time=None)[source]

Setting the Agitator setpoint

Parameters
  • before (float, optional) – Value of the setpoint before a change is initiated, by default the current setpoint value

  • after (float, optional) – Value of the setpoint after a change is initiated, by default the current setpoint value

  • duration (float, optional) – Duration of the change from ‘before’ to ‘after’ in (hours). Step change for duration = 0, ramp otherwise, by default 0.0

  • start_time (float, optional) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated, by default the current simulation time

get_agitator_sp()[source]

Gets and returns the values for the Agitator setpoint

Returns

  • before (float) – Value of the setpoint before a change is initiated

  • after (float) – Value of the setpoint after a change is initiated

  • duration (float) – Duration of the change from ‘before’ to ‘after’ in (hours)

  • t_start (float) – Absolute simulation time in hours at which the change from ‘before’ to ‘after’ is initiated

get_sim_status()[source]

Provides the simulation status of the active Simulink model

Returns

status – Takes on the values ‘stopped’ | ‘updating’ | ‘initializing’ | ‘running’ | ‘paused’ | ‘terminating’ | ‘external’

Return type

string

save_workspace(name)[source]

Saves the workspace to a .mat file with the specifed name

Parameters

name (mat file (mat)) – Workspace saved in the .mat format

get_workspace_variable(name)[source]

Fetches a workspace variable from the MATLAB workspace to Python.

Parameters

name (string) – Name of the desired workspace variable to obtain

Returns

Numeric primitives are returned as np.floats. Vectors are returned as np.arrays. Matrices are returned as np.arrays.

Return type

np.floats, np.arrays

set_simpause_time(absolute_pause_time)[source]

Pauses Simulink simulation time at a specified time (in hours)

Parameters

absolute_pause_time (float) – Absolute pause time in hours (i.e at hour 10.5)

set_workspace_variable(name, value)[source]

Sets a MATLAB workspace variable from Python

Parameters
  • name (string) – string identifier for desired workspace variable

  • value (np.floats, np.arrays) – 1d arrays are set as vectors. 2d arrays are set as matrices.

isolate_recent_data_in_workspace(ref_time)[source]

Extracts the parts of the timeseries simulation data in the MATLAB workspace for which t_sim > ref_time and and stores them in separate arrays in the MATlAB workspace. Created arrays are: latest_tout, latest_op_cost, latest_simout, latest_xmv, latest_setpoints, latest_idv_list

Parameters

ref_time (float) – Absolute simulation time.

engineutils

General low-level utility functions for the Matlab engine for python, which are utilized by the MatlabBridge.

Functions that simplify the interaction with the matlab engine in python

pytep.engineutils.get_workspace(engine)[source]

Gets and returns the MATLAB workspace

Parameters

engine (MATLAB engine) – A MATLAB engine object

Returns

Dictionary containing key-value pairs for each variable and its value from the MATLAB workspace

Return type

Dictionary

pytep.engineutils.set_variable(engine, var, val)[source]

Sets a MATLAB workspace variable from Python

Parameters
  • engine (MATLAB engine) – A MATLAB engine object

  • var (string) – string containing the variable name to set in the workspace

  • val (np.floats, np.arrays) – 1d arrays are set as vectors. 2d arrays are set as matrices.

pytep.engineutils.get_variable(engine, var)[source]

Gets a workspace variable from the MATLAB workspace to Python.

Parameters
  • engine (MATLAB engine) – A MATLAB engine object

  • var (string) – string containing the variable name to get from the workspace

Returns

Numeric primitives are returned as np.floats. Vectors are returned as np.arrays. Matrices are returned as np.arrays.

Return type

np.floats, np.arrays