2

I was writing code for the simulation of the fluid dynamics of a layer of water:

import numpy as np
# IYPT prob 7
cup_dt = 1e-4  # Time step size for simulation (s) - Reduced  for stability
water_kinetic_viscosity = 1e-2  # cm^2/s
water_viscosity=1e-2  # Pa.s
save_frame_frequency_per_second = 24# frame per s
from numba import njit
@njit
def layer_angular_velocity_change(*,
                              kinetic_viscosity: float,
                              radius: float,
                              layer: int,
                              total_layers: int,
                              upper_angular_velocity: np.ndarray,
                              angular_velocity: np.ndarray,
                              lower_angular_velocity: np.ndarray
                              ) :

return [1,1,1]
@njit
def solid_liquid_layer_angular_velocity_change(
    viscosity,
    radius,
    thickness,
    solid_inertia,
    solid_angular_velocity,
    liquid_layer_angular_velocity,
    second_liquid_layer_angular_velocity
):
liquid_angular_velocity_change = layer_angular_velocity_change(
        kinetic_viscosity=water_kinetic_viscosity,
        radius=1,
        layer=1 / thickness,
        total_layers=1,
        upper_angular_velocity=solid_angular_velocity,
        angular_velocity=liquid_layer_angular_velocity,
        lower_angular_velocity=second_liquid_layer_angular_velocity
)

return 1,2
# Update boundary layer and solid
upper_layer_viscous_increment_term, solid_angular_velocity_viscous_increment_term = solid_liquid_layer_angular_velocity_change(
1,
1,
1,
[1,1,1],
[1,1,1],
[1,1,1],
[1,1,1],
)

then, I received an error which is caused by numba, which claims to be the parameters calling doesn't match the function was defined causing index out of range, following:

/usr/local/bin/python3.13 /Users/niuyingkai/PycharmProjects/PT-formula/2026 prob 7 liquid solid interaction.py 
Traceback (most recent call last):
File "/Users/niuyingkai/PycharmProjects/PT-formula/2026 prob 7 liquid solid interaction.py", line 174, in <module>
upper_layer_viscous_increment_term, solid_angular_velocity_viscous_increment_term = solid_liquid_layer_angular_velocity_change(
                                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    viscosity=water_viscosity,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
      second_liquid_layer_angular_velocity=water_angular_velocity_current[water_layer_num-2],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 443, in _compile_for_args
raise e
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 376, in _compile_for_args
return_val = self.compile(tuple(argtypes))
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 908, in compile
cres = self._compiler.compile(args, return_type)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 80, in compile
status, retval = self._compile_cached(args, return_type)
                 ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 94, in _compile_cached
retval = self._compile_core(args, return_type)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 107, in _compile_core
cres = compiler.compile_extra(self.targetdescr.typing_context,
                              self.targetdescr.target_context,
...<2 lines>...
                              flags=flags, locals=self.locals,
                              pipeline_class=self.pipeline_class)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler.py", line 739, in compile_extra
return pipeline.compile_extra(func)
       ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler.py", line 439, in compile_extra
return self._compile_bytecode()
       ~~~~~~~~~~~~~~~~~~~~~~^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler.py", line 505, in _compile_bytecode
return self._compile_core()
       ~~~~~~~~~~~~~~~~~~^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler.py", line 481, in _compile_core
raise e
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler.py", line 473, in _compile_core
pm.run(self.state)
~~~~~~^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler_machinery.py", line 363, in run
raise e
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler_machinery.py", line 356, in run
self._runPass(idx, pass_inst, state)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
return func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler_machinery.py", line 311, in _runPass
mutated |= check(pss.run_pass, internal_state)
           ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/compiler_machinery.py", line 272, in check
mangled = func(compiler_state)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typed_passes.py", line 114, in run_pass
typemap, return_type, calltypes, errs = type_inference_stage(
                                        ~~~~~~~~~~~~~~~~~~~~^
    state.typingctx,
    ^^^^^^^^^^^^^^^^
...<4 lines>...
    state.locals,
    ^^^^^^^^^^^^^
    raise_errors=self._raise_errors)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typed_passes.py", line 95, in type_inference_stage
errs = infer.propagate(raise_errors=raise_errors)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typeinfer.py", line 1075, in propagate
errors = self.constraints.propagate(self)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typeinfer.py", line 160, in propagate
constraint(typeinfer)
~~~~~~~~~~^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typeinfer.py", line 572, in __call__
self.resolve(typeinfer, typevars, fnty)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typeinfer.py", line 595, in resolve
sig = typeinfer.resolve_call(fnty, pos_args, kw_args)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typeinfer.py", line 1569, in resolve_call
return self.context.resolve_function_type(fnty, pos_args, kw_args)
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typing/context.py", line 279, in resolve_function_type
res = self._resolve_user_function_type(func, args, kws)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/typing/context.py", line 335, in _resolve_user_function_type
return func.get_call_type(self, args, kws)
       ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/types/functions.py", line 541, in get_call_type
self.dispatcher.get_call_template(args, kws)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 315, in get_call_template
pysig, args = self._compiler.fold_argument_types(args, kws)
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numba/core/dispatcher.py", line 73, in fold_argument_types
args = fold_arguments(self.pysig, args, kws,
                      normal_handler,
                      default_handler,
                      stararg_handler)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-fpackages/numba/core/typing/templates.py", line 217, in fold_arguments
bind_kws[n] = args[len(kwonly) + idx]
              ~~~~^^^^^^^^^^^^^^^^^^^
IndexError: tuple index out of range

Process finished with exit code 1

But I checked the calling and there was no problem at all. What is the problem? How to solve it?

4
  • Could you share a minimal reproducible example? Something we can run so to analyse what is going on. It might be a Numba bug. Commented yesterday
  • 1
    This might be related to this issue. It's not exactly the same situation, but the stack trace looks almost identical. How about using positional arguments instead of keyword arguments? Commented yesterday
  • @ken I changed the code to upper_layer_viscous_increment_term, solid_angular_velocity_viscous_increment_term = solid_liquid_layer_angular_velocity_change( water_viscosity, water_radius, layer_thickness, inertia_tensor, solid_angular_velocity_current, water_angular_velocity_current[water_layer_num-1], water_angular_velocity_current[water_layer_num-2], ) but it still have the same error Commented yesterday
  • if you remove the requirement for keyword only arguments in layer_angular_velocity_change then the code runs Commented 13 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.