Skip to content

Commit

Permalink
Fix merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
janosg committed Oct 31, 2024
2 parents 02fb4d1 + 4dca0bc commit d4d666c
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 44 deletions.
33 changes: 30 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ jobs:
micromamba activate optimagic
pytest -m "not slow and not jax"
run-tests-with-old-pandas:
# This job is only for testing if optimagic works with older pandas versions, as
# many pandas functions we use will be deprecated in pandas 3. optimagic's behavior
# for older verions is handled in src/optimagic/compat.py.
# This job is only for testing if optimagic works with pandas<2, as many pandas
# functions we use will be deprecated in pandas 3. optimagic's behavior for older
# verions is handled in src/optimagic/compat.py. For compatibility with we have to
# restrict numpy<2.
name: Run tests for ${{ matrix.os}} on ${{ matrix.python-version }} with pandas 1
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -97,6 +98,32 @@ jobs:
run: |
micromamba activate optimagic
pytest -m "not slow and not jax"
run-tests-with-old-numpy:
# This job is only for testing if optimagic works with numpy<2. Because we already
# test pandas<2 with numpy<2, in this environment we restrict pandas>=2.
name: Run tests for ${{ matrix.os}} on ${{ matrix.python-version }} with numpy 1
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- '3.10'
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.tools/envs/testenv-numpy.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pytest -m "not slow and not jax"
code-in-docs:
name: Run code snippets in documentation
runs-on: ubuntu-latest
Expand Down
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
- hatchling
- ruff
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args:
Expand Down Expand Up @@ -68,7 +68,7 @@ repos:
- id: yamllint
exclude: tests/optimagic/optimizers/_pounders/fixtures
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
rev: eb1df34
hooks:
- id: docformatter
args:
Expand All @@ -80,7 +80,7 @@ repos:
- --blank
exclude: src/optimagic/optimization/algo_options.py
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.7.1
hooks:
# Run the linter.
- id: ruff
Expand All @@ -97,7 +97,7 @@ repos:
- pyi
- jupyter
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.18
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -109,7 +109,7 @@ repos:
- '88'
files: (README\.md)
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.18
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -132,12 +132,12 @@ repos:
args:
- --drop-empty-cells
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy
files: src|tests
additional_dependencies:
- numpy<2.0
- numpy
- packaging
- pandas-stubs
- sqlalchemy-stubs
Expand Down
4 changes: 2 additions & 2 deletions .tools/envs/testenv-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ dependencies:
- statsmodels # dev, tests
- cloudpickle # run, tests
- joblib # run, tests
- numpy<2.0 # run, tests
- numpy >= 2 # run, tests
- pandas # run, tests
- plotly # run, tests
- pybaum>=0.1.2 # run, tests
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy>=1.11 # dev, tests
- mypy=1.13 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
Expand Down
37 changes: 37 additions & 0 deletions .tools/envs/testenv-numpy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: optimagic
channels:
- conda-forge
- nodefaults
dependencies:
- pandas>=2
- numpy<2
- cyipopt>=1.4.0 # dev, tests
- pygmo>=2.19.0 # dev, tests
- nlopt # dev, tests
- pip # dev, tests, docs
- pytest # dev, tests
- pytest-cov # tests
- pytest-xdist # dev, tests
- statsmodels # dev, tests
- cloudpickle # run, tests
- joblib # run, tests
- plotly # run, tests
- pybaum>=0.1.2 # run, tests
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy=1.13 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- pip: # dev, tests, docs
- DFO-LS # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- kaleido # dev, tests
- types-cffi # dev, tests
- types-openpyxl # dev, tests
- types-jinja2 # dev, tests
- sqlalchemy-stubs # dev, tests
- -e ../../
4 changes: 2 additions & 2 deletions .tools/envs/testenv-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ dependencies:
- statsmodels # dev, tests
- cloudpickle # run, tests
- joblib # run, tests
- numpy<2.0 # run, tests
- numpy >= 2 # run, tests
- pandas # run, tests
- plotly # run, tests
- pybaum>=0.1.2 # run, tests
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy>=1.11 # dev, tests
- mypy=1.13 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
Expand Down
6 changes: 3 additions & 3 deletions .tools/envs/testenv-pandas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ channels:
- conda-forge
- nodefaults
dependencies:
- pandas<2.0.0
- pandas<2
- numpy<2
- cyipopt>=1.4.0 # dev, tests
- pygmo>=2.19.0 # dev, tests
- nlopt # dev, tests
Expand All @@ -15,13 +16,12 @@ dependencies:
- statsmodels # dev, tests
- cloudpickle # run, tests
- joblib # run, tests
- numpy<2.0 # run, tests
- plotly # run, tests
- pybaum>=0.1.2 # run, tests
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy>=1.11 # dev, tests
- mypy=1.13 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
Expand Down
23 changes: 15 additions & 8 deletions .tools/update_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,27 @@ def main():
## test environment others
test_env_others = deepcopy(test_env)

## test environment for pandas version 1
## test environment for pandas version < 2 (requires numpy < 2)
test_env_pandas = deepcopy(test_env)
test_env_pandas = [line for line in test_env_pandas if "pandas" not in line]
test_env_pandas.insert(_insert_idx, " - pandas<2.0.0")

# create docs testing environment

for pkg in ["numpy", "pandas"]:
test_env_pandas = [line for line in test_env_pandas if pkg not in line]
test_env_pandas.insert(_insert_idx, f" - {pkg}<2")

## test environment for numpy version < 2 (with pandas >= 2)
test_env_numpy = deepcopy(test_env)
for pkg in ["numpy", "pandas"]:
test_env_numpy = [line for line in test_env_numpy if pkg not in line]
test_env_numpy.insert(_insert_idx, " - numpy<2")
test_env_numpy.insert(_insert_idx, " - pandas>=2")

# test environment for documentation
docs_env = [line for line in lines if _keep_line(line, "docs")]
docs_env.append(" - -e ../../") # add local installation

# write environments
for name, env in zip(
["linux", "others", "pandas"],
[test_env_linux, test_env_others, test_env_pandas],
["linux", "others", "pandas", "numpy"],
[test_env_linux, test_env_others, test_env_pandas, test_env_numpy],
strict=False,
):
# Specify newline to avoid wrong line endings on Windows.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/how_to/how_to_multistart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
"metadata": {},
"outputs": [],
"source": [
"np.row_stack(res.multistart_info.exploration_sample).shape"
"np.vstack(res.multistart_info.exploration_sample).shape"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- toml # dev
- cloudpickle # run, tests
- joblib # run, tests
- numpy<2.0 # run, tests
- numpy >= 2 # run, tests
- pandas # run, tests
- plotly # run, tests
- pybaum>=0.1.2 # run, tests
Expand All @@ -32,7 +32,7 @@ dependencies:
- sphinx-panels # docs
- sphinxcontrib-bibtex # docs
- seaborn # dev, tests
- mypy>=1.11 # dev, tests
- mypy=1.13 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- furo # dev, docs
Expand All @@ -42,7 +42,7 @@ dependencies:
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- kaleido # dev, tests
- pre-commit # dev
- pre-commit>=4 # dev
- -e . # dev
# type stubs
- pandas-stubs # dev, tests
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ requires-python = ">=3.10"
dependencies = [
"cloudpickle",
"joblib",
"numpy<2.0",
"numpy",
"pandas",
"plotly",
"pybaum>=0.1.2",
Expand Down
9 changes: 6 additions & 3 deletions src/estimagic/estimate_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def estimate_ml(
optimize_options to False. Pytrees can be a numpy array, a pandas Series, a
DataFrame with "value" column, a float and any kind of (nested) dictionary
or list containing these elements. See :ref:`params` for examples.
optimize_options (dict, str or False): Keyword arguments that govern the
numerical optimization. Valid entries are all arguments of
optimize_options (dict, Algorithm, str or False): Keyword arguments that govern
the numerical optimization. Valid entries are all arguments of
:func:`~estimagic.optimization.optimize.minimize` except for those that are
passed explicilty to ``estimate_ml``. If you pass False as optimize_options
you signal that ``params`` are already the optimal parameters and no
Expand Down Expand Up @@ -199,7 +199,10 @@ def estimate_ml(
is_optimized = optimize_options is False

if not is_optimized:
if isinstance(optimize_options, str):
# If optimize_options is not a dictionary and not False, we assume it represents
# an algorithm. The actual testing of whether it is a valid algorithm is done
# when `maximize` is called.
if not isinstance(optimize_options, dict):
optimize_options = {"algorithm": optimize_options}

check_optimization_options(
Expand Down
9 changes: 6 additions & 3 deletions src/estimagic/estimate_msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def estimate_msm(
optimize_options to False. Pytrees can be a numpy array, a pandas Series, a
DataFrame with "value" column, a float and any kind of (nested) dictionary
or list containing these elements. See :ref:`params` for examples.
optimize_options (dict, str or False): Keyword arguments that govern the
numerical optimization. Valid entries are all arguments of
optimize_options (dict, Algorithm, str or False): Keyword arguments that govern
the numerical optimization. Valid entries are all arguments of
:func:`~estimagic.optimization.optimize.minimize` except for those that can
be passed explicitly to ``estimate_msm``. If you pass False as
``optimize_options`` you signal that ``params`` are already
Expand Down Expand Up @@ -199,7 +199,10 @@ def estimate_msm(
is_optimized = optimize_options is False

if not is_optimized:
if isinstance(optimize_options, str):
# If optimize_options is not a dictionary and not False, we assume it represents
# an algorithm. The actual testing of whether it is a valid algorithm is done
# when `minimize` is called.
if not isinstance(optimize_options, dict):
optimize_options = {"algorithm": optimize_options}

check_optimization_options(
Expand Down
4 changes: 2 additions & 2 deletions src/optimagic/differentiation/richardson_extrapolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _compute_step_ratio(steps):
"""
ratios = steps[1:, :] / steps[:-1, :]
ratios = ratios[np.isfinite(ratios)]
finite_ratios = ratios[np.isfinite(ratios)]

step_ratio = ratios.flat[0]
step_ratio = finite_ratios.item(0)
return step_ratio
2 changes: 1 addition & 1 deletion src/optimagic/optimization/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _solve_internal_problem(
def __post_init__(self) -> None:
for field in self.__dataclass_fields__:
raw_value = getattr(self, field)
target_type = self.__dataclass_fields__[field].type
target_type = typing.cast(type, self.__dataclass_fields__[field].type)
if target_type in TYPE_CONVERTERS:
try:
value = TYPE_CONVERTERS[target_type](raw_value)
Expand Down
4 changes: 2 additions & 2 deletions src/optimagic/optimizers/_pounders/gqtpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def gqtpar(model, x_candidate, *, k_easy=0.1, k_hard=0.2, maxiter=200):
zero_threshold = (
model.square_terms.shape[0]
* np.finfo(float).eps
* np.linalg.norm(model.square_terms, np.Inf)
* np.linalg.norm(model.square_terms, np.inf)
)
stopping_criteria = {
"k_easy": k_easy,
Expand Down Expand Up @@ -175,7 +175,7 @@ def _get_initial_guess_for_lambdas(
gradient_norm = np.linalg.norm(main_model.linear_terms)
model_hessian = main_model.square_terms

hessian_infinity_norm = np.linalg.norm(model_hessian, np.Inf)
hessian_infinity_norm = np.linalg.norm(model_hessian, np.inf)
hessian_frobenius_norm = np.linalg.norm(model_hessian, "fro")

hessian_gershgorin_lower, hessian_gershgorin_upper = _compute_gershgorin_bounds(
Expand Down
2 changes: 1 addition & 1 deletion src/optimagic/parameters/kernel_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def _transformation_matrix(dim):

rows = [_unit_vector_or_zeros(i, dim**2) for i in indices]

transformer = np.row_stack(rows)
transformer = np.vstack(rows)
return transformer


Expand Down
2 changes: 1 addition & 1 deletion src/optimagic/shared/check_option_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def check_optimization_options(options, usage, algorithm_mandatory=True):
msg = (
"The following are not valid entries of optimize_options because they are "
"not only relevant for minimization but also for inference: "
"{invalid_general}"
f"{invalid_general}"
)
raise ValueError(msg)
Loading

0 comments on commit d4d666c

Please sign in to comment.