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

Remove RMSE function #3988

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions docs/source/api/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Utility functions

.. autofunction:: pybamm.get_git_commit_info

.. autofunction:: pybamm.rmse

.. autofunction:: pybamm.root_dir

.. autoclass:: pybamm.Timer
Expand Down
84 changes: 15 additions & 69 deletions pybamm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
import sys
import os


#
# Version info
#
from pybamm.version import __version__

#
# Constants
#
# Float format: a float can be converted to a 17 digit decimal and back without
# loss of information
FLOAT_FORMAT = "{: .17e}"
# Absolute path to the PyBaMM repo
script_path = os.path.abspath(__file__)

from .util import root_dir

ABSOLUTE_PATH = root_dir()
PARAMETER_PATH = [
root_dir(),
os.getcwd(),
os.path.join(root_dir(), "pybamm", "input", "parameters"),
]


#
# Utility classes and methods
#
from .util import Timer, TimerTime, FuzzyDict
from .util import (
root_dir,
rmse,
load,
is_constant_and_can_evaluate,
)
Expand All @@ -48,9 +23,6 @@
from .settings import settings
from .citations import Citations, citations, print_citations

#
# Classes for the Expression Tree
#
from .expression_tree.symbol import *
from .expression_tree.binary_operators import *
from .expression_tree.concatenations import *
Expand All @@ -73,7 +45,6 @@

from .expression_tree.exceptions import *

# Operations
from .expression_tree.operations.evaluate_python import (
find_symbols,
id_to_python_variable,
Expand All @@ -88,14 +59,10 @@
from .expression_tree.operations.convert_to_casadi import CasadiConverter
from .expression_tree.operations.unpack_symbols import SymbolUnpacker

#
# Model classes
#
from .models.base_model import BaseModel
from .models.event import Event
from .models.event import EventType

# Battery models
from .models.full_battery_models.base_battery_model import (
BaseBatteryModel,
BatteryModelOptions,
Expand All @@ -104,9 +71,6 @@
from .models.full_battery_models import lithium_ion
from .models.full_battery_models import equivalent_circuit

#
# Submodel classes
#
from .models.submodels.base_submodel import BaseSubModel

from .models.submodels import (
Expand All @@ -132,18 +96,12 @@
from .models.submodels.interface import interface_utilisation
from .models.submodels.interface import open_circuit_potential

#
# Geometry
#
from .geometry.geometry import Geometry
from .geometry.battery_geometry import battery_geometry

from .expression_tree.independent_variable import KNOWN_COORD_SYS
from .geometry import standard_spatial_vars

#
# Parameter classes and methods
#
from .parameters.parameter_values import ParameterValues
from .parameters import constants
from .parameters.geometric_parameters import geometric_parameters, GeometricParameters
Expand All @@ -158,9 +116,6 @@
from .parameters.size_distribution_parameters import *
from .parameters.parameter_sets import parameter_sets

#
# Mesh and Discretisation classes
#
from .discretisations.discretisation import Discretisation
from .discretisations.discretisation import has_bc_of_form
from .meshes.meshes import Mesh, SubMesh, MeshGenerator
Expand All @@ -181,23 +136,14 @@
UserSupplied2DSubMesh,
)

#
# Serialisation
#
from .models.base_model import load_model

#
# Spatial Methods
#
from .spatial_methods.spatial_method import SpatialMethod
from .spatial_methods.zero_dimensional_method import ZeroDimensionalSpatialMethod
from .spatial_methods.finite_volume import FiniteVolume
from .spatial_methods.spectral_volume import SpectralVolume
from .spatial_methods.scikit_finite_element import ScikitFiniteElement

#
# Solver classes
#
from .solvers.solution import Solution, EmptySolution, make_cycle_solution
from .solvers.processed_variable import ProcessedVariable
from .solvers.processed_variable_computed import ProcessedVariableComputed
Expand All @@ -214,38 +160,38 @@
from .solvers.idaklu_jax import IDAKLUJax
from .solvers.idaklu_solver import IDAKLUSolver, have_idaklu

#
# Experiments
#
from .experiment.experiment import Experiment
from . import experiment
from .experiment import step


#
# Plotting
#
from .plotting.quick_plot import QuickPlot, close_plots, QuickPlotAxes
from .plotting.plot import plot
from .plotting.plot2D import plot2D
from .plotting.plot_voltage_components import plot_voltage_components
from .plotting.plot_summary_variables import plot_summary_variables
from .plotting.dynamic_plot import dynamic_plot

#
# Simulation
#
from .simulation import Simulation, load_sim, is_notebook

#
# Batch Study
#
from .batch_study import BatchStudy

from . import callbacks

#
# Callbacks
# Constants
#
from . import callbacks
# Float format: a float can be converted to a 17 digit decimal and back without
# loss of information
FLOAT_FORMAT = "{: .17e}"
# Absolute path to the PyBaMM repo
script_path = os.path.abspath(__file__)

ABSOLUTE_PATH = root_dir()
PARAMETER_PATH = [
root_dir(),
os.getcwd(),
os.path.join(root_dir(), "pybamm", "input", "parameters"),
]
kratman marked this conversation as resolved.
Show resolved Hide resolved

#
# Remove any imported modules, so we don't expose them as part of pybamm
Expand Down
11 changes: 0 additions & 11 deletions pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import difflib
from warnings import warn

import numpy as np
import pybamm

# Versions of jax and jaxlib compatible with PyBaMM. Note: these are also defined in
Expand Down Expand Up @@ -244,16 +243,6 @@ def __eq__(self, other):
return self.value == other.value


def rmse(x, y):
"""
Calculate the root-mean-square-error between two vectors x and y, ignoring NaNs
"""
# Check lengths
if len(x) != len(y):
raise ValueError("Vectors must have the same length")
return np.sqrt(np.nanmean((x - y) ** 2))


def load(filename):
"""Load a saved object"""
with open(filename, "rb") as f:
Expand Down
18 changes: 2 additions & 16 deletions tests/unit/test_util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#
# Tests the utility functions.
#
import importlib
from tests import TestCase
import numpy as np
import os
import sys
import pybamm
Expand All @@ -24,17 +20,6 @@ class TestUtil(TestCase):
Test the functionality in util.py
"""

def test_rmse(self):
self.assertEqual(pybamm.rmse(np.ones(5), np.zeros(5)), 1)
self.assertEqual(pybamm.rmse(2 * np.ones(5), np.zeros(5)), 2)
self.assertEqual(pybamm.rmse(2 * np.ones(5), np.ones(5)), 1)

x = np.array([1, 2, 3, 4, 5])
self.assertEqual(pybamm.rmse(x, x), 0)

with self.assertRaisesRegex(ValueError, "same length"):
pybamm.rmse(np.ones(5), np.zeros(3))

def test_is_constant_and_can_evaluate(self):
symbol = pybamm.PrimaryBroadcast(0, "negative electrode")
self.assertEqual(False, pybamm.is_constant_and_can_evaluate(symbol))
Expand Down Expand Up @@ -165,7 +150,8 @@ def test_optional_dependencies(self):
self.assertFalse(
bool(optional_present_deps),
f"Optional dependencies installed: {optional_present_deps}.\n"
"Please ensure that optional dependencies are not present in the core PyBaMM installation, or list them as required.",
"Please ensure that optional dependencies are not present in the core PyBaMM installation, "
"or list them as required.",
)


Expand Down
Loading