diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 146e3fc..cedfb69 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,8 +8,7 @@ on: - develop push: branches: - - main - - develop + - '**' tags: '*' jobs: test: diff --git a/Project.toml b/Project.toml index d6fc34c..dc0a7f2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,13 @@ name = "Capse" uuid = "994f66c3-d2c7-4ba6-88fb-4a10f50800ba" authors = ["marcobonici "] -version = "0.2.0" + +version = "0.2.1" [deps] AbstractCosmologicalEmulators = "c83c1981-e5c4-4837-9eb8-c9b1572acfc6" +Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" [compat] -AbstractCosmologicalEmulators = "0.3" +AbstractCosmologicalEmulators = "0.3.2" +Adapt = "3" diff --git a/README.md b/README.md index 48dee6a..6f4c36f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ ![size](https://img.shields.io/github/repo-size/CosmologicalEmulators/Capse.jl) -Repo containing the CMB Angular Power Spectrum Emulator (`Capse.jl`). +Repo containing the CMB Angular Power Spectrum Emulator, `Capse.jl`. + +`Capse.jl` is entirely written in `Julia`, but can be transparently called from `Python` using the [`pycapse`](https://github.com/CosmologicalEmulators/pycapse) wrapper. ## Citing diff --git a/docs/Project.toml b/docs/Project.toml index 071223e..635eb32 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,6 +1,5 @@ [deps] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" -Capse = "994f66c3-d2c7-4ba6-88fb-4a10f50800ba" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" diff --git a/docs/src/index.md b/docs/src/index.md index 0a6a3b6..587047f 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -10,6 +10,9 @@ default(palette = palette(:tab10)) benchmark = BenchmarkTools.load("./assets/capse_benchmark.json") path_json = "./assets/nn_setup.json" weights = rand(20000) +ℓgrid = ones(2000) +InMinMax_array = zeros(2,2000) +OutMinMax_array = zeros(2,2000) ``` `Capse.jl` is a Julia package designed to emulate the computation of the CMB Angular Power Spectrum, with a speedup of several orders of magnitude. @@ -43,8 +46,8 @@ After this, you just have to pass the `NN_dict` and the `weights` array to the ` In order to instantiate the emulator, just run -```julia -trained_emu = Capse.init_emulator(NN_dict, weights, Capse.SimpleChainsEmulator) +```@example tutorial +trained_emu = Capse.init_emulator(NN_dict, weights, Capse.SimpleChainsEmulator); ``` `SimpleChains.jl` is faster expecially for small NN on the CPU. If you prefer to use `Lux.jl`, pass as last argument `Capse.LuxEmulator`. @@ -54,7 +57,6 @@ Each trained emulator should be shipped with a description within the JSON file. ```@example tutorial Capse.get_emulator_description(NN_dict["emulator_description"]) ``` - After instantiating the NN, we need: - the ``\ell``-grid used to train the emulator, `ℓgrid` @@ -62,12 +64,18 @@ After instantiating the NN, we need: Now you can instantiate the emulator, using -```julia +```@example tutorial Cℓ_emu = Capse.CℓEmulator(TrainedEmulator = trained_emu, ℓgrid = ℓgrid, - InMinMax = InMinMax_array, OutMinMax = OutMinMax_array) + InMinMax = InMinMax_array, OutMinMax = OutMinMax_array); +``` + +Each trained emulator should be shipped with a description within the JSON file. In order to print the description, just runs: + +```@example tutorial +Capse.get_emulator_description(Cℓ_emu) ``` -After loading a trained `CℓTT_emu`, feed it some input parameters `x`. +After loading a trained emulator, feed it some input parameters `x` in order to get the emulated $C_\ell$'s ```julia x = rand(6) # generate some random input diff --git a/src/Capse.jl b/src/Capse.jl index b5cebc8..88546c1 100644 --- a/src/Capse.jl +++ b/src/Capse.jl @@ -1,7 +1,11 @@ module Capse using Base: @kwdef +using Adapt using AbstractCosmologicalEmulators +import AbstractCosmologicalEmulators.get_emulator_description + +export get_Cℓ, get_emulator_description abstract type AbstractCℓEmulators end @@ -14,19 +18,21 @@ It contains: - TrainedEmulator::AbstractTrainedEmulators, the trained emulator -- ℓgrid::Array, the ``\\ell``-grid the emulator has been trained on. +- ℓgrid::AbstractVector, the ``\\ell``-grid the emulator has been trained on. -- InMinMax::Matrix, the `Matrix` used for the MinMax normalization of the input features +- InMinMax::AbstractMatrix, the `Matrix` used for the MinMax normalization of the input features -- OutMinMax::Matrix, the `Matrix` used for the MinMax normalization of the output features +- OutMinMax::AbstractMatrix, the `Matrix` used for the MinMax normalization of the output features """ @kwdef mutable struct CℓEmulator <: AbstractCℓEmulators TrainedEmulator::AbstractTrainedEmulators - ℓgrid::Array - InMinMax::Matrix - OutMinMax::Matrix + ℓgrid::AbstractVector + InMinMax::AbstractMatrix + OutMinMax::AbstractMatrix end +Adapt.@adapt_structure CℓEmulator + """ get_Cℓ(CℓEmulator::AbstractCℓEmulators) Computes and returns the ``C_\\ell``on the ``\\ell``-grid the emulator has been trained on. @@ -47,4 +53,8 @@ function get_ℓgrid(CℓEmulator::AbstractCℓEmulators) return CℓEmulator.ℓgrid end +function get_emulator_description(Clemu::AbstractCℓEmulators) + get_emulator_description(Clemu.TrainedEmulator) +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 200a607..5a7491c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,4 +26,5 @@ capse_emu = Capse.CℓEmulator(TrainedEmulator = emu, ℓgrid=ℓ_test, InMinMax output_vec = Capse.get_Cℓ(cosmo_vec, capse_emu) @test isapprox(output_vec[:,1], output) @test ℓ_test == Capse.get_ℓgrid(capse_emu) + @test_logs (:warn, "We do not know which parameters were included in the emulators training space. Use this trained emulator with caution!") Capse.get_emulator_description(capse_emu) end