reconnect moved files to git repo

This commit is contained in:
root
2025-08-01 04:33:03 -04:00
commit 5d3c35492d
23190 changed files with 4750716 additions and 0 deletions

View File

@ -0,0 +1,18 @@
from .exceptions import (
MaxEvalError,
TargetSuccess,
CallbackSuccess,
FeasibleSuccess,
)
from .math import get_arrays_tol, exact_1d_array
from .versions import show_versions
__all__ = [
"MaxEvalError",
"TargetSuccess",
"CallbackSuccess",
"FeasibleSuccess",
"get_arrays_tol",
"exact_1d_array",
"show_versions",
]

View File

@ -0,0 +1,22 @@
class MaxEvalError(Exception):
"""
Exception raised when the maximum number of evaluations is reached.
"""
class TargetSuccess(Exception):
"""
Exception raised when the target value is reached.
"""
class CallbackSuccess(StopIteration):
"""
Exception raised when the callback function raises a ``StopIteration``.
"""
class FeasibleSuccess(Exception):
"""
Exception raised when a feasible point of a feasible problem is found.
"""

View File

@ -0,0 +1,77 @@
import numpy as np
EPS = np.finfo(float).eps
def get_arrays_tol(*arrays):
"""
Get a relative tolerance for a set of arrays.
Parameters
----------
*arrays: tuple
Set of `numpy.ndarray` to get the tolerance for.
Returns
-------
float
Relative tolerance for the set of arrays.
Raises
------
ValueError
If no array is provided.
"""
if len(arrays) == 0:
raise ValueError("At least one array must be provided.")
size = max(array.size for array in arrays)
weight = max(
np.max(np.abs(array[np.isfinite(array)]), initial=1.0)
for array in arrays
)
return 10.0 * EPS * max(size, 1.0) * weight
def exact_1d_array(x, message):
"""
Preprocess a 1-dimensional array.
Parameters
----------
x : array_like
Array to be preprocessed.
message : str
Error message if `x` cannot be interpreter as a 1-dimensional array.
Returns
-------
`numpy.ndarray`
Preprocessed array.
"""
x = np.atleast_1d(np.squeeze(x)).astype(float)
if x.ndim != 1:
raise ValueError(message)
return x
def exact_2d_array(x, message):
"""
Preprocess a 2-dimensional array.
Parameters
----------
x : array_like
Array to be preprocessed.
message : str
Error message if `x` cannot be interpreter as a 2-dimensional array.
Returns
-------
`numpy.ndarray`
Preprocessed array.
"""
x = np.atleast_2d(x).astype(float)
if x.ndim != 2:
raise ValueError(message)
return x

View File

@ -0,0 +1,67 @@
import os
import platform
import sys
from importlib.metadata import PackageNotFoundError, version
def _get_sys_info():
"""
Get useful system information.
Returns
-------
dict
Useful system information.
"""
return {
"python": sys.version.replace(os.linesep, " "),
"executable": sys.executable,
"machine": platform.platform(),
}
def _get_deps_info():
"""
Get the versions of the dependencies.
Returns
-------
dict
Versions of the dependencies.
"""
deps = ["cobyqa", "numpy", "scipy", "setuptools", "pip"]
deps_info = {}
for module in deps:
try:
deps_info[module] = version(module)
except PackageNotFoundError:
deps_info[module] = None
return deps_info
def show_versions():
"""
Display useful system and dependencies information.
When reporting issues, please include this information.
"""
print("System settings")
print("---------------")
sys_info = _get_sys_info()
print(
"\n".join(
f"{k:>{max(map(len, sys_info.keys())) + 1}}: {v}"
for k, v in sys_info.items()
)
)
print()
print("Python dependencies")
print("-------------------")
deps_info = _get_deps_info()
print(
"\n".join(
f"{k:>{max(map(len, deps_info.keys())) + 1}}: {v}"
for k, v in deps_info.items()
)
)