VowpalWabbit / coba

Contextual bandit benchmarking
https://coba-docs.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
48 stars 19 forks source link

coba exception with python 3.9/3.11: ValueError: matmul: Input operand 1 has a mismatch #20

Closed arielf closed 1 year ago

arielf commented 1 year ago

First, thanks for sharing this very cool library!

The following complete-script runs fine in a python3.8 env and throws an exception with python 3.9 or python 3.11

Example of the exception with python 3.9:

% ./coba-example.py
2023-01-07 15:22:51 -- Processing chunk...
2023-01-07 15:22:51 --   * Recording Learner 0 parameters... (0.0 seconds) (completed)
2023-01-07 15:22:51 --   * Recording Learner 1 parameters... (0.0 seconds) (completed)
2023-01-07 15:22:51 --   * Recording Environment 0 statistics... (0.0 seconds) (completed)
2023-01-07 15:22:51 --   * Evaluating Learner 0 on Environment 0... (0.07 seconds) (completed)
2023-01-07 15:22:51 --   * Evaluating Learner 1 on Environment 0... (0.0 seconds) (exception)
2023-01-07 15:22:51 --   * Unexpected exception:

  File "~/.VENV/3.9/lib/python3.9/site-packages/coba/experiments/process.py", line 176, in filter
    row = list(item.task.process(learner, interactions))
  File "~/.VENV/3.9/lib/python3.9/site-packages/coba/experiments/tasks.py", line 140, in process
    learn(context, actions, action, reward, prob, **info)
  File "~/.VENV/3.9/lib/python3.9/site-packages/coba/learners/primitives.py", line 171, in learn
    self._safe_learn(context,actions,action,reward,probability,kwargs)
  File "~/.VENV/3.9/lib/python3.9/site-packages/coba/learners/primitives.py", line 237, in _safe_learn
    self._learner.learn(context, actions, action, reward, probability, **kwargs)
  File "~/.VENV/3.9/lib/python3.9/site-packages/coba/learners/linucb.py", line 101, in learn
    r = self._theta @ features

  ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 7 is different from 31)

Source code to reproduce:

#!/usr/bin/env python3

from coba.environments import Environments
from coba.learners     import RandomLearner, LinUCBLearner
from coba.experiments  import Experiment

#
# -- main
#
env = Environments.from_linear_synthetic(500, seed=5)
lrn = [ RandomLearner(), LinUCBLearner() ]

result = Experiment(env, lrn).evaluate()
result.plot_learners()
mrucker commented 1 year ago

Thanks for the kind words and for letting me know about the issue.

I'll look into it tomorrow and try to release a patch.

It should be fairly easy to fix and get a unit test in place for it.

arielf commented 1 year ago

Thanks again, just to add some info (unsure if relevant): A few python library versions in my python 3.9 env (where the exception happens) are:

numpy==1.22.3
pandas==1.4.2
scikit-learn==1.0.2
vowpalwabbit==9.1.0

Please let me know if you need any further help on this, and again thanks for all the work on Coba!

mrucker commented 1 year ago

Thanks!

I've released an update to pypi, 6.2.0, that includes a fix for this issue.

Please let me know if you have any other issues.

arielf commented 1 year ago

Thanks so much, the 6.2.0 upgrade indeed fixed the matmul issue.