Skip to content

Comments

Add shekel funcfix#16

Merged
SimonBlanke merged 8 commits intoSimonBlanke:mainfrom
ZohaibHassan16:add-shekel-funcfix
Feb 19, 2026
Merged

Add shekel funcfix#16
SimonBlanke merged 8 commits intoSimonBlanke:mainfrom
ZohaibHassan16:add-shekel-funcfix

Conversation

@ZohaibHassan16
Copy link
Contributor

Description

This PR adds the Shekel function to the library's collection of standard algebraic test functions.

Related Issues

issue #10

Type of Change

  • [ x] [ENH] - New feature (non-breaking change adding functionality))

How was this solved?

Implementation: Created shekel_function.py inside src/surfaces/test_functions/algebraic/standard/test_functions_nd/.

Registration: Updated the following init.py files to ensure the function is properly exported and accessible via the library's API:

src/surfaces/test_functions/algebraic/init.py

src/surfaces/test_functions/algebraic/standard/init.py

src/surfaces/test_functions/algebraic/standard/test_functions_nd/init.py

Checklist

Required

  • [x ] PR title includes appropriate tag: [BUG], [ENH], [DOC] or [MNT]
  • [x ] Code passes make check (lint, format, isort)

Tests

  • [x ] Tests added/updated for changes

Documentation

  • [ x] Documentation added/updated (docstrings, user guide, examples)

Note: New features ([ENH]) typically require both tests and documentation.
Bug fixes ([BUG]) should include a regression test when possible.

Testing

It can be verified by instantiating it through the standard algebraic interface:

from surfaces.test_functions.algebraic import ShekelFunction

func = ShekelFunction()
print(func.search_space)

Additional Notes

This is a fresh Pull Request intended to replace previous one that was "accidentally" combined with the other one

@ZohaibHassan16 ZohaibHassan16 mentioned this pull request Jan 18, 2026
5 tasks
Copy link
Owner

@SimonBlanke SimonBlanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would fit better to create a new module "test_functions_4d", because this test-function does not have a n_dim parameter. There is also some code-quality test, that fails.

@ZohaibHassan16
Copy link
Contributor Author

Done and cleaned the code @SimonBlanke

Copy link
Owner

@SimonBlanke SimonBlanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some tests failing. Could you explain why?

@ZohaibHassan16
Copy link
Contributor Author

My bad @SimonBlanke , it's because ShekelFunction was simultaneously still sitting in the standard_functions_nd list in constructor. Should be all green now


def _create_objective_function(self) -> None:
def shekel_function(params: Dict[str, Any]) -> float:
x_input = np.array([params[f"x{i}"] for i in range(self.n_dim)])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to change this and the search-space. This part still looks like an n-d test function

@ZohaibHassan16
Copy link
Contributor Author

Hey @SimonBlanke ,
I've updated ShekelFunction with the following changes:

  • Explicit Unpacking: Replaced the loop in the evaluator with explicit x0 through x3 handling for better clarity.

  • Search Space: Updated the _search_space method to explicitly define the four dimensions.

Just a lil note, I think it will fail on CI run because in test_spec_immutable_across_calls currently assumes all multi-dimenstional functions are 2D? Please correct me on that

Copy link
Owner

@SimonBlanke SimonBlanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests are still failing. Please also do a local test run before pushing the new commits.

@ZohaibHassan16
Copy link
Contributor Author

Tests are failing because test_spec_immutable_across_calls test currently uses a hardcoded fallback that assumes any multi-dimensional function is strictly 2D. It passes {"x0": 0.5, "x1": 0.5}. Since ShekelFunction is our first 4D function, it crashes with a KeyError: 'x2' when the evaluator looks for the remaining dimensions.

We can fix this by making it dim-agnostic.

Specifically:

# Old code: 
# _ = func({"x0": 0.5} if len(func.search_space) == 1 else {"x0": 0.5, "x1": 0.5})

# New code:
params = {key: 0.5 for key in func.search_space.keys()}
_ = func(params)

@SimonBlanke
Copy link
Owner

Tests are failing because test_spec_immutable_across_calls test currently uses a hardcoded fallback that assumes any multi-dimensional function is strictly 2D. It passes {"x0": 0.5, "x1": 0.5}. Since ShekelFunction is our first 4D function, it crashes with a KeyError: 'x2' when the evaluator looks for the remaining dimensions.

We can fix this by making it dim-agnostic.

Specifically:

# Old code: 
# _ = func({"x0": 0.5} if len(func.search_space) == 1 else {"x0": 0.5, "x1": 0.5})

# New code:
params = {key: 0.5 for key in func.search_space.keys()}
_ = func(params)

That is right! Currently we do not even have 3D test functions. Only 1D, 2D and ND. And the test is set on this test-function collection, which is not good. I think your change makes sense. Please implement it :-)

@ZohaibHassan16
Copy link
Contributor Author

Done @SimonBlanke , spec consistency tests are now passing.

2026-02-19 13_07_22-Surfaces – test_spec_consistency py

Copy link
Owner

@SimonBlanke SimonBlanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to merge this soon, but there are changes in the .gitignore that create merge conflicts. There should not be any changes in the .gitignore in this PR.

@ZohaibHassan16
Copy link
Contributor Author

Resolved @SimonBlanke

Copy link
Owner

@SimonBlanke SimonBlanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some test fails. It is an easy fix. Just bump the number.

Copy link
Owner

@SimonBlanke SimonBlanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done.

@SimonBlanke SimonBlanke merged commit e93ece2 into SimonBlanke:main Feb 19, 2026
21 checks passed
@ZohaibHassan16
Copy link
Contributor Author

Thanks for your patience !!! These were my first two PRs ever on GitHub, so I learned a lot, especially about how not to be a dumbass in a large codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants