Skip to content

Commit

Permalink
Merge pull request #764 from ProjectTorreyPines/dev
Browse files Browse the repository at this point in the history
Major update to the multi_objective and database generator studies
  • Loading branch information
orso82 authored Dec 6, 2024
2 parents 39a3a4d + 6cbf04f commit 41ce14c
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 277 deletions.
51 changes: 28 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ else
endif

GENERAL_REGISTRY_PACKAGES := CoordinateConventions FuseExchangeProtocol MillerExtendedHarmonic IMASdd IMASutils
FUSE_PACKAGES_MAKEFILE := ADAS BalanceOfPlantSurrogate BoundaryPlasmaModels CHEASE CoordinateConventions EPEDNN FiniteElementHermite FusionMaterials FuseExchangeProtocol IMAS IMASdd IMASutils MXHEquilibrium MeshTools MillerExtendedHarmonic NEO NNeutronics QED RABBIT SimulationParameters TEQUILA TGLFNN TJLF VacuumFields
FUSE_PACKAGES_MAKEFILE := ADAS BalanceOfPlantSurrogate BoundaryPlasmaModels CHEASE CoordinateConventions EPEDNN FiniteElementHermite FRESCO FusionMaterials FuseExchangeProtocol IMAS IMASdd IMASutils MXHEquilibrium MeshTools MillerExtendedHarmonic NEO NNeutronics QED RABBIT SimulationParameters TEQUILA TGLFNN TJLF TroyonBetaNN VacuumFields
FUSE_PACKAGES_MAKEFILE_EXTENSION := ThermalSystemModels
ifndef NO_FUSE_EXTENSION
FUSE_PACKAGES_MAKEFILE := $(FUSE_PACKAGES_MAKEFILE) $(FUSE_PACKAGES_MAKEFILE_EXTENSION)
Expand Down Expand Up @@ -69,25 +69,25 @@ help: header help_info
ADAS:
$(call clone_pull_repo,$@)

FUSE:
$(call clone_pull_repo,$@)
BalanceOfPlantSurrogate:
$(call clone_pull_repo$@)

IMAS:
BoundaryPlasmaModels:
$(call clone_pull_repo,$@)

IMASdd:
CHEASE:
$(call clone_pull_repo,$@)

CoordinateConventions:
$(call clone_pull_repo,$@)

MillerExtendedHarmonic:
EPEDNN:
$(call clone_pull_repo,$@)

IMASutils:
FiniteElementHermite:
$(call clone_pull_repo,$@)

FuseUtils:
FRESCO:
$(call clone_pull_repo,$@)

FusionMaterials:
Expand All @@ -96,7 +96,13 @@ FusionMaterials:
FuseExchangeProtocol:
$(call clone_pull_repo,$@)

VacuumFields:
IMAS:
$(call clone_pull_repo,$@)

IMASdd:
$(call clone_pull_repo,$@)

IMASutils:
$(call clone_pull_repo,$@)

MXHEquilibrium:
Expand All @@ -105,46 +111,45 @@ MXHEquilibrium:
MeshTools:
$(call clone_pull_repo,$@)

TGLFNN:
MillerExtendedHarmonic:
$(call clone_pull_repo,$@)

TJLF:
NEO:
$(call clone_pull_repo,$@)

EPEDNN:
NNeutronics:
$(call clone_pull_repo,$@)

QED:
$(call clone_pull_repo,$@)

FiniteElementHermite:
RABBIT:
$(call clone_pull_repo,$@)

CHEASE:
SimulationParameters:
$(call clone_pull_repo,$@)

TEQUILA:
$(call clone_pull_repo,$@)

BalanceOfPlantSurrogate:
$(call clone_pull_repo$@)

NNeutronics:
TGLFNN:
$(call clone_pull_repo,$@)

SimulationParameters:
TJLF:
$(call clone_pull_repo,$@)

BoundaryPlasmaModels:
TroyonBetaNN:
$(call clone_pull_repo,$@)

NEO:
VacuumFields:
$(call clone_pull_repo,$@)

XSteam:
# ========

FUSE:
$(call clone_pull_repo,$@)

RABBIT:
XSteam:
$(call clone_pull_repo,$@)

ThermalSystemModels:
Expand Down
4 changes: 3 additions & 1 deletion docs/src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ For installation start your Julia interpreter by typing `julia` at the terminal,
1. Exit julia and clone [`FUSE examples`](https://github.com/ProjectTorreyPines/FuseExamples) in the current working directory. To see/run those `.ipynb` files, you'll need to use Jupyter-Lab or VScode.

```bash
fusebot install_examples
git clone https://github.com/ProjectTorreyPines/FuseExamples
```

This is a git repository that you are in control of. Do a `git fetch && git reset --hard origin/master` to gather the latest updates (**NOTE: this will wipe out any changes you have made to those examples!**)

## Install Jupyter-Lab with Julia support

1. You will need to [install `jupyter-lab`](https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html) if that's not already available on your system
Expand Down
8 changes: 8 additions & 0 deletions generate_dd/data_structures_extra/mhd_linear.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mhd_linear.time_slice[:].toroidal_mode[:].metric": {
"data_type": "FLT_0D",
"documentation": "MHD stability metric, to be defined by user",
"type": "dynamic",
"units": "-"
}
}
41 changes: 28 additions & 13 deletions src/actors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ end
#= ============= =#
# actor_logging #
#= ============= =#
function actor_logging(dd::IMAS.dd)
function actor_logging(dd::IMAS.DD)
aux = getfield(dd, :_aux)
if :fuse_actor_logging keys(aux)
aux[:fuse_actor_logging] = true
end
return aux[:fuse_actor_logging]
end

function actor_logging(dd::IMAS.dd, value::Bool)
function actor_logging(dd::IMAS.DD, value::Bool)
aux = getfield(dd, :_aux)
old_value = actor_logging(dd)
aux[:fuse_actor_logging] = value
Expand Down Expand Up @@ -219,14 +219,14 @@ end

function enter_workflow(actor::AbstractActor)
aux = _aux_workflow(actor.dd)
h = goto_worflow_depth(aux[:fuse_workflow], aux[:fuse_workflow_depth])
aux[:fuse_workflow_count] += 1
aux[:fuse_workflow_depth] += 1
return h[(name(actor), aux[:fuse_workflow_count])] = Workflow(name(actor))
h = goto_worflow_depth(aux[:fuse_workflow], aux[:fuse_workflow_depth][1])
aux[:fuse_workflow_count][1] += 1
aux[:fuse_workflow_depth][1] += 1
return h[(name(actor), aux[:fuse_workflow_count][1])] = Workflow(name(actor))
end

function exit_workflow(actor::AbstractActor)
return _aux_workflow(actor.dd)[:fuse_workflow_depth] -= 1
return _aux_workflow(actor.dd)[:fuse_workflow_depth][1] -= 1
end

function goto_worflow_depth(workflow::Workflow, depth::Int)
Expand All @@ -237,20 +237,35 @@ function goto_worflow_depth(workflow::Workflow, depth::Int)
return h
end

function workflow_depth(dd::IMAS.dd)
return _aux_workflow(dd)[:fuse_workflow_depth]
function workflow_depth(dd::IMAS.DD)
return _aux_workflow(dd)[:fuse_workflow_depth][1]
end

function workflow(dd::IMAS.dd)
function workflow(dd::IMAS.DD)
return _aux_workflow(dd)[:fuse_workflow]
end

function _aux_workflow(dd::IMAS.dd)
function _aux_workflow(dd::IMAS.DD)
aux = getfield(dd, :_aux)
if :fuse_workflow keys(aux)
aux[:fuse_workflow] = Workflow("Main")
aux[:fuse_workflow_depth] = 0
aux[:fuse_workflow_count] = 0
aux[:fuse_workflow_depth] = [0]
aux[:fuse_workflow_count] = [0]
end
return aux
end

"""
copy_workflow!(dd_out::IMAS.DD, dd_in::IMAS.DD)
Copy (:fuse_workflow, :fuse_workflow_depth, :fuse_workflow_count, :fuse_actor_logging) from `dd_in` to `dd_out`
This is useful when continuing the execution of a FUSE workflow on different dd's
"""
function copy_workflow!(dd_out::IMAS.DD, dd_in::IMAS.DD)
for item in (:fuse_workflow, :fuse_workflow_depth, :fuse_workflow_count, :fuse_actor_logging)
if item in keys(getfield(dd_in, :_aux))
getfield(dd_out, :_aux)[item] = getfield(dd_in, :_aux)[item]
end
end
end
1 change: 1 addition & 0 deletions src/actors/costing/costing_actor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function ActorCosting(dd::IMAS.dd, par::FUSEparameters__ActorCosting, act::Param
empty!(dd.costing)

ddR = IMAS.get_timeslice(Measurement{Float64}, dd)
copy_workflow!(ddR, dd) # to let FUSE continue tracking the execution workflow on ddR

ddR.costing.construction_start_year = act.ActorCosting.construction_start_year
ddR.costing.future.inflation_rate = act.ActorCosting.future_inflation_rate
Expand Down
8 changes: 4 additions & 4 deletions src/actors/stability/vertical_actor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ function _finalize(actor::ActorVerticalStability)

# Stability margin
mode = mhd.toroidal_mode[1]
mode.perturbation_type.description = "Vertical stability margin, > 0.15 for stability (N.B., not in Hz)"
mode.perturbation_type.description = "Vertical stability margin, > 0.15 for stability"
mode.perturbation_type.name = "m_s"
mode.n_tor = 0
mode.growthrate = actor.stability_margin # not in Hz
mode.stability_metric = actor.stability_margin

# Normalized growth rate
mode = mhd.toroidal_mode[2]
mode.perturbation_type.description = "Normalized vertical growth rate, < 10 for stability (N.B., not in Hz)"
mode.perturbation_type.description = "Normalized vertical growth rate, < 10 for stability"
mode.perturbation_type.name = "γτ"
mode.n_tor = 0
mode.growthrate = actor.normalized_growth_rate # not in Hz
mode.stability_metric = actor.normalized_growth_rate

# plot
if par.do_plot
Expand Down
5 changes: 3 additions & 2 deletions src/optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ function optimization_engine(
constraint_functions::AbstractVector{<:IMAS.ConstraintFunction},
save_folder::AbstractString,
save_dd::Bool,
p::ProgressMeter.Progress)
p::ProgressMeter.Progress,
generation_offset::Int)

# parallel evaluation of a generation
ProgressMeter.next!(p)
tmp = Distributed.pmap(
x -> _optimization_engine(ini, act, actor_or_workflow, x, objective_functions, constraint_functions, save_folder, p.counter, save_dd),
x -> _optimization_engine(ini, act, actor_or_workflow, x, objective_functions, constraint_functions, save_folder, p.counter + generation_offset, save_dd),
[X[k, :] for k in 1:size(X)[1]]
)
F = zeros(size(X)[1], length(tmp[1][1]))
Expand Down
13 changes: 8 additions & 5 deletions src/parameters/parameters_studies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function study_common_parameters(; kw...)
name = first(keys(kw))
default = first(values(kw))
if name == :server
return Switch{String}(["localhost", "omega", "saga"], "-", "Where to run"; default)
return Switch{String}(["localhost", "omega", "saga", "feynman"], "-", "Where to run"; default)
elseif name == :n_workers
return Entry{Int}("-", "Number of workers to run with"; default)
elseif name == :file_save_mode
return Switch{Symbol}([:safe_write, :overwrite], "-", "Saving file policy, `safe_write` only writes when the folder is empty"; default)
return Switch{Symbol}([:safe_write, :overwrite, :append], "-", "Saving file policy, `safe_write` only writes when the folder is empty"; default)
elseif name == :release_workers_after_run
return Entry{Bool}("-", "Releases the workers after running the study"; default)
elseif name == :save_dd
Expand Down Expand Up @@ -57,9 +57,9 @@ function setup(study::AbstractStudy)
return _setup(study)
end

function analyze(study::AbstractStudy)
function analyze(study::AbstractStudy; kw...)
# here you can add timing info and more
return _analyze(study)
return _analyze(study; kw...)
end

function run(study::T, args...; kw...) where {T<:AbstractStudy}
Expand Down Expand Up @@ -89,7 +89,10 @@ function check_and_create_file_save_mode(sty)
@assert !isfile(sty.save_folder) "$(sty.save_folder) can't be a file"
mkdir(sty.save_folder)
end
elseif sty.file_save_mode == :overwrite && !isdir(sty.save_folder)
elseif sty.file_save_mode == :overwrite
rm(sty.save_folder; force=true, recursive=true)
mkdir(sty.save_folder)
elseif sty.file_save_mode == :append
# this is fine
end
end
30 changes: 29 additions & 1 deletion src/utils_begin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,33 @@ function parallel_environment(cluster::String="localhost", nworkers::Integer=0,
error("Not running on saga cluster")
end

elseif cluster == "feynman"
if occursin("feynman", gethostname())
gigamem_per_node = 800
cpus_per_node = 30
if nworkers > 0
nodes = 1
nprocs_max = cpus_per_node * nodes
nworkers = min(nworkers, nprocs_max)
end
np = nworkers + 1
gigamem_per_cpu = Int(ceil(memory_usage_fraction * gigamem_per_node / cpus_per_node * cpus_per_task))
ENV["JULIA_WORKER_TIMEOUT"] = "360"
if Distributed.nprocs() < np
Distributed.addprocs(
ClusterManagers.SlurmManager(np - Distributed.nprocs());
partition="LocalQ",
topology=:master_worker,
time="99:99:99",
cpus_per_task,
exeflags=["--threads=$(cpus_per_task)", "--heap-size-hint=$(gigamem_per_cpu)G"],
kw...
)
end
else
error("Not running on feynman cluster")
end

elseif cluster == "localhost"
mem_size = Int(ceil(localhost_memory() * memory_usage_fraction))

Expand Down Expand Up @@ -298,4 +325,5 @@ struct MissingExtensionError <: Exception
package_name::String
end

Base.showerror(io::IO, e::MissingExtensionError) = print(io, "The FUSE actor $(e.actor_name) cannot be run because the Julia package $(e.package_name).jl is not loaded. Please load it to enable this feature.")
Base.showerror(io::IO, e::MissingExtensionError) =
print(io, "The FUSE actor $(e.actor_name) cannot be run because the Julia package $(e.package_name).jl is not loaded. Please load it to enable this feature.")
Loading

0 comments on commit 41ce14c

Please sign in to comment.