tonybaloney / Pyjion

Pyjion - A JIT for Python based upon CoreCLR
https://www.trypyjion.com
MIT License
1.43k stars 59 forks source link

PyjionUnboxingError: Pyjion PGC expected float, but 0.023045 is a numpy.float64. || pyjion.config(pgc=False) not working. #437

Open cryptocoinserver opened 2 years ago

cryptocoinserver commented 2 years ago
============================== EXCEPTION TRACEBACK:
  File "/usr/local/bin/jesse", line 33, in <module>
    sys.exit(load_entry_point('jesse', 'console_scripts', 'jesse')())
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/src/jesse/jesse/__init__.py", line 308, in backtest
    backtest_mode.run(start_date, finish_date, chart=chart, tradingview=tradingview, csv=csv,
  File "/home/src/jesse/jesse/modes/backtest_mode/__init__.py", line 65, in run
    simulator(candles)
  File "/home/src/jesse/jesse/modes/backtest_mode/__init__.py", line 303, in simulator
    store.orders.execute_pending_market_orders()
  File "/home/src/jesse/jesse/store/state_orders.py", line 70, in execute_pending_market_orders
    o.execute()
  File "/home/src/jesse/jesse/models/Order.py", line 169, in execute
    p._on_executed_order(self)
  File "/home/src/jesse/jesse/models/Position.py", line 352, in _on_executed_order
    self.strategy._on_updated_position(order)
  File "/home/src/jesse/jesse/strategies/Strategy.py", line 148, in _on_updated_position
    self._on_open_position(order)
  File "/home/src/jesse/jesse/strategies/Strategy.py", line 665, in _on_open_position
    submitted_order: Order = self.broker.reduce_position_at(
  File "/home/src/jesse/jesse/services/broker.py", line 91, in reduce_position_at
    if self.position.is_close:
  File "/home/src/jesse/jesse/models/Position.py", line 163, in is_close
    return self.qty == 0
=========================================================================

 Uncaught Exception: PyjionUnboxingError: Pyjion PGC expected float, but 0.023045 is a numpy.float64. Try disabling PGC pyjion.config(pgc=False) to avoid hitting this error.

The strange thing is that config doesn't seem to have an effect. This is how I use pyjion:

    pyjion.config(debug=True, pgc=False)
    pyjion.enable()

Thank you for your help.

tonybaloney commented 2 years ago

Thanks for the report. Please can you do pyjion.config(graph=True)

and send me the content of pyjion.graph(Position.is_close.__code__)

cryptocoinserver commented 2 years ago

Tried it raises this: Uncaught Exception: AttributeError: 'property' object has no attribute '__code__'

Using it initalized with self.position.is_close.__code__ : Uncaught Exception: AttributeError: 'numpy.bool_' object has no attribute '__code__'

cryptocoinserver commented 2 years ago

The code of Position.is_close:

    @property
    def is_close(self) -> bool:
        """
        Is the current position close?

        :return: bool
        """
        return self.qty == 0
cryptocoinserver commented 2 years ago

I think the project I try to use it on is just too complex.

tonybaloney commented 2 years ago

I think issue is happening because Pyjion had detected that self.qty is a float when it was assigned in the constructor, then later it was replaced with a numpy float (which is a different type)

pyjion.config(level=0) might fix it.

I'll have a think about a better solution for this.

cryptocoinserver commented 2 years ago

This setting works. It's 20 seconds slower though then without pyjion. Probably compilation time? Thanks for your support!

tonybaloney commented 2 years ago

level=0 effectively turns off the optimisations, so any opportunities to make the code faster will be disabled.

I'll look at a way of resolving this particular error so you can at least try level 1.

Code should be run at least 3 times in the same thread to see the effective performance difference