Skip to content

Commit 99f8cb8

Browse files
authored
Merge pull request #27 from LAMPSPUC/main
update dev from main
2 parents 0c38095 + 137da5e commit 99f8cb8

File tree

11 files changed

+162
-49
lines changed

11 files changed

+162
-49
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22
on:
33
push:
44
branches:
5-
- master
5+
- main
66
tags: ['*']
77
pull_request:
88
workflow_dispatch:
@@ -24,7 +24,7 @@ jobs:
2424
matrix:
2525
version:
2626
- '1.11'
27-
- '1.6'
27+
- '1'
2828
os:
2929
- ubuntu-latest
3030
arch:
@@ -39,4 +39,7 @@ jobs:
3939
- uses: julia-actions/julia-buildpkg@v1
4040
- uses: julia-actions/julia-runtest@v1
4141
- uses: julia-actions/julia-processcoverage@v1
42-
- uses: codecov/codecov-action@v5
42+
- uses: codecov/codecov-action@v5
43+
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}
45+
slug: LAMPSPUC/ApplicationDrivenLearning.jl
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags: '*'
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
permissions:
13+
actions: write
14+
contents: write
15+
pull-requests: read
16+
statuses: write
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: julia-actions/setup-julia@v2
21+
with:
22+
version: '1'
23+
- uses: julia-actions/cache@v2
24+
- name: Install dependencies
25+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
26+
- name: Build and deploy
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
29+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
30+
run: julia --project=docs/ docs/make.jl

.github/workflows/format_check.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: format-check
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1'
16+
- uses: actions/checkout@v4
17+
- name: Format check
18+
shell: julia --color=yes {0}
19+
run: |
20+
using Pkg
21+
# If you update the version, also update the style guide docs.
22+
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
23+
using JuliaFormatter
24+
format("src", verbose=true)
25+
format("test", verbose=true)
26+
format("docs", verbose=true)
27+
out = String(read(Cmd(`git diff`)))
28+
if isempty(out)
29+
exit(0)
30+
end
31+
@error "Some files have not been formatted !!!"
32+
write(stdout, out)
33+
exit(1)

Project.toml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
name = "ApplicationDrivenLearning"
22
uuid = "0856f1c8-ef17-4e14-9230-2773e47a789e"
3-
authors = ["giovanni "]
3+
authors = ["Giovanni Amorin"]
44
version = "0.1.0"
55

66
[deps]
77
BilevelJuMP = "485130c0-026e-11ea-0f1a-6992cd14145c"
8-
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
98
DiffOpt = "930fe3bc-9c6b-11ea-2d94-6184641e85e7"
9+
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
10+
JobQueueMPI = "32d208e1-246e-420c-b6ff-18b71b410923"
1011
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
12+
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
1113
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
1214
ParametricOptInterface = "0ce4ce61-57bf-432b-a095-efac525d185e"
1315
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1416
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
15-
JobQueueMPI = "32d208e1-246e-420c-b6ff-18b71b410923"
16-
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
17+
18+
[compat]
19+
BilevelJuMP = "0.6.2"
20+
DiffOpt = "0.5.0"
21+
Flux = "0.14.25"
22+
JobQueueMPI = "0.1.1"
23+
JuMP = "1.24"
24+
Optim = "1.11"
25+
MPI = "0.20.22"
26+
ParametricOptInterface = "0.9.0"
27+
Zygote = "0.6.75"
28+
julia = "1.10"

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
ApplicationDrivenLearning.jl is a Julia package for training time series models using the application driven learning framework, that connects the optimization problem final cost with predictive model parameters in order to achieve the best model for a given application.
44

5+
[![Build Status](https://github.com/LAMPSPUC/ApplicationDrivenLearning.jl/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/LAMPSPUC/ApplicationDrivenLearning.jl/actions?query=workflow%3ACI)
6+
7+
[![codecov](https://codecov.io/gh/LAMPSPUC/ApplicationDrivenLearning.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/LAMPSPUC/ApplicationDrivenLearning.jl)
8+
9+
[![dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://LAMPSPUC.github.io/ApplicationDrivenLearning.jl/dev/)
10+
511
## Usage
612

713
```julia
814
import Pkg
915

10-
Pkg.add("ApplicationDrivenLearning") # not working yet! clone the repo instead
16+
Pkg.add("https://github.com/LAMPSPUC/ApplicationDrivenLearning.jl")
1117

1218
using ApplicationDrivenLearning
1319

@@ -73,4 +79,4 @@ This package is **not yet** registered so if you want to use or test the code cl
7379
## Contributing
7480

7581
* PRs such as adding new models and fixing bugs are very welcome!
76-
* For nontrivial changes, you'll probably want to first discuss the changes via issue.
82+
* For nontrivial changes, you'll probably want to first discuss the changes via issue.

docs/make.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using Documenter
1+
import Documenter
22

3-
push!(LOAD_PATH, "../src")
43
using ApplicationDrivenLearning
54

6-
makedocs(;
7-
modules = [ApplicationDrivenLearning],
8-
doctest = false,
5+
Documenter.makedocs(;
96
clean = true,
10-
sitename = "ApplicationDrivenLearning.jl",
7+
sitename = "ApplicationDrivenLearning.jl documentation",
118
authors = "Giovanni Amorim, Joaquim Garcia",
12-
pages = ["Home" => "index.md", "API Reference" => "reference.md"],
9+
)
10+
11+
Documenter.deploydocs(;
12+
repo = "github.com/LAMPSPUC/ApplicationDrivenLearning.jl.git",
13+
push_preview = true,
1314
)

src/jump.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,9 @@ JuMP.object_dictionary(model::Model) = model.obj_dict
117117

118118
function JuMP.set_optimizer(model::Model, builder, evaluate_duals::Bool = true)
119119
# set diffopt optimizer for plan model
120-
new_diff_optimizer = DiffOpt.diff_optimizer(builder)
121-
JuMP.set_optimizer(
122-
model.plan,
123-
() ->
124-
POI.Optimizer(new_diff_optimizer; evaluate_duals = evaluate_duals),
125-
)
120+
new_diff_optimizer =
121+
DiffOpt.diff_optimizer(builder; with_parametric_opt_interface = true)
122+
JuMP.set_optimizer(model.plan, () -> new_diff_optimizer)
126123

127124
# basic setting for assess model
128125
return JuMP.set_optimizer(model.assess, builder)
@@ -133,10 +130,6 @@ function JuMP.set_silent(model::Model)
133130
return MOI.set(model.assess, MOI.Silent(), true)
134131
end
135132

136-
function JuMP.num_variables(model::Model)
137-
return JuMP.num_variables(model.plan) + JuMP.num_variables(model.assess)
138-
end
139-
140133
function JuMP.num_constraints(model::Model)
141134
return JuMP.num_constraints(model.plan) + JuMP.num_constraints(model.assess)
142135
end

src/simulation.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function compute_single_step_gradient(
2525
dCdy::Vector{<:Real},
2626
)
2727
dCdz .= dual.(model.assess[:assess_policy_fix])
28+
DiffOpt.empty_input_sensitivities!(model.plan)
2829
for i = 1:size(model.policy_vars, 1)
2930
MOI.set(
3031
model.plan,
@@ -35,11 +36,12 @@ function compute_single_step_gradient(
3536
end
3637
DiffOpt.reverse_differentiate!(model.plan)
3738
for j = 1:size(model.forecast_vars, 1)
38-
dCdy[j] = MOI.get(
39-
model.plan,
40-
POI.ReverseParameter(),
41-
model.plan_forecast_params[j],
42-
)
39+
dCdy[j] =
40+
MOI.get(
41+
model.plan,
42+
DiffOpt.ReverseConstraintSet(),
43+
ParameterRef(model.plan_forecast_params[j]),
44+
).value
4345
end
4446

4547
return dCdy

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Random.seed!(123)
1313

1414
include("utils.jl")
1515
include("test_predictive_model.jl")
16-
include("test_newsvendor.jl")
16+
include("test_newsvendor.jl")

test/test_newsvendor.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,27 @@ end)
1919
con1, y <= d.plan
2020
con2, y + w <= x.plan
2121
end)
22-
@objective(ApplicationDrivenLearning.Plan(model), Min, c * x.plan - q * y - r * w)
22+
@objective(
23+
ApplicationDrivenLearning.Plan(model),
24+
Min,
25+
c * x.plan - q * y - r * w
26+
)
2327
@variables(ApplicationDrivenLearning.Assess(model), begin
2428
y >= 0
2529
w >= 0
2630
end)
27-
@constraints(ApplicationDrivenLearning.Assess(model), begin
28-
con1, y <= d.assess
29-
con2, y + w <= x.assess
30-
end)
31-
@objective(ApplicationDrivenLearning.Assess(model), Min, c * x.assess - q * y - r * w)
31+
@constraints(
32+
ApplicationDrivenLearning.Assess(model),
33+
begin
34+
con1, y <= d.assess
35+
con2, y + w <= x.assess
36+
end
37+
)
38+
@objective(
39+
ApplicationDrivenLearning.Assess(model),
40+
Min,
41+
c * x.assess - q * y - r * w
42+
)
3243
set_optimizer(model, HiGHS.Optimizer)
3344
set_silent(model)
3445
nn = Chain(Dense(1 => 1; bias = false, init = (size...) -> rand(size...)))
@@ -41,7 +52,10 @@ nn = Chain(Dense(1 => 1; bias = false, init = (size...) -> rand(size...)))
4152
opt = ApplicationDrivenLearning.Options(
4253
ApplicationDrivenLearning.BilevelMode,
4354
optimizer = HiGHS.Optimizer,
44-
mode = BilevelJuMP.FortunyAmatMcCarlMode(primal_big_M = 100, dual_big_M = 100),
55+
mode = BilevelJuMP.FortunyAmatMcCarlMode(
56+
primal_big_M = 100,
57+
dual_big_M = 100,
58+
),
4559
silent = true,
4660
)
4761
sol = ApplicationDrivenLearning.train!(model, X, Y, opt)

0 commit comments

Comments
 (0)