Skip to content

Commit

Permalink
added randomized API key to reopt_jl and updated all Julia dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lilycatolson committed Dec 14, 2023
1 parent 3fabdf6 commit 5eee297
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 36 deletions.
70 changes: 38 additions & 32 deletions omf/solvers/reopt_jl/REoptSolver/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ weakdeps = ["ChainRulesCore", "Test"]

[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "02f731463748db57cc2ebfbd9fbc9ce8280d3433"
git-tree-sha1 = "cde29ddf7e5726c9fb511f340244ea3481267608"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.7.1"
version = "3.7.2"

[deps.Adapt.extensions]
AdaptStaticArraysExt = "StaticArrays"
Expand Down Expand Up @@ -51,9 +51,9 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[deps.BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
git-tree-sha1 = "d9a9701b899b30332bbcb3e1679c41cce81fb0e8"
git-tree-sha1 = "f1f03a9fa24271160ed7e73051fba3c1a759b53f"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.3.2"
version = "1.4.0"

[[deps.BitFlags]]
git-tree-sha1 = "2dc09997850d68179b69dafb58ae806167a32b1b"
Expand Down Expand Up @@ -142,9 +142,9 @@ version = "0.3.0"

[[deps.Compat]]
deps = ["UUIDs"]
git-tree-sha1 = "8a62af3e248a8c4bad6b32cbbe663ae02275e32c"
git-tree-sha1 = "886826d76ea9e72b35fcd000e535588f7b60f21d"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "4.10.0"
version = "4.10.1"
weakdeps = ["Dates", "LinearAlgebra"]

[deps.Compat.extensions]
Expand Down Expand Up @@ -189,9 +189,9 @@ version = "0.1.0"

[[deps.CoolProp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "3e707957390c96dbe6184dc27eb6da2f5d2e6aac"
git-tree-sha1 = "f0f70a17d132d2ab5bf2b61993db36ac1099f6c7"
uuid = "3351c21f-4feb-5f29-afb9-f4fcb0e27549"
version = "6.5.0+0"
version = "6.6.0+0"

[[deps.Crayons]]
git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15"
Expand Down Expand Up @@ -385,9 +385,9 @@ version = "1.10.1"

[[deps.HiGHS]]
deps = ["HiGHS_jll", "MathOptInterface", "PrecompileTools", "SparseArrays"]
git-tree-sha1 = "dc62a0bb7b13cab77b6992f0b778d3c79b5ea30c"
git-tree-sha1 = "fce13308f09771b160232903cad57be39a8a0ebb"
uuid = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
version = "1.7.2"
version = "1.7.5"

[[deps.HiGHS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl"]
Expand All @@ -397,9 +397,9 @@ version = "1.6.0+0"

[[deps.Hwloc_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "8ecb0b34472a3c98f945e3c75fc7d5428d165511"
git-tree-sha1 = "ca0f6bf568b4bfc807e7537f081c81e35ceca114"
uuid = "e33a78d0-f292-5ffc-b300-72abe9b543c8"
version = "2.9.3+0"
version = "2.10.0+0"

[[deps.ICU_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down Expand Up @@ -458,15 +458,21 @@ version = "0.21.4"

[[deps.JpegTurbo_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "6f2675ef130a300a112286de91973805fcc5ffbc"
git-tree-sha1 = "60b1194df0a3298f460063de985eae7b01bc011a"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "2.1.91+0"
version = "3.0.1+0"

[[deps.JuMP]]
deps = ["LinearAlgebra", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "Printf", "SnoopPrecompile", "SparseArrays"]
git-tree-sha1 = "3cacc9aa90f3313e0375b1c4ac4641c8d57349ef"
deps = ["LinearAlgebra", "MacroTools", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "Printf", "SnoopPrecompile", "SparseArrays"]
git-tree-sha1 = "cd161958e8b47f9696a6b03f563afb4e5fe8f703"
uuid = "4076af6c-e467-56ae-b986-b466b2749572"
version = "1.13.0"
version = "1.17.0"

[deps.JuMP.extensions]
JuMPDimensionalDataExt = "DimensionalData"

[deps.JuMP.weakdeps]
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"

[[deps.Kerberos_krb5_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down Expand Up @@ -590,9 +596,9 @@ version = "1.9.4+0"

[[deps.MPICH_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "MPIPreferences", "TOML"]
git-tree-sha1 = "8a5b4d2220377d1ece13f49438d71ad20cf1ba83"
git-tree-sha1 = "2ee75365ca243c1a39d467e35ffd3d4d32eef11e"
uuid = "7cb0a576-ebde-5e09-9194-50597f1243b4"
version = "4.1.2+0"
version = "4.1.2+1"

[[deps.MPIPreferences]]
deps = ["Libdl", "Preferences"]
Expand Down Expand Up @@ -623,9 +629,9 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MathOptInterface]]
deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "DataStructures", "ForwardDiff", "JSON", "LinearAlgebra", "MutableArithmetics", "NaNMath", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays", "SpecialFunctions", "Test", "Unicode"]
git-tree-sha1 = "70ea2892b8bfffecc0387ba1a6a21192814f120c"
git-tree-sha1 = "362ae34a5291a79e16b8eb87b5738532c5e799ff"
uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
version = "1.22.0"
version = "1.23.0"

[[deps.MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "NetworkOptions", "Random", "Sockets"]
Expand Down Expand Up @@ -665,9 +671,9 @@ version = "2022.10.11"

[[deps.MutableArithmetics]]
deps = ["LinearAlgebra", "SparseArrays", "Test"]
git-tree-sha1 = "6985021d02ab8c509c841bb8b2becd3145a7b490"
git-tree-sha1 = "806eea990fb41f9b36f1253e5697aa645bf6a9f8"
uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
version = "1.3.3"
version = "1.4.0"

[[deps.NaNMath]]
deps = ["OpenLibm_jll"]
Expand Down Expand Up @@ -805,19 +811,19 @@ uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[[deps.PyCall]]
deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Serialization", "VersionParsing"]
git-tree-sha1 = "43d304ac6f0354755f1d60730ece8c499980f7ba"
git-tree-sha1 = "c9932f1c60d2e653df4f06d76108af8fde2200c0"
uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
version = "1.96.1"
version = "1.96.3"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[deps.REopt]]
deps = ["ArchGDAL", "CSV", "CoolProp", "DataFrames", "Dates", "DelimitedFiles", "HTTP", "JLD", "JSON", "JuMP", "LinDistFlow", "LinearAlgebra", "Logging", "MathOptInterface", "Requires", "Roots", "Statistics", "TestEnv"]
git-tree-sha1 = "f0bb76959fb18989d9cc8510a9fd06e37564c3bf"
git-tree-sha1 = "013fc07e92f4b742f09b7adae75d2d63dfbc9237"
uuid = "d36ad4e8-d74a-4f7a-ace1-eaea049febf6"
version = "0.32.7"
version = "0.39.0"

[[deps.Random]]
deps = ["SHA", "Serialization"]
Expand Down Expand Up @@ -1053,9 +1059,9 @@ version = "1.6.1"

[[deps.XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Zlib_jll"]
git-tree-sha1 = "da69178aacc095066bad1f69d2f59a60a1dd8ad1"
git-tree-sha1 = "801cbe47eae69adc50f36c3caec4758d2650741b"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.12.0+0"
version = "2.12.2+0"

[[deps.XZ_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand Down Expand Up @@ -1104,10 +1110,10 @@ uuid = "06c338fa-64ff-565b-ac2f-249532af990e"
version = "100.701.100+0"

[[deps.libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c"
deps = ["Artifacts", "JLLWrappers", "Libdl", "Zlib_jll"]
git-tree-sha1 = "93284c28274d9e75218a416c65ec49d0e0fcdf3d"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.38+0"
version = "1.6.40+0"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down
5 changes: 4 additions & 1 deletion omf/solvers/reopt_jl/REoptSolver/src/REoptSolver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function results_to_json(results, output_path)
end
end

function run(path::String, outages::Bool=false, microgrid_only::Bool=false, max_runtime_s::Union{Nothing,Int}=nothing)
function run(path::String, outages::Bool=false, microgrid_only::Bool=false, max_runtime_s::Union{Nothing,Int}=nothing,
api_key::String="WhEzm6QQQrks1hcsdN0Vrd56ZJmUyXJxTJFg6pn9")

ENV["NREL_DEVELOPER_API_KEY"]=api_key

m = get_model(path, max_runtime_s)
m2 = get_model(path, max_runtime_s)
Expand Down
23 changes: 20 additions & 3 deletions omf/solvers/reopt_jl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json, time
import os, platform
import random

thisDir = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -8,7 +9,7 @@ def build_julia_image():

os.system(f'''julia --project={thisDir}/REoptSolver -e '
import Pkg; Pkg.instantiate();
import REoptSolver; using PackageCompiler;
import REoptSolver; using PackageCompiler;
PackageCompiler.create_sysimage(["REoptSolver"]; sysimage_path="{thisDir}/reopt_jl.so",
precompile_execution_file="{thisDir}/precompile_reopt.jl", cpu_target="generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)")
' ''')
Expand Down Expand Up @@ -236,6 +237,19 @@ def write_json(outputPath, jsonData):
# run_reopt_jl
##########################################################################

def get_randomized_api_key():
'''returns a random API key'''
REOPT_API_KEYS = [
'WhEzm6QQQrks1hcsdN0Vrd56ZJmUyXJxTJFg6pn9',
'Y8GMAFsqcPtxhjIa1qfNj5ILxN5DH5cjV3i6BeNE',
'etg8hytwTYRf4CD0c4Vl9U7ACEQnQg6HV2Jf4E5W',
'BNFaSCCwz5WkauwJe89Bn8FZldkcyda7bNwDK1ic',
'L2e5lfH2VDvEm2WOh0dJmzQaehORDT8CfCotaOcf',
'08USmh2H2cOeAuQ3sCCLgzd30giHjfkhvsicUPPf'
]
key_index = random.randint(0,5)
return REOPT_API_KEYS[key_index]

#potential optional inputs (for solver): ratio_gap, threads, max_solutions, verbosity
def run_reopt_jl(path, inputFile="", default=False, convert=False, outages=False, microgrid_only=False, max_runtime_s=None):
''' calls 'run' function through run_reopt.jl (Julia file) '''
Expand Down Expand Up @@ -266,9 +280,12 @@ def run_reopt_jl(path, inputFile="", default=False, convert=False, outages=False
outages_jl = "false" if not outages else "true"
max_runtime_s_jl = "nothing" if max_runtime_s == None else max_runtime_s

api_key = get_randomized_api_key()

os.system(f'''julia --sysimage={f'{thisDir}/reopt_jl.so'} -e '
using .REoptSolver;
REoptSolver.run("{path}", {outages_jl}, {microgrid_only_jl}, {max_runtime_s_jl})
ENV["NREL_DEVELOPER_API_KEY"]="{api_key}";
REoptSolver.run("{path}", {outages_jl}, {microgrid_only_jl}, {max_runtime_s_jl}, "{api_key}")
' ''')
except Exception as e:
print(e)
Expand Down Expand Up @@ -299,7 +316,7 @@ def _test():

############### CE test case
# CE.json copied from CE Test Case/Scenario_test_POST.json
#runAllSolvers(path, "CE Test Case", fileName="CE.json", solvers=all_solvers) #, max_runtime_s=240)
#runAllSolvers(path, "CE Test Case", fileName="CE.json", solvers=all_solvers, max_runtime_s=240)

############## CONWAY_30MAY23_SOLARBATTERY
# CONWAY_SB.json copied from CONWAY_30MAY23_SOLARBATTERY/Scenario_test_POST.json
Expand Down

0 comments on commit 5eee297

Please sign in to comment.