-
Notifications
You must be signed in to change notification settings - Fork 6
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
[feature] wrapping cost function to return best value explored #33
[feature] wrapping cost function to return best value explored #33
Conversation
It looks like mypy is failing due to this: python/mypy#3060. Not sure what to do 🤷♂️ |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
- Coverage 94.95% 94.17% -0.78%
==========================================
Files 28 29 +1
Lines 1011 1185 +174
==========================================
+ Hits 960 1116 +156
- Misses 51 69 +18
☔ View full report in Codecov by Sentry. |
Can we add an option for the user to go back to the old way of using the scipy optimizer? People might get confused if we don't 😅 |
class _CostFunctionWithBestValueType(type): | ||
def __instancecheck__(cls, obj: object) -> bool: | ||
if ( | ||
isinstance(obj, Callable) | ||
and hasattr(obj, "best_value") | ||
and hasattr(obj, "best_params") | ||
): | ||
return True | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice little piece of code! But I'm afraid it might be needlessly opaque since isinstance is only used once here and just for an assert statement. metaclasses are considered "heavy machinery" so it's best not to use them when they could be replaced with a simple if statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove this to check the new instance check, I get some linting problems 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but since you only use this isinstance once, it's not really worth changing the instancecheck method right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this trick for the tensor train optimiser PR too #31. Do you want me to instead have a custom isinstanceCostFunctionWithBestValue
function, or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's probably fine. Not worth holding up the PR for this.
I'm using this in a GEO workflow but it seems as though it isn't working as expected. Here are the logs from the workflow: {"timestamp": "2023-01-25 08:32:15,166", "level": "INFO", "filename": "history_selector.py:102", "message": Number of pre-selected candidates 398. The radius is 0.0390625}
{"timestamp": "2023-01-25 08:32:15,298", "level": "INFO", "filename": "base.py:769", "message": Probs sum is: 1.0000000000000022}
{"timestamp": "2023-01-25 08:32:15,298", "level": "INFO", "filename": "base.py:770", "message": xtrain size is: 7924}
{"timestamp": "2023-01-25 08:32:15,298", "level": "INFO", "filename": "base.py:771", "message": Number of observations are: 7924}
{"timestamp": "2023-01-25 08:32:15,298", "level": "INFO", "filename": "base.py:772", "message": Minimum cost is: -8.103484550314727}
Composition labels in HDBSCAN clustering:
Counter({-1: 4496, 4: 1412, 8: 838, 7: 283, 1: 197, 5: 194, 6: 161, 0: 121, 3: 113, 2: 109})
Cleared cache for LangerInCorners(m=4) in 2 dimensions and seed 0
{"timestamp": "2023-01-25 08:32:16,405", "level": "INFO", "filename": "geo_workflows.py:315", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Finished in 0.024 seconds"}}
{"timestamp": "2023-01-25 08:32:16,405", "level": "INFO", "filename": "geo_workflows.py:316", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Optimum value: -7.866315123621101"}}
{"timestamp": "2023-01-25 08:32:16,433", "level": "INFO", "filename": "local_workflows.py:62", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :::: Cleaned history from length 30 to length 1. dl = 0.1810866855724538"}}
Cleared cache for LangerInCorners(m=4) in 2 dimensions and seed 0
{"timestamp": "2023-01-25 08:32:17,202", "level": "INFO", "filename": "geo_workflows.py:315", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Finished in 0.025 seconds"}}
{"timestamp": "2023-01-25 08:32:17,203", "level": "INFO", "filename": "geo_workflows.py:316", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Optimum value: -7.8663151681677315"}}
{"timestamp": "2023-01-25 08:32:17,227", "level": "INFO", "filename": "local_workflows.py:62", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :::: Cleaned history from length 67 to length 2. dl = 0.17779190436107137"}}
Cleared cache for LangerInCorners(m=4) in 2 dimensions and seed 0
{"timestamp": "2023-01-25 08:32:17,966", "level": "INFO", "filename": "geo_workflows.py:315", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Finished in 0.024 seconds"}}
{"timestamp": "2023-01-25 08:32:17,966", "level": "INFO", "filename": "geo_workflows.py:316", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Optimum value: -7.866315173534457"}}
{"timestamp": "2023-01-25 08:32:17,992", "level": "INFO", "filename": "local_workflows.py:62", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :::: Cleaned history from length 67 to length 1. dl = 0.17560887003556275"}}
Cleared cache for LangerInCorners(m=4) in 2 dimensions and seed 0
{"timestamp": "2023-01-25 08:32:18,650", "level": "INFO", "filename": "geo_workflows.py:315", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Finished in 0.024 seconds"}}
{"timestamp": "2023-01-25 08:32:18,651", "level": "INFO", "filename": "geo_workflows.py:316", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Optimum value: -7.856305814156559"}}
{"timestamp": "2023-01-25 08:32:18,680", "level": "INFO", "filename": "local_workflows.py:62", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :::: Cleaned history from length 62 to length 2. dl = 0.17537807662467564"}}
Cleared cache for LangerInCorners(m=4) in 2 dimensions and seed 0
{"timestamp": "2023-01-25 08:32:19,406", "level": "INFO", "filename": "geo_workflows.py:315", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Finished in 0.024 seconds"}}
{"timestamp": "2023-01-25 08:32:19,407", "level": "INFO", "filename": "geo_workflows.py:316", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :: Optimum value: -7.856305810418254"}}
{"timestamp": "2023-01-25 08:32:19,431", "level": "INFO", "filename": "local_workflows.py:62", "message": {"run_id": "wf.local_run.0000000@tsk.task_local-0.00000", "logs": " :::: Cleaned history from length 60 to length 2. dl = 0.17537775444008236"}} From GEO optimisation we get a minimum of |
Let me know if you need any help with debugging and GEO to get the behavior you're expecting! Although I'm not sure how much help I'll be! |
3c84347
to
9818a7a
Compare
…' of https://github.com/zapatacomputing/orquestra-opt into fix/#29/wrap-cost-function-to-return-best-val-scipy-opt
Description
Closes #29
Please verify that you have completed the following steps