vectorbt
vectorbt copied to clipboard
What ways I have to debug functions?
Currently I have some implementation of order_func_nb for example:
@njit
def order_func_nb(c):
"""Called for each timestamp to generate orders"""
# print(f"Context: {c}") - I want to debug it with print or other ways
return vbt.portfolio.enums.NoOrder
And I tried to use:
- Plain approach with print and I got this traceback:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<class 'str'>) found for signature:
>>> str(OrderContext(UniTuple(int64 x 2), array(int64, 1d, C), array(float64, 1d, C), bool, array(int64, 2d, F), array(bool, 2d, C), bool, bool, array(float64, 2d, F), bool, bool, bool, bool, array(Record(id[type=int64;offset=0],col[type=int64;offset=8],idx[type=int64;offset=16],size[type=float64;offset=24],price[type=float64;offset=32],fees[type=float64;offset=40],side[type=int64;offset=48];56;True), 1d, C), array(Record(id[type=int64;offset=0],group[type=int64;offset=8],col[type=int64;offset=16],idx[type=int64;offset=24],cash[type=float64;offset=32],position[type=float64;offset=40],debt[type=float64;offset=48],free_cash[type=float64;offset=56],val_price[type=float64;offset=64],value[type=float64;offset=72],req_size[type=float64;offset=80],req_price[type=float64;offset=88],req_size_type[type=int64;offset=96],req_direction[type=int64;offset=104],req_fees[type=float64;offset=112],req_fixed_fees[type=float64;offset=120],req_slippage[type=float64;offset=128],req_min_size[type=float64;offset=136],req_max_size[type=float64;offset=144],req_size_granularity[type=float64;offset=152],req_reject_prob[type=float64;offset=160],req_lock_cash[type=bool;offset=168],req_allow_partial[type=bool;offset=169],req_raise_reject[type=bool;offset=170],req_log[type=bool;offset=171],new_cash[type=float64;offset=176],new_position[type=float64;offset=184],new_debt[type=float64;offset=192],new_free_cash[type=float64;offset=200],new_val_price[type=float64;offset=208],new_value[type=float64;offset=216],res_size[type=float64;offset=224],res_price[type=float64;offset=232],res_fees[type=float64;offset=240],res_side[type=int64;offset=248],res_status[type=int64;offset=256],res_status_info[type=int64;offset=264],order_id[type=int64;offset=272];280;True), 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(int64, 1d, C), array(int64, 1d, C), array(Record(id[type=int64;offset=0],col[type=int64;offset=8],size[type=float64;offset=16],entry_idx[type=int64;offset=24],entry_price[type=float64;offset=32],entry_fees[type=float64;offset=40],exit_idx[type=int64;offset=48],exit_price[type=float64;offset=56],exit_fees[type=float64;offset=64],pnl[type=float64;offset=72],return[type=float64;offset=80],direction[type=int64;offset=88],status[type=int64;offset=96],parent_id[type=int64;offset=104];112;True), 1d, C), int64, int64, int64, int64, int64, array(int64, 1d, A), int64, int64, float64, float64, float64, float64, float64, float64, float64, Record(id[type=int64;offset=0],col[type=int64;offset=8],size[type=float64;offset=16],entry_idx[type=int64;offset=24],entry_price[type=float64;offset=32],entry_fees[type=float64;offset=40],exit_idx[type=int64;offset=48],exit_price[type=float64;offset=56],exit_fees[type=float64;offset=64],pnl[type=float64;offset=72],return[type=float64;offset=80],direction[type=int64;offset=88],status[type=int64;offset=96],parent_id[type=int64;offset=104];112;True)))
There are 10 candidate implementations:
- Of which 10 did not match due to:
Overload of function 'str': File: <numerous>: Line N/A.
With argument(s): '(OrderContext(UniTuple(int64 x 2), array(int64, 1d, C), array(float64, 1d, C), bool, array(int64, 2d, F), array(bool, 2d, C), bool, bool, array(float64, 2d, F), bool, bool, bool, bool, array(Record(id[type=int64;offset=0],col[type=int64;offset=8],idx[type=int64;offset=16],size[type=float64;offset=24],price[type=float64;offset=32],fees[type=float64;offset=40],side[type=int64;offset=48];56;True), 1d, C), array(Record(id[type=int64;offset=0],group[type=int64;offset=8],col[type=int64;offset=16],idx[type=int64;offset=24],cash[type=float64;offset=32],position[type=float64;offset=40],debt[type=float64;offset=48],free_cash[type=float64;offset=56],val_price[type=float64;offset=64],value[type=float64;offset=72],req_size[type=float64;offset=80],req_price[type=float64;offset=88],req_size_type[type=int64;offset=96],req_direction[type=int64;offset=104],req_fees[type=float64;offset=112],req_fixed_fees[type=float64;offset=120],req_slippage[type=float64;offset=128],req_min_size[type=float64;offset=136],req_max_size[type=float64;offset=144],req_size_granularity[type=float64;offset=152],req_reject_prob[type=float64;offset=160],req_lock_cash[type=bool;offset=168],req_allow_partial[type=bool;offset=169],req_raise_reject[type=bool;offset=170],req_log[type=bool;offset=171],new_cash[type=float64;offset=176],new_position[type=float64;offset=184],new_debt[type=float64;offset=192],new_free_cash[type=float64;offset=200],new_val_price[type=float64;offset=208],new_value[type=float64;offset=216],res_size[type=float64;offset=224],res_price[type=float64;offset=232],res_fees[type=float64;offset=240],res_side[type=int64;offset=248],res_status[type=int64;offset=256],res_status_info[type=int64;offset=264],order_id[type=int64;offset=272];280;True), 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(int64, 1d, C), array(int64, 1d, C), array(Record(id[type=int64;offset=0],col[type=int64;offset=8],size[type=float64;offset=16],entry_idx[type=int64;offset=24],entry_price[type=float64;offset=32],entry_fees[type=float64;offset=40],exit_idx[type=int64;offset=48],exit_price[type=float64;offset=56],exit_fees[type=float64;offset=64],pnl[type=float64;offset=72],return[type=float64;offset=80],direction[type=int64;offset=88],status[type=int64;offset=96],parent_id[type=int64;offset=104];112;True), 1d, C), int64, int64, int64, int64, int64, array(int64, 1d, A), int64, int64, float64, float64, float64, float64, float64, float64, float64, Record(id[type=int64;offset=0],col[type=int64;offset=8],size[type=float64;offset=16],entry_idx[type=int64;offset=24],entry_price[type=float64;offset=32],entry_fees[type=float64;offset=40],exit_idx[type=int64;offset=48],exit_price[type=float64;offset=56],exit_fees[type=float64;offset=64],pnl[type=float64;offset=72],return[type=float64;offset=80],direction[type=int64;offset=88],status[type=int64;offset=96],parent_id[type=int64;offset=104];112;True)))':
No match.
During: resolving callee type: Function(<class 'str'>)
During: typing of call at /var/folders/tb/nylgytwx0gsg8xd89000w0dm0000gn/T/ipykernel_19487/776259500.py (41)
File "../../../../../../var/folders/tb/nylgytwx0gsg8xd89000w0dm0000gn/T/ipykernel_19487/776259500.py", line 41:
<source missing, REPL/exec in use?>
During: resolving callee type: type(CPUDispatcher(<function order_func_nb at 0x152e5fe50>))
During: typing of call at /Users/stanislav.gorchakov/Documents/Projects/backtests/.venv/lib/python3.9/site-packages/vectorbt/portfolio/nb.py (3019)
During: resolving callee type: type(CPUDispatcher(<function order_func_nb at 0x152e5fe50>))
During: typing of call at /Users/stanislav.gorchakov/Documents/Projects/backtests/.venv/lib/python3.9/site-packages/vectorbt/portfolio/nb.py (3019)
During: resolving callee type: type(CPUDispatcher(<function order_func_nb at 0x152e5fe50>))
During: typing of call at /Users/stanislav.gorchakov/Documents/Projects/backtests/.venv/lib/python3.9/site-packages/vectorbt/portfolio/nb.py (3019)
File "../.venv/lib/python3.9/site-packages/vectorbt/portfolio/nb.py", line 3019:
... def post_sim_func_nb(c):
<source elided>
)
order = order_func_nb(order_ctx, *pre_segment_out, *order_args)
- with
@jit(nopython=False)
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of type(CPUDispatcher(<function order_func_nb at 0x152e5ff70>)) with parameters (OrderContext(UniTuple(int64 x 2), array(int64, 1d, C), array(float64, 1d, C), bool, array(int64, 2d, F), array(bool, 2d, C), bool, bool, array(float64, 2d, F), bool, bool, bool, bool, array(Record(id[type=int64;offset=0],col[type=int64;offset=8],idx[type=int64;offset=16],size[type=float64;offset=24],price[type=float64;offset=32],fees[type=float64;offset=40],side[type=int64;offset=48];56;True), 1d, C), array(Record(id[type=int64;offset=0],group[type=int64;offset=8],col[type=int64;offset=16],idx[type=int64;offset=24],cash[type=float64;offset=32],position[type=float64;offset=40],debt[type=float64;offset=48],free_cash[type=float64;offset=56],val_price[type=float64;offset=64],value[type=float64;offset=72],req_size[type=float64;offset=80],req_price[type=float64;offset=88],req_size_type[type=int64;offset=96],req_direction[type=int64;offset=104],req_fees[type=float64;offset=112],req_fixed_fees[type=float64;offset=120],req_slippage[type=float64;offset=128],req_min_size[type=float64;offset=136],req_max_size[type=float64;offset=144],req_size_granularity[type=float64;offset=152],req_reject_prob[type=float64;offset=160],req_lock_cash[type=bool;offset=168],req_allow_partial[type=bool;offset=169],req_raise_reject[type=bool;offset=170],req_log[type=bool;offset=171],new_cash[type=float64;offset=176],new_position[type=float64;offset=184],new_debt[type=float64;offset=192],new_free_cash[type=float64;offset=200],new_val_price[type=float64;offset=208],new_value[type=float64;offset=216],res_size[type=float64;offset=224],res_price[type=float64;offset=232],res_fees[type=float64;offset=240],res_side[type=int64;offset=248],res_status[type=int64;offset=256],res_status_info[type=int64;offset=264],order_id[type=int64;offset=272];280;True), 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(int64, 1d, C), array(int64, 1d, C), array(Record(id[type=int64;offset=0],col[type=int64;offset=8],size[type=float64;offset=16],entry_idx[type=int64;offset=24],entry_price[type=float64;offset=32],entry_fees[type=float64;offset=40],exit_idx[type=int64;offset=48],exit_price[type=float64;offset=56],exit_fees[type=float64;offset=64],pnl[type=float64;offset=72],return[type=float64;offset=80],direction[type=int64;offset=88],status[type=int64;offset=96],parent_id[type=int64;offset=104];112;True), 1d, C), int64, int64, int64, int64, int64, array(int64, 1d, A), int64, int64, float64, float64, float64, float64, float64, float64, float64, Record(id[type=int64;offset=0],col[type=int64;offset=8],size[type=float64;offset=16],entry_idx[type=int64;offset=24],entry_price[type=float64;offset=32],entry_fees[type=float64;offset=40],exit_idx[type=int64;offset=48],exit_price[type=float64;offset=56],exit_fees[type=float64;offset=64],pnl[type=float64;offset=72],return[type=float64;offset=80],direction[type=int64;offset=88],status[type=int64;offset=96],parent_id[type=int64;offset=104];112;True)), array(float64, 2d, F))
During: resolving callee type: type(CPUDispatcher(<function order_func_nb at 0x152e5ff70>))
During: typing of call at /Users/stanislav.gorchakov/Documents/Projects/backtests/.venv/lib/python3.9/site-packages/vectorbt/portfolio/nb.py (3019)
File "../.venv/lib/python3.9/site-packages/vectorbt/portfolio/nb.py", line 3019:
... def post_sim_func_nb(c):
<source elided>
)
order = order_func_nb(order_ctx, *pre_segment_out, *order_args)
^
What is the best approach here to make normal debugging with print or other tools?
Run this before importing vbt:
import os
os.environ["NUMBA_DISABLE_JIT"] = "1"
@polakowo yes, it worked! Thank you a lot for quick reply!