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

Add tests for varying parameter fits/optimisations #93

Open
BradyPlanden opened this issue Nov 13, 2023 · 1 comment
Open

Add tests for varying parameter fits/optimisations #93

BradyPlanden opened this issue Nov 13, 2023 · 1 comment
Labels
enhancement New feature or request priority:high

Comments

@BradyPlanden
Copy link
Member

Feature description

Provides better coverage for the challenges in optimisation a cost function for differing parameter types. A good example of this is add geometric parameters into our current fitting API (see #18):

import pybop
import numpy as np

parameter_set = pybop.ParameterSet("pybamm", "Chen2020")
model = pybop.lithium_ion.SPMe(parameter_set=parameter_set)

# Fitting parameters
parameters = [
    pybop.Parameter(
        "Positive particle radius [m]",
        prior=pybop.Gaussian(1e-6, 0.0),
        bounds=[0.999e-6, 1.0001e-6],
    ),
    pybop.Parameter(
        "Positive electrode diffusivity [m2.s-1]",
        prior=pybop.Gaussian(3.43e-15, 1e-15),
        bounds=[1e-15, 5e-15],
    ),
]

sigma = 0.001
t_eval = np.arange(0, 900, 2)
values = model.predict(t_eval=t_eval)
corrupt_voltage = values["Terminal voltage [V]"].data + np.random.normal(
    0, sigma, len(t_eval)
)

dataset = [
    pybop.Dataset("Time [s]", t_eval),
    pybop.Dataset("Current function [A]", values["Current [A]"].data),
    pybop.Dataset("Terminal voltage [V]", corrupt_voltage),
]

# Generate problem, cost function, and optimisation class
problem = pybop.Problem(model, parameters, dataset)
cost = pybop.SumSquaredError(problem)
optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent)
optim.optimiser.set_learning_rate(0.025)

x, final_cost = optim.run()
print("Estimated parameters:", x)

This results in non-scalar geometric parameter when building the PyBaMM model. While we are capturing this issue in #18, adding a larger variety of fitting/optimisation tests will help us check potential edge-cases.

Motivation

No response

Possible implementation

No response

Additional context

No response

@BradyPlanden BradyPlanden added the enhancement New feature or request label Nov 13, 2023
@BradyPlanden
Copy link
Member Author

Updating priority on this issue, a move towards diversifying our test suite would be very welcome. This can be done by updating the parameter identification tests we currently have, or by adding an additional test that iterates over a list of parameters to identify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority:high
Projects
None yet
Development

No branches or pull requests

1 participant