Skip to content
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

[BUG] extract_top_k_and_threshold_from_distance_profiles_one_series Function Errors Related to Numba and n_candidates Parameter #2475

Open
lucifer4073 opened this issue Dec 29, 2024 · 1 comment · May be fixed by #2473
Labels
bug Something isn't working similarity search Similarity search package

Comments

@lucifer4073
Copy link
Contributor

lucifer4073 commented Dec 29, 2024

Describe the bug

The extract_top_k_and_threshold_from_distance_profiles_one_series function in similarity_search/_commons.py encounters errors primarily due to the @njit(cache=True) decorator from the Numba module.

After removing the Numba accelerator, the function operates correctly only when the distance profile array has n_candidates=1. Setting n_candidates to a value greater than 1 results in a ValueError.

Steps/Code to reproduce the bug

To reproduce

n_cases=10
n_candidates=2
arr=np.random.randint(0,10,size=(n_cases,n_candidates))
res_arr=extract_top_k_and_threshold_from_distance_profiles_one_series(arr,id_x=2)

Expected results

No error should be thrown

Actual results

Error when @njit(cache=True) is used

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], [line 1](vscode-notebook-cell:?execution_count=8&line=1)
----> [1](vscode-notebook-cell:?execution_count=8&line=1) res_arr=extract_top_k_and_threshold_from_distance_profiles_one_series(arr,id_x=0)
      [2](vscode-notebook-cell:?execution_count=8&line=2) res_arr

File c:\Users\Balgopal\aeon_gsoc\aeon\aeon-venv\Lib\site-packages\numba\core\dispatcher.py:442, in _DispatcherBase._compile_for_args(self, *args, **kws)
    [440](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:440)             e.patch_message('\n'.join((str(e).rstrip(), help_msg)))
    [441](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:441)     # ignore the FULL_TRACEBACKS config, this needs reporting!
--> [442](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:442)     raise e
    [443](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:443) finally:
    [444](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:444)     self._types_active_call = []

File c:\Users\Balgopal\aeon_gsoc\aeon\aeon-venv\Lib\site-packages\numba\core\dispatcher.py:375, in _DispatcherBase._compile_for_args(self, *args, **kws)
    [373](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:373) return_val = None
    [374](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:374) try:
--> [375](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:375)     return_val = self.compile(tuple(argtypes))
    [376](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:376) except errors.ForceLiteralArg as e:
    [377](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:377)     # Received request for compiler re-entry with the list of arguments
    [378](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:378)     # indicated by e.requested_args.
    [379](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:379)     # First, check if any of these args are already Literal-ized
    [380](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:380)     already_lit_pos = [i for i in e.requested_args
    [381](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/dispatcher.py:381)                        if isinstance(args[i], types.Literal)]

File c:\Users\Balgopal\aeon_gsoc\aeon\aeon-venv\Lib\site-packages\numba\core\dispatcher.py:905, in Dispatcher.compile(self, sig)
...
--> [249](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/typing/npydecl.py:249) assert len(sig.args) == 3
    [250](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/typing/npydecl.py:250) real_sig = signature(sig.return_type, *sig.args[:2])
    [251](file:///C:/Users/Balgopal/aeon_gsoc/aeon/aeon-venv/Lib/site-packages/numba/core/typing/npydecl.py:251) return real_sig

AttributeError: 'NoneType' object has no attribute 'args'

Error on removal for n_candidates >=1

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: only length-1 arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
Cell In[7], [line 1](vscode-notebook-cell:?execution_count=7&line=1)
----> [1](vscode-notebook-cell:?execution_count=7&line=1) res_arr=extract_top_k_and_threshold_from_distance_profiles_one_series(arr,id_x=2)
      [2](vscode-notebook-cell:?execution_count=7&line=2) res_arr

File ~\aeon_gsoc\aeon\aeon\similarity_search\_commons.py:348, in extract_top_k_and_threshold_from_distance_profiles_one_series(distance_profiles, id_x, k, threshold, exclusion_size, inverse_distance)
    [346](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Balgopal/aeon_gsoc/aeon/sample_tests/~/aeon_gsoc/aeon/aeon/similarity_search/_commons.py:346)     for i in range(_k):
    [347](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Balgopal/aeon_gsoc/aeon/sample_tests/~/aeon_gsoc/aeon/aeon/similarity_search/_commons.py:347)         indexes[i, 0] = id_x
--> [348](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Balgopal/aeon_gsoc/aeon/sample_tests/~/aeon_gsoc/aeon/aeon/similarity_search/_commons.py:348)         indexes[i, 1] = _argsort[i]
    [349](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Balgopal/aeon_gsoc/aeon/sample_tests/~/aeon_gsoc/aeon/aeon/similarity_search/_commons.py:349)     return distance_profiles[_argsort[:_k]], indexes
    [350](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Balgopal/aeon_gsoc/aeon/sample_tests/~/aeon_gsoc/aeon/aeon/similarity_search/_commons.py:350) else:
    [351](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Balgopal/aeon_gsoc/aeon/sample_tests/~/aeon_gsoc/aeon/aeon/similarity_search/_commons.py:351)     # Apply exclusion zone to avoid neighboring matches

ValueError: setting an array element with a sequence.

Versions

No response

@baraline
Copy link
Member

Hi, thanks for raising the issue, could you by any chance try to use the function I defined in #2473 (defined in /subsequence_search/_commons.py) to see if it fix your issue ? I extensively tested this one so it should be fine

@baraline baraline added the similarity search Similarity search package label Jan 1, 2025
@baraline baraline linked a pull request Jan 2, 2025 that will close this issue
8 tasks
@baraline baraline linked a pull request Jan 2, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working similarity search Similarity search package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants