Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.12' # only supported version: Julia 1.13 needs a newer Reactant, which needs CUDA/cuDNN versions GraphNetCore 0.4 does not allow
- '1.12' # minimum supported (Octopus requires Julia ≥ 1.12; see Project.toml [compat])
- '1' # latest stable 1.x
steps:
- uses: actions/checkout@v7
- uses: julia-actions/setup-julia@v3
Expand Down
28 changes: 13 additions & 15 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GraphNetSim"
uuid = "5ff66f56-808c-48e7-ac84-dd29877231f8"
version = "0.3.0"
version = "0.4.0"
authors = ["Josef Jouaux <Josef.Kircher@uni-a.de>", "JT <julian.trommer@uni-a.de>"]

[deps]
Expand All @@ -12,7 +12,6 @@ ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
GraphNetCore = "7809f980-de1b-4f9a-8451-85f041491431"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Expand All @@ -25,9 +24,9 @@ MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
Octopus = "49bb3e92-56cb-4d34-aed6-8ee8ef58b458"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PointNeighbors = "1c4d5385-0a27-49de-8e2c-43b175c8985c"
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -44,42 +43,41 @@ cuDNN = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd"
Adapt = "4.3.0"
Aqua = "0.8"
CSV = "0.10.15"
CUDA = "5.9.6"
GPUCompiler = "~1.9"
CUDA = "6.2"
ChainRulesCore = "1.16.0 - 1"
ComponentArrays = "0.15"
DataFrames = "1.6"
DataInterpolations = "8.6.0"
DataInterpolations = "10"
Distributions = "0.25"
GraphNetCore = "0.4.2"
GraphNetCore = "0.5"
HDF5 = "0.17"
JLD2 = "0.6"
JSON = "0.21"
JSON = "1"
JuliaFormatter = "~2.2"
KernelAbstractions = "0.9.39"
LightXML = "0.9"
Lux = "1.13 - 1"
LuxCUDA = "0.3"
MLUtils = "0.4.4 - 0.4"
Octopus = "0.2"
Octopus = "0.2.2"
Optimisers = "0.4, 1"
OrdinaryDiffEq = "6.85 - 6"
OrdinaryDiffEq = "7"
OrdinaryDiffEqLowOrderRK = "2.2.6"
Plots = "1.40.18"
PointNeighbors = "0.6.3"
PreallocationTools = "0.4.34"
Printf = "1"
ProgressMeter = "1.7.0 - 1"
Random = "1"
ReadVTK = "0.2.6"
RecursiveArrayTools = "3.36.0"
SciMLBase = "2.7.0 - 2"
RecursiveArrayTools = "4"
SciMLBase = "3"
SciMLSensitivity = "7.76 - 7"
Setfield = "1.1.2"
Statistics = "1"
Test = "1"
Zygote = "0.6, 0.7"
cuDNN = "1.4 - 1"
julia = "~1.12"
cuDNN = "6.2"
julia = "1.12"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ The package is build upon [**GraphNetCore.jl**](https://github.com/una-auxme/Gra

## Requirements

- **Julia 1.12** (Julia 1.13 is not supported yet; it needs dependency versions that GraphNetCore v0.4 does not allow)
- Built on [GraphNetCore.jl](https://github.com/una-auxme/GraphNetCore.jl) **v0.4**, which uses a
- **Julia ≥ 1.12**
- Built on [GraphNetCore.jl](https://github.com/una-auxme/GraphNetCore.jl) **v0.5**, which uses a
[Lux.jl](https://github.com/LuxDL/Lux.jl) `TrainState` and pulls in a CUDA-capable stack.
- A CUDA-capable GPU is recommended for training (falls back to CPU when CUDA is unavailable).

Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ GraphNetSim = "5ff66f56-808c-48e7-ac84-dd29877231f8"
Optuna = "a5d0552b-b2dc-4f08-ac5c-85ca7d701b92"

[compat]
julia = "~1.12"
julia = "1.12"
2 changes: 1 addition & 1 deletion example/BallisticSmall/BallisticSmall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using GraphNetSim

import OrdinaryDiffEq: Euler, Tsit5
import OrdinaryDiffEq: Tsit5
import Optimisers: Adam

# Generate dataset into data/ballistic_small if not already present
Expand Down
3 changes: 2 additions & 1 deletion example/DamBreakSmall/DamBreakSmall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

using GraphNetSim

import OrdinaryDiffEq: Euler, Tsit5
import OrdinaryDiffEq: Tsit5
import OrdinaryDiffEqLowOrderRK: Euler
import Optimisers: Adam

# Generate dataset into data/dam_break_small if not already present
Expand Down
12 changes: 6 additions & 6 deletions example/DamBreakSmall/DamBreakSmall_optuna.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using GraphNetSim
using Optuna
import OrdinaryDiffEq: Euler
import OrdinaryDiffEqLowOrderRK: Euler
import Optimisers: Adam, AdamW, RAdam

# ── Dataset setup ────────────────────────────────────────────────────────
Expand All @@ -39,11 +39,8 @@ end

ds_path = "data/dam_break_small"

# Precompute both normalization statistics (reusable across trials).
# `update_meta!` writes one statistic type per call, so run both — the trial
# then selects between them via `norm_type` (:minmax / :meanstd).
update_meta!(ds_path, :minmax)
update_meta!(ds_path, :meanstd)
# Normalization statistics are written per trial (see `objective`): `update_meta!`
# keeps only one statistic type in meta.json at a time, removing the other.

# ── Fixed training parameters ────────────────────────────────────────────

Expand Down Expand Up @@ -93,6 +90,9 @@ function objective(trial::Trial; params)

lr_stop = params[:lr] * params[:lr_decay_ratio]

# Write the statistics this trial's norm_type needs; update_meta! drops the other type.
update_meta!(ds_path, params[:norm_type])

min_val_loss = train_network(
opt,
ds_path,
Expand Down
8 changes: 7 additions & 1 deletion example/DamBreakSmall/Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[deps]
GraphNetSim = "5ff66f56-808c-48e7-ac84-dd29877231f8"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
Optuna = "a5d0552b-b2dc-4f08-ac5c-85ca7d701b92"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"

[sources.GraphNetSim]
path = "../.."

[compat]
HDF5 = "0.17"
JSON = "1"
Optimisers = "0.4, 1"
Optuna = "0.2.1"
OrdinaryDiffEq = "6.85 - 6"
OrdinaryDiffEq = "7"
OrdinaryDiffEqLowOrderRK = "2.2.6"
32 changes: 14 additions & 18 deletions src/GraphNetSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ using Plots
import SciMLBase: ODEProblem, SecondOrderODEProblem
# Newer OrdinaryDiffEq relocated `OrdinaryDiffEqAlgorithm` into its OrdinaryDiffEqCore
# subpackage; alias it back to the original name so solver-type signatures stay unchanged.
import OrdinaryDiffEq: OrdinaryDiffEqCore, Tsit5, Euler
import OrdinaryDiffEq: OrdinaryDiffEqCore, Tsit5
import OrdinaryDiffEqLowOrderRK: Euler
const OrdinaryDiffEqAlgorithm = OrdinaryDiffEqCore.OrdinaryDiffEqAlgorithm
import ProgressMeter: Progress

Expand Down Expand Up @@ -408,7 +409,7 @@ function calc_norms(dataset, device, args)
return quantities, e_norms, n_norms, o_norms
end

# Bridge between GraphNetCore.load()'s 2-col df_step (step, loss) and the
# Bridge between GraphNetCore.load_checkpoint()'s 2-col df_step (step, loss) and the
# 3-col schema (step, interval_idx, loss). Idempotent: 3-col input is left
# unchanged. Legacy 2-col rows preserve their original interval indices in
# `interval_idx`; `step` is rebuilt as a monotonic 1:N counter so historical
Expand Down Expand Up @@ -560,9 +561,9 @@ function train_network(opt, ds_path, cp_path; kws...)
outputs += ds_train.meta["features"][tf]["dim"]
end

# GraphNetCore >= 0.4: load() returns (gns, df_train, df_valid). The optimiser
# load_checkpoint() returns (gns, df_train, df_valid). The optimiser
# state now lives inside gns.train_state (df_step was dropped upstream).
gns, df_train, df_valid = load(
gns, df_train, df_valid = load_checkpoint(
quantities,
typeof(dims) <: AbstractArray ? length(dims) : dims,
e_norms,
Expand All @@ -577,12 +578,6 @@ function train_network(opt, ds_path, cp_path; kws...)
cp_path,
) # geht mit dims oder dimensions of array

# The optimiser state lives inside `gns.train_state` (populated on a fresh start by the
# TrainState constructor, restored on resume). On resume GraphNetCore loads it from the
# (CPU) checkpoint without moving it to the device, so re-`device` it in place here to keep
# it co-located with the (GPU) parameters.
@set! gns.train_state.optimizer_state = device(gns.train_state.optimizer_state)

Lux.trainmode(gns.train_state.states)

@info "Model built!"
Expand Down Expand Up @@ -938,12 +933,13 @@ function train_gns!(
_restore_online_normalisers!(frozen_state)
end

# GraphNetCore >= 0.4: save! no longer appends to df_valid, so record
# the validation loss here (once per checkpoint).
# GraphNetCore >= 0.4: save_checkpoint! (save! before 0.5) does not
# append to df_valid, so record the validation loss here (once per
# checkpoint).
push!(df_valid, [step, valid_error / ds_valid.meta["n_trajectories"]])

if valid_error / ds_valid.meta["n_trajectories"] < min_validation_loss
save!(
save_checkpoint!(
gns,
gns.train_state.optimizer_state,
df_train,
Expand All @@ -966,7 +962,7 @@ function train_gns!(
println(" min_validation_loss: $min_validation_loss")
println(" last_validation_loss: $last_validation_loss")
end
save!(
save_checkpoint!(
gns, gns.train_state.optimizer_state, df_train, df_valid, step, cp_path
)
avg_loss = 0.0f0
Expand Down Expand Up @@ -1102,7 +1098,7 @@ function eval_network(
outputs += ds_test.meta["features"][tf]["dim"]
end

gns, _, _ = load(
gns, _, _ = load_checkpoint(
quantities,
typeof(dims) <: AbstractArray ? length(dims) : dims,
e_norms,
Expand All @@ -1112,7 +1108,7 @@ function eval_network(
args.mps,
args.layer_size,
args.hidden_layers,
# v0.4 load() builds a Lux TrainState that requires a real optimiser even for
# load_checkpoint() builds a Lux TrainState that requires a real optimiser even for
# eval/extrapolate (its optimiser state is unused here); pass a throwaway Adam.
Optimisers.Adam(),
device,
Expand Down Expand Up @@ -1432,7 +1428,7 @@ function extrapolate_network(
outputs += ds_test.meta["features"][tf]["dim"]
end

gns, _, _ = load(
gns, _, _ = load_checkpoint(
quantities,
typeof(dims) <: AbstractArray ? length(dims) : dims,
e_norms,
Expand All @@ -1442,7 +1438,7 @@ function extrapolate_network(
args.mps,
args.layer_size,
args.hidden_layers,
# v0.4 load() builds a Lux TrainState that requires a real optimiser even for
# load_checkpoint() builds a Lux TrainState that requires a real optimiser even for
# eval/extrapolate (its optimiser state is unused here); pass a throwaway Adam.
Optimisers.Adam(),
device,
Expand Down
2 changes: 1 addition & 1 deletion src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function load_model_config(cp_path::String)::Union{ModelConfig,Nothing}
isfile(path) || return nothing

try
d = json_parsefile(path)
d = json_parsefile(path; dicttype=Dict{String,Any})
arch = d["architecture"]
train = d["training"]
return ModelConfig(;
Expand Down
4 changes: 2 additions & 2 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function Dataset(datafile::String, metafile::String, args)
)
end

meta = parse(Base.read(metafile, String))
meta = parse(Base.read(metafile, String); dicttype=Dict{String,Any})
keys_traj = keystraj(datafile)
meta["n_trajectories"] = length(keys_traj)
meta["keys_trajectories"] = keys_traj
Expand Down Expand Up @@ -135,7 +135,7 @@ function Dataset(split::Symbol, path::String, args)
)
end

meta = parse(Base.read(joinpath(path, "meta.json"), String))
meta = parse(Base.read(joinpath(path, "meta.json"), String); dicttype=Dict{String,Any})
datafile = get_file(split, path)
keys_traj = keystraj(datafile)
meta["n_trajectories"] = length(keys_traj)
Expand Down
2 changes: 1 addition & 1 deletion src/import_data/vtkToh5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ function _install_provided_meta(meta_path::AbstractString, output::AbstractStrin
dest = joinpath(dirname(abspath(output)), "meta.json")
# Light structural check: every dynamic feature key `X[$t]` must have `X[1]`
# in the written file, every static feature key must exist.
m = JSON.parsefile(meta_path)
m = JSON.parsefile(meta_path; dicttype=Dict{String,Any})
h5open(output, "r") do fid
g = fid[first(keys(fid))]
for (fn, spec) in get(m, "features", Dict())
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ function update_meta!(path::String, norm_type::Symbol)
return meta_path
end

meta = json_parsefile(meta_path)
meta = json_parsefile(meta_path; dicttype=Dict{String,Any})

conflicting_minmax = ("data_min", "data_max", "output_min", "output_max")
conflicting_meanstd = ("data_mean", "data_std")
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"
PointNeighbors = "1c4d5385-0a27-49de-8e2c-43b175c8985c"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
6 changes: 1 addition & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ include("generate_fixtures.jl")
@testset "Method ambiguity" begin
Aqua.test_ambiguities([GraphNetSim])
end
# Deps that are intentionally not `import`ed from src/, so exclude them from the
# stale-deps check:
# - GPUCompiler: deps-only version pin (see Project.toml [compat]), loaded
# transitively via CUDA/Reactant.
Aqua.test_all(GraphNetSim; ambiguities=false, stale_deps=(ignore=[:GPUCompiler],))
Aqua.test_all(GraphNetSim; ambiguities=false)
end

include("test_converters.jl")
Expand Down
6 changes: 4 additions & 2 deletions test/test_converters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ end
pvd = _make_vtk_dataset(dir; T=5, with_acc=true)
out = joinpath(dir, "train.h5")
vtk_to_hdf5(pvd, out; write_meta=true, connectivity_radius=0.5)
meta = JSON.parsefile(joinpath(dir, "meta.json"))
meta = JSON.parsefile(joinpath(dir, "meta.json"); dicttype=Dict{String,Any})
@test meta["dims"] == 3
@test meta["trajectory_length"] == 5
@test Set(meta["feature_names"]) ==
Expand All @@ -272,7 +272,9 @@ end
out = joinpath(outdir, "train.h5")
vtk_to_hdf5(pvd, out; meta=provided)
@test isfile(joinpath(outdir, "meta.json"))
@test JSON.parsefile(joinpath(outdir, "meta.json"))["dims"] == 3
@test JSON.parsefile(
joinpath(outdir, "meta.json"); dicttype=Dict{String,Any}
)["dims"] == 3
end
end

Expand Down
Loading
Loading