Skip to content

Commit

Permalink
Fix windows test failures (#262)
Browse files Browse the repository at this point in the history
* dummy push to check current test success on windows

* update test pipeline to v1

* syntax

* info

* Project.toml

* info statements

* Pycall version wasnt issue

* see if issue is in fit! or just calling the pycall object

* try noise_learn false

* add MWE at start of Emulator testing

* typo, remove noise_learn = false

* trim MWE

* escapes

* update python packages

* update python packages for lin/mac

* update 1.1.1 -> 1.3.2

* format

* update init

* try update test versions

* try resolve syntax error?

* try resolve syntax error?

* try resolve syntax error?

* indent

* update versions of some actions, and checkout actions@main

* rm info statements

* rm info

* test 1.5.1

* rm / change info statements
  • Loading branch information
odunbar authored Dec 2, 2024
1 parent 182d574 commit a39e67a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 38 deletions.
42 changes: 20 additions & 22 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
name: Tests

on:
pull_request:
push:
tags: '*'

on: [push]
jobs:
test-linux:
test-linux-v1:
name: test-linux-v1
timeout-minutes: 60
strategy:
fail-fast: true
Expand All @@ -15,17 +11,17 @@ jobs:

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.8.0
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@main

- name: Set up Julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: 1
version: '1'

- name: Install Julia Project Packages
# we add this ENV varaible to force PyCall to download and use Conda rather than
Expand Down Expand Up @@ -56,12 +52,13 @@ jobs:
if: success()

- name: Submit coverage
uses: codecov/codecov-action@v1.0.7
uses: codecov/codecov-action@v5
with:
token: ${{secrets.CODECOV_TOKEN}}
if: success()

test-macos:
test-macos-v1:
name: test-macos-v1
timeout-minutes: 60
strategy:
fail-fast: true
Expand All @@ -70,18 +67,18 @@ jobs:

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.8.0
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@main

- name: Set up Julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: 1.9.0
# later versions causes hanging in package building
version: 1

- name: Install Julia Project Packages
env:
PYTHON: ""
Expand All @@ -101,7 +98,8 @@ jobs:
run: |
LD_LIBRARY_PATH=$HOME/.julia/conda/3/lib julia --project -e 'using Pkg; Pkg.test()'
test-windows:
test-windows-v1:
name: test-windows-v1
timeout-minutes: 60
strategy:
fail-fast: true
Expand All @@ -110,15 +108,15 @@ jobs:

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.8.0
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@main

- name: Set up Julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: 1

Expand Down
2 changes: 1 addition & 1 deletion src/Emulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function Emulator(

training_pairs = PairedDataContainer(training_inputs, decorrelated_training_outputs)
# [4.] build an emulator

build_models!(machine_learning_tool, training_pairs)
else
if decorrelate || !isa(machine_learning_tool, VectorRandomFeatureInterface)
Expand All @@ -160,7 +161,6 @@ function Emulator(
build_models!(machine_learning_tool, training_pairs, regularization_matrix = obs_noise_cov)
end


return Emulator{FT}(
machine_learning_tool,
training_pairs,
Expand Down
15 changes: 5 additions & 10 deletions src/GaussianProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ using ScikitLearn
const pykernels = PyNULL()
const pyGP = PyNULL()
function __init__()
copy!(pykernels, pyimport_conda("sklearn.gaussian_process.kernels", "scikit-learn=1.1.1"))
copy!(pyGP, pyimport_conda("sklearn.gaussian_process", "scikit-learn=1.1.1"))
copy!(pykernels, pyimport_conda("sklearn.gaussian_process.kernels", "scikit-learn=1.5.1"))
copy!(pyGP, pyimport_conda("sklearn.gaussian_process", "scikit-learn=1.5.1"))
end

#exports (from Emulator)
Expand Down Expand Up @@ -260,25 +260,20 @@ function build_models!(
kern = kern + white
println("Learning additive white noise")
end

regularization_noise = gp.alg_reg_noise

for i in 1:N_models
kernel_i = deepcopy(kern)
data_i = output_values[i, :]
m = pyGP.GaussianProcessRegressor(kernel = kernel_i, n_restarts_optimizer = 10, alpha = regularization_noise)

# ScikitLearn.fit! arguments:
# input_values: (N_samples × input_dim)
# data_i: (N_samples,)

@info("Training kernel $(i), ")
ScikitLearn.fit!(m, input_values, data_i)
if i == 1
println(m.kernel.hyperparameters)
print("Completed training of: ")
end
println(i, ", ")
push!(models, m)
println(m.kernel)
@info(m.kernel)
end
end

Expand Down
29 changes: 29 additions & 0 deletions test/Emulator/MWE.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using PyCall
using ScikitLearn
const pykernels = PyNULL()
const pyGP = PyNULL()

function init()
copy!(pykernels, pyimport_conda("sklearn.gaussian_process.kernels", "scikit-learn=1.3.2"))
copy!(pyGP, pyimport_conda("sklearn.gaussian_process", "scikit-learn=1.3.2"))
end

function minimal_failing_example()
# some kind of kernel
kernel = pykernels.ConstantKernel(constant_value = 1.0)

# some data
n = 20 # number of training points
x = reshape(2.0 * π * rand(n), 1, n) # predictors/features: 1 x n
y = reshape(sin.(x) + 0.05 * randn(n)', 1, n) # predictands/targets: 1 x n

# the model
m = pyGP.GaussianProcessRegressor(kernel = kernel)

# call fit!
ScikitLearn.fit!(m, x, y)
@info "fit successful"
end

init()
minimal_failing_example()
2 changes: 2 additions & 0 deletions test/Emulator/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include("MWE.jl")

# Import modules
using Random
using Test
Expand Down
6 changes: 1 addition & 5 deletions test/GaussianProcess/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using LinearAlgebra
using PyCall
using ScikitLearn
const pykernels = PyNULL()
copy!(pykernels, pyimport_conda("sklearn.gaussian_process.kernels", "scikit-learn=1.1.1"))
copy!(pykernels, pyimport_conda("sklearn.gaussian_process.kernels", "scikit-learn=1.5.1"))


using CalibrateEmulateSample.Emulators
Expand Down Expand Up @@ -127,9 +127,7 @@ using CalibrateEmulateSample.DataContainers
se = pykernels.RBF(1.0)
GPkernel = var * se


gp3 = GaussianProcess(gppackage; kernel = GPkernel, noise_learn = true, prediction_type = pred_type)

em3 = Emulator(
gp3,
iopairs,
Expand All @@ -138,7 +136,6 @@ using CalibrateEmulateSample.DataContainers
standardize_outputs = false,
retained_svd_frac = 1.0,
)

@test_logs (:warn,) (:warn,) Emulator(
gp3,
iopairs,
Expand All @@ -159,7 +156,6 @@ using CalibrateEmulateSample.DataContainers

Emulators.optimize_hyperparameters!(em3)


#gp3 = GaussianProcess(iopairs, gppackage; GPkernel=GPkernel, obs_noise_cov=nothing,
# normalized=false, noise_learn=true,
# retained_svd_frac=1.0, standardize=false,
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if TEST_PLOT_OUTPUT
using Plots
end


function include_test(_module)
println("Starting tests for $_module")
t = @elapsed include(joinpath(_module, "runtests.jl"))
Expand Down

0 comments on commit a39e67a

Please sign in to comment.