Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add job queue mpi #10

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.1.0"

[deps]
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
JobQueueMPI = "32d208e1-246e-420c-b6ff-18b71b410923"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ProgressTables = "e0b4b9f6-8cc7-451e-9c86-94c5316e9f73"
Expand Down
78 changes: 78 additions & 0 deletions mpiexecjl.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (C) 2023 Guilherme Bodin
# License is MIT "Expat"
#
# Commentary:
#
# Command line utility to call the `mpiexec` binary used by the `MPI.jl` version
# in the given Julia project. It has the same syntax as the `mpiexec` binary
# that would be called, with the additional `--project=...` flag to select a
# different Julia project.
#
# Examples of usage (the MPI flags available depend on the MPI implementation
# called):
#
# $ mpiexecjl -n 40 julia mpi-script.jl
# $ mpiexecjl --project=my_experiment -n 80 --oversubscribe julia mpi-script.jl
# To call the application in parallel in the non-compiled mode powershell.exe -ExecutionPolicy ByPass -File .\mpiexecjl.ps1 -n 3 --project=. julia .\main.jl

function usage {
Write-Host "Usage: $([System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)) [--project=...] MPIEXEC_ARGUMENTS..."
Write-Host "Call the mpiexec binary in the Julia environment specified by the --project option."
Write-Host "If no project is specified, the MPI associated with the global Julia environment will be used."
Write-Host "All other arguments are forwarded to mpiexec."
}

$julia_args = @()
$PROJECT_ARG = ""

foreach ($arg in $args) {
if ($arg -match "^--project(=.*)?$") {
$PROJECT_ARG = $arg
}
elseif ($arg -eq "-h" -or $arg -eq "--help") {
$helpRequested = $true
usage
Write-Host "Below is the help of the current mpiexec."
Write-Host
exit 0
}
else {
$julia_args += $arg
}
}

if (-not $julia_args) {
Write-Error "ERROR: no arguments specified."
usage
exit 1
}

if ($env:JULIA_BINDIR) {
$JULIA_CMD = Join-Path $env:JULIA_BINDIR "julia"
} else {
$JULIA_CMD = "julia"
}

$SCRIPT = @'
using MPI
ENV[\"JULIA_PROJECT\"] = dirname(Base.active_project())
mpiexec(exe -> run(`$exe $ARGS`))
'@

$PRECOMPILATION_SCRIPT = @'
println(\"precompiling current project before running MPI\")

import Pkg
Pkg.activate(dirname(Base.active_project()))
Pkg.instantiate()

println(\"precompilation finished\")
'@

& $JULIA_CMD $PROJECT_ARG -e $PRECOMPILATION_SCRIPT

if ($PROJECT_ARG) {
& $JULIA_CMD $PROJECT_ARG --color=yes --startup-file=no --compile=min -O0 -e $SCRIPT -- $julia_args
} else {
& $JULIA_CMD --color=yes --startup-file=no --compile=min -O0 -e $SCRIPT -- $julia_args
}
6 changes: 5 additions & 1 deletion src/LightBenders.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module LightBenders

# Standard library dependencies
using JobQueueMPI
using LinearAlgebra
using Statistics

# Third party dependencies
using EnumX
using JuMP

using ProgressTables

# module constants
const JQM = JobQueueMPI

# Keys aspects of the algorithm
include("debugging_options.jl")
include("results.jl")
Expand Down Expand Up @@ -40,6 +43,7 @@ include("simulate.jl")

# training implementations
include("training_strategies/benders_serial.jl")
include("training_strategies/benders_job_queue.jl")

# simulation implementations
include("simulation_strategies/benders_serial.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/stopping_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct ConvergenceResult
end

has_converged(result::ConvergenceResult) = result.has_converged
message(result::ConvergenceResult) = result.message
results_message(result::ConvergenceResult) = result.message

"""
IterationLimit(max_iterations::Int)
Expand Down
17 changes: 14 additions & 3 deletions src/train.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
abstract type AbstractTrainingImplementation end

struct BendersSerialTraining <: AbstractTrainingImplementation end
struct SerialTraining <: AbstractTrainingImplementation end

struct JobQueueTraining <: AbstractTrainingImplementation end

"""
"""
Base.@kwdef mutable struct PolicyTrainingOptions
num_scenarios::Int
lower_bound::Real = 0.0
discount_rate::Real = 0.0
implementation_strategy::AbstractTrainingImplementation = BendersSerialTraining()
implementation_strategy::AbstractTrainingImplementation = SerialTraining()
cut_strategy::CutStrategy.T = CutStrategy.SingleCut
risk_measure::AbstractRiskMeasure = RiskNeutral()
stopping_rule::AbstractStoppingRule = IterationLimit(5)
Expand Down Expand Up @@ -39,7 +41,7 @@ function train(;
inputs = nothing,
policy_training_options::PolicyTrainingOptions
)
if policy_training_options.implementation_strategy isa BendersSerialTraining
if policy_training_options.implementation_strategy isa SerialTraining
return serial_benders_train(;
state_variables_builder,
first_stage_builder,
Expand All @@ -48,6 +50,15 @@ function train(;
inputs,
policy_training_options,
)
elseif policy_training_options.implementation_strategy isa JobQueueTraining
return job_queue_benders_train(;
state_variables_builder,
first_stage_builder,
second_stage_builder,
second_stage_modifier,
inputs,
policy_training_options,
)
else
error("ImplementationStrategy not implemented.")
end
Expand Down
Loading
Loading