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

WIP: New JSON Interface #231

Merged
merged 20 commits into from
Sep 10, 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
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.8.0-dev"

[deps]
ACEfit = "ad31a8ef-59f5-4a01-b543-a85c2f73e95c"
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
AtomsBuilder = "f5cc8831-eeb7-4288-8d9f-d6c1ddb77004"
AtomsCalculators = "a3e0e189-c65a-42c1-833c-339540406eb1"
Expand All @@ -17,13 +18,15 @@ ExtXYZ = "352459e4-ddd7-4360-8937-99dcb397b478"
Folds = "41a02a25-b8f0-4f67-bc48-60067656b558"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
LuxCore = "bb33d45b-7691-41d6-9220-0943567d0623"
NamedTupleTools = "d9ec5142-1e00-5aa0-9d6a-321866360f50"
NeighbourLists = "2fcf5ba9-9ed4-57cf-b73f-ff513e316b9c"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand Down
65 changes: 0 additions & 65 deletions scripts/ace_fit.jl

This file was deleted.

81 changes: 0 additions & 81 deletions scripts/acefit.jl

This file was deleted.

69 changes: 69 additions & 0 deletions scripts/example_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"model": {
"model_name": "ACE1",
"pair_basis": "legendre",
"elements": [
"Si"
],
"pair_rin": 0.0,
"pure": false,
"pair_transform": [
"agnesi",
1,
3
],
"totaldegree": 10,
"delete2b": false,
"wL": 1.5,
"pair_degree": 10,
"rbasis": "legendre",
"pure2b": false,
"pair_rcut": 6.7,
"rcut": 6.7,
"variable_cutoffs": false,
"rin": 0.0,
"order": 3,
"r0": 2.5,
"transform": [
"agnesi",
2,
4
]
},
"solve": {
"weights": {
"FLD_TiAl": {
"V": 1.0,
"E": 30.0,
"F": 1.0
},
"TiAl_T5000": {
"V": 1.0,
"E": 5.0,
"F": 1.0
}
},
"prior": {
"name": "algebraic",
"param": 4
},
"solver": {
"name": "BLR",
"param": {
"factorization": "svd",
"committee_size": 20
}
}
},
"data": {
"train_file": "Si_tiny.xyz",
"force_key": "dft_force",
"test_file": "Si_tiny.xyz",
"energy_key": "dft_energy",
"virial_key": "dft_virial"
},
"output": {
"model": "results.json"
}
}

24 changes: 0 additions & 24 deletions scripts/generate_artifacts.jl

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/plotRn/Project.toml

This file was deleted.

64 changes: 64 additions & 0 deletions scripts/runfit.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# julia --project=. runfit.jl -p example_params.json
#

using ACEpotentials
using ACEpotentials: JSON, ExtXYZ
using ACEpotentials.ArgParse: ArgParseSettings, @add_arg_table, parse_args

parser = ArgParseSettings(description="Fit an ACE potential from parameters file")

@add_arg_table parser begin
"--params", "-p"
help = "A JSON or YAML filename with parameters for the fit"
"--dry-run"
help = "Only quickly compute various sizes, etc"
action = :store_true
"--num-blas-threads"
help = "Number of processes for BLAS to use when solving the LsqDB"
arg_type = Int
default = 1
end

# parse the command
args = parse_args(parser)

@info("Load parameter file")
args_dict = JSON.parsefile(args["params"])

@info("Construct ACEmodel of type $(args_dict["model"]["model_name"])")
model = ACEpotentials.make_model(args_dict["model"])

@info("Load datasets")
train = ExtXYZ.load(args_dict["data"]["train_file"])

data_keys = (
force_key = args_dict["data"]["force_key"],
energy_key = args_dict["data"]["energy_key"],
virial_key = args_dict["data"]["virial_key"])

weights = args_dict["solve"]["weights"]

solver = ACEpotentials.make_solver(args_dict["solve"]["solver"])

# TODO: make prior

acefit!(train, model;
data_keys..., weights = weights, solver = solver)

# training errors
err_train = ACEpotentials.linear_errors(train, model; data_keys..., weights=weights)
err = Dict("train" => err_train)

# test errors (if a test dataset exists)
if haskey(args_dict["data"], "test_file")
test = ExtXYZ.load(args_dict["data"]["test_file"])
err_test = ACEpotentials.linear_errors(test, model; data_keys..., weights=weights)
err["test"] = err_test
end

# saving results
result_file = args_dict["output"]["model"]
ACEpotentials.save_model(model, joinpath(@__DIR__(), args_dict["output"]["model"]);
make_model_args = args_dict,
errors = err, )
6 changes: 6 additions & 0 deletions src/ACEpotentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import ACEpotentials.Models: algebraic_smoothness_prior,
exp_smoothness_prior,
gaussian_smoothness_prior,
set_parameters!
import JSON

export ace1_model,
length_basis,
Expand All @@ -49,4 +50,9 @@ export ace1_model,
gaussian_smoothness_prior,
set_parameters!


include("json_interface.jl")



end
1 change: 0 additions & 1 deletion src/ace1_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,3 @@ end

end


Loading
Loading