To work with ENERGY 2100 policy files in the Julia REPL, you must first set up your workspace in VS Code (by activating the environment and loading the EnergyModel's package and global structures).

All policy files are Julia script files and are stored in the \Policy folder. Each policy is set up as a module having the same name as the filename. The last function call in the policy file is a control function, PolicyControl(DB), which reads in the model database, DB, as input.

You can test compiling a policy file interactively directly from the Julia REPL.

Step 1 - Include your policy file in the Julia workspace

Including the policy file in your workspace gives you access to the functions defined in the given policy module. In the Julia REPL, type the following:

julia> include("Policy/MyPolicyFile.jl")

Step 2 - Execute the policy code by calling its PolicyControl function

julia> MyPolicyModule.PolicyControl(DB)

The MyPolicyModule.PolicyControl(DB) command executes the policy. If there are no errors, it will stop with a julia> prompt. 


🕮

Exercise

Run the policy file, Res_PeakSavings.jl. Make sure you have all the needed packages loaded in your VS code workspace.

View Solution
using EnergyModel
import EnergyModel: DB
include("Policy/Res_PeakSavings.jl")
Res_PeakSavings.PolicyControl(DB)

Alternative Method of Calling a Policy File from the REPL

The EnergyModel package gives you access to all of the variables, sets, databases, functions, and modules that have been defined in the model. To access these functions, you need to know the hierarchy of the calling functions.

EnergyModel.jl is stored in \src and calls all the files that define the structures and functionality of the model. For example, EnergyModel.jl loads all the modules from Policy.jl: include("../Policy/Policy.jl"), which loads all the policy modules defined in the reference case. Each of the policy modules defines a calling function: PolicyControl(DB), where DB points to the model's HDF5 database. In Julia's REPL, we are able to access any of the modules and functions defined in the EnergyModel package using the hierarchy and dots (.).

Hierarchy: EnergyModel loads the "Policy" module, which loads specific policy modules (such as: Res_PeakSavings), each of which has a controlling function named PolicyControl(DB).

So, to call the function defined in the Res_PeakSavings.jl policy file, we can type the following into the REPL:

using EnergyModel
EnergyModel.Policy.Res_PeakSavings.PolicyControl(EnergyModel.DB)

Alternatively, we can assign the EnergyModel package a short name and use the short name in the REPL:

import EnergyModel as M
M.Policy.Res_PeakSavings.PolicyControl(M.DB)

Alternatively, we are able to access the database and the policy module directly without using the dots (".") by importing the database and including the policy file into the REPL, such as:

using EnergyModel
const DB = EnergyModel.DB
include("Policy/Res_PeakSavings.jl")
Res_PeakSavings.PolicyControl(DB)

If the policy file hits errors and you make changes to the file and save it, VS Code may not recognize the newly saved file in your current workspace. 

Step 3 - Load Julia's "Revise" package if you make changes to your policy file

Revise.jl is a Julia package that automatically updates function, module, and type definitions in a running Julia session whenever the underlying source code files change. It eliminates the need to restart the REPL or manually re-include files, significantly speeding up development workflows by allowing immediate testing of code changes.


If you make changes to theyour policy file in your current VS Code session, use Julia's "Revise" package, which is part of EnergyModel's global environment. To use Revise, follow the steps below:

  1. Load the Revise package:

using Revise

  1. Run the policy's control procedure again:

MyPolicyModule.PolicyControl(DB)


Now that you have compiled your policy file (which modified policy variables), you may want to view the values of the variables to verify worked as intended. For instructions, please refer to Viewing Variables Using the Julia REPL.