Skip to content

Commit

Permalink
Merge pull request #784 from gchq/feature/deprecation-removals-v0.3.0
Browse files Browse the repository at this point in the history
Deprecation removals for v0.3.0
  • Loading branch information
pc532627 authored Oct 3, 2024
2 parents b042b34 + 09aca34 commit 093f3d1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 107 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ disable tqdm progress bar terminal output. Defaults to disabled (`False`).

### Removed


- `coreax.weights.MMD` - deprecated alias for `coreax.weights.MMDWeightsOptimiser`; deprecated since version 0.2.0.
- `coreax.weights.SBQ` - deprecated alias for `coreax.weights.SBQWeightsOptimiser`; deprecated since version 0.2.0.
- `coreax.util.squared_distance_pairwise` - deprecated alias for `coreax.util.pairwise(squared_distance)`; deprecated since version 0.2.0.
- `coreax.util.pairwise_difference` - deprecated alias for `coreax.util.pairwise(difference)`; deprecated since version 0.2.0.

### Deprecated
- All uses of `coreax.kernel.Kernel` should be replaced with `coreax.kernels.base.ScalarValuedKernel`.
Expand Down
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ or class entirely, the deprecation period must instead be at least **two minor r
or two months (whichever is longer).**

Ensure that during the deprecation period, the old behaviour still works, but raises a
`DeprecationWarning` with an appropriate message. If at all possible, ensure that there
`DeprecationWarning` with an appropriate message (which should include which version
the behaviour is deprecated since, and which version the deprecated behaviour is
expected to be removed in). If at all possible, ensure that there
is straightforward signposting for how users should change their code to use
non-deprecated parts of the codebase instead.

Expand All @@ -112,7 +114,10 @@ def my_old_function(x: int) -> int:
def my_new_function(x: int) -> int:
return x*4

@deprecated("Renamed to my_new_function; will be removed in v0.3.0")
@deprecated(
"Renamed to my_new_function."
+ " Deprecated since v0.2.0; will be removed in v0.3.0."
)
def my_old_function(x: int) -> int:
return my_new_function(x)

Expand Down
109 changes: 63 additions & 46 deletions coreax/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,184 +71,201 @@

# pylint:disable = abstract-method
@deprecated(
"Renamed to `ScalarValuedKernel`; "
+ " moved to `coreax.kernels.base.ScalarValuedKernel`; "
+ " will be removed in version 0.3.0"
"Renamed to `ScalarValuedKernel`;"
+ " moved to `coreax.kernels.base.ScalarValuedKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class Kernel(_ScalarValuedKernel):
"""
Deprecated reference to :class:`~coreax.kernels.ScalarValuedKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Renamed to `UniCompositeKernel`; "
+ " moved to `coreax.kernels.base.UniCompositeKernel`; "
+ " will be removed in version 0.3.0"
"Renamed to `UniCompositeKernel`;"
+ " moved to `coreax.kernels.base.UniCompositeKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class CompositeKernel(_UniCompositeKernel):
"""
Deprecated reference to :class:`~coreax.kernels.UniCompositeKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Renamed to `DuoCompositeKernel`; "
+ " moved to `coreax.kernels.base.DuoCompositeKernel`; "
+ " will be removed in version 0.3.0"
"Renamed to `DuoCompositeKernel`;"
+ " moved to `coreax.kernels.base.DuoCompositeKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class PairedKernel(_DuoCompositeKernel):
"""
Deprecated reference to :class:`~coreax.kernels.DuoCompositeKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


# pylint:enable = abstract-method


@deprecated(
"Moved to `coreax.kernels.base.AdditiveKernel`; will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.AdditiveKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class AdditiveKernel(_AdditiveKernel):
"""
Deprecated reference to :class:`~coreax.kernels.AdditiveKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.ProductKernel`; will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.ProductKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class ProductKernel(_ProductKernel):
"""
Deprecated reference to :class:`~coreax.kernels.ProductKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.LinearKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.LinearKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class LinearKernel(_LinearKernel):
"""
Deprecated reference to :class:`~coreax.kernels.LinearKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.LinearKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.LinearKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class PolynomialKernel(_PolynomialKernel):
"""
Deprecated reference to :class:`~coreax.kernels.PolynomialKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.SquaredExponentialKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.SquaredExponentialKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class SquaredExponentialKernel(_SquaredExponentialKernel):
"""
Deprecated reference to :class:`~coreax.kernels.SquaredExponentialKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.ExponentialKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.ExponentialKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class ExponentialKernel(_ExponentialKernel):
"""
Deprecated reference to :class:`~coreax.kernels.ExponentialKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.RationalQuadraticKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.RationalQuadraticKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class RationalQuadraticKernel(_RationalQuadraticKernel):
"""
Deprecated reference to :class:`~coreax.kernels.RationalQuadraticKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.PeriodicKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.PeriodicKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class PeriodicKernel(_PeriodicKernel):
"""
Deprecated reference to :class:`~coreax.kernels.PeriodicKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.LocallyPeriodicKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.LocallyPeriodicKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class LocallyPeriodicKernel(_LocallyPeriodicKernel):
"""
Deprecated reference to :class:`~coreax.kernels.LocallyPeriodicKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.LaplacianKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.LaplacianKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class LaplacianKernel(_LaplacianKernel):
"""
Deprecated reference to :class:`~coreax.kernels.SquaredExponentialKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.PCIMQKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.PCIMQKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class PCIMQKernel(_PCIMQKernel):
"""
Deprecated reference to :class:`~coreax.kernels.PCIMQKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""


@deprecated(
"Moved to `coreax.kernels.base.scalar_valued.SteinKernel`; "
+ " will be removed in version 0.3.0"
"Moved to `coreax.kernels.base.scalar_valued.SteinKernel`."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
class SteinKernel(_SteinKernel):
"""
Deprecated reference to :class:`~coreax.kernels.PCIMQKernel`.
Will be removed in version 0.3.0
Deprecated since version 0.3.0. Will be removed in version 0.4.0.
"""
42 changes: 3 additions & 39 deletions coreax/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,6 @@ def squared_distance(
return jnp.dot(x - y, x - y)


@deprecated(
"Use coreax.util.pairwise(coreax.util.squared_distance)(x, y);"
"will be removed in version 0.3.0"
)
def squared_distance_pairwise(
x: Union[Shaped[Array, " d"], Shaped[Array, ""], float, int],
y: Union[Shaped[Array, " d"], Shaped[Array, ""], float, int],
) -> Shaped[Array, ""]:
r"""
Calculate efficient pairwise square distance between two arrays.
:param x: First set of vectors as a :math:`n \times d` array
:param y: Second set of vectors as a :math:`m \times d` array
:return: Pairwise squared distances between ``x_array`` and ``y_array`` as an
:math:`n \times m` array
"""
return pairwise(squared_distance)(x, y)


@jit
def difference(
x: Union[Shaped[Array, " d"], Shaped[Array, ""], float, int],
Expand All @@ -256,7 +237,9 @@ def difference(


@deprecated(
"Use coreax.kernels.util.median_heuristic; will be removed in version 0.3.0"
"Use coreax.kernels.util.median_heuristic instead."
+ " Deprecated since version 0.3.0."
+ " Will be removed in version 0.4.0."
)
@jit
def median_heuristic(
Expand Down Expand Up @@ -284,25 +267,6 @@ def median_heuristic(
return jnp.sqrt(median_square_distance / 2.0)


@deprecated(
"Use coreax.util.pairwise(coreax.util.difference)(x, y);"
"will be removed in version 0.3.0"
)
def pairwise_difference(
x: Union[Shaped[Array, " d"], Shaped[Array, ""], float, int],
y: Union[Shaped[Array, " d"], Shaped[Array, ""], float, int],
) -> Shaped[Array, ""]:
r"""
Calculate efficient pairwise difference between two arrays of vectors.
:param x: First set of vectors as a :math:`n \times d` array
:param y: Second set of vectors as a :math:`m \times d` array
:return: Pairwise differences between ``x_array`` and ``y_array`` as an
:math:`n \times m \times d` array
"""
return pairwise(difference)(x, y)


def sample_batch_indices(
random_key: KeyArrayLike,
max_index: int,
Expand Down
19 changes: 0 additions & 19 deletions coreax/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from jax import Array
from jaxopt import OSQP
from jaxtyping import Shaped
from typing_extensions import deprecated

from coreax.data import Data, as_data
from coreax.kernels import ScalarValuedKernel
Expand Down Expand Up @@ -313,21 +312,3 @@ def solve(
unroll=unroll,
)
return solve_qp(kernel_cc, kernel_cd, **solver_kwargs)


@deprecated("Renamed to SBQWeightsOptimiser; will be removed in version 0.3.0")
class SBQ(SBQWeightsOptimiser):
"""
Deprecated reference to :class:`~coreax.weights.SBQWeightsOptimiser`.
Will be removed in version 0.3.0
"""


@deprecated("Renamed to `MMDWeightsOptimiser`; will be removed in version 0.3.0")
class MMD(MMDWeightsOptimiser):
"""
Deprecated reference to :class:`~coreax.weights.MMDWeightsOptimiser`.
Will be removed in version 0.3.0
"""

0 comments on commit 093f3d1

Please sign in to comment.