secondmind-labs/trieste

cannot pickle '_thread.RLock' object

amehrish opened this issue · 6 comments

TypeError: cannot pickle '_thread.RLock' object

I installed trieste on Windows-11 with tensorflow-gpu==2.10 with Python 3.8 and tried to run the very first example in your documentation: https://secondmind-labs.github.io/trieste/2.0.0/notebooks/expected_improvement.html as a PyCharm script

The problem is with this snippet:
bo = trieste.bayesian_optimizer.BayesianOptimizer(observer, search_space)

I get:

TypeError: cannot pickle '_thread.RLock' object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\abhin\AppData\Local\Programs\Python\Python38\lib\site-packages\trieste\bayesian_optimizer.py", line 721, in optimize
raise NotImplementedError(
NotImplementedError: Failed to save the optimization state. Some models do not support deecopying or serialization and cannot be saved. (This is particularly common for deep neural network models, though some of the model wrappers accept a model closure as a workaround.) For these models, the track_state`` argument of the :meth:~trieste.bayesian_optimizer.BayesianOptimizer.optimizemethod should be set toFalse`. This means that only the final model will be available.

System information

  • OS: windows-11
  • Python version: 3.8
  • Trieste version: 2.0.0
  • TensorFlow version: tensorflow-gpu==2.10
  • GPflow version: 2.9.0

Additional context
I dont expect this to be a bug because the nature of this error is so elementary that you would have seen it. Usually,
TypeError: cannot pickle '_thread.RLock' object is a threading vs multiproc error. How should I amend this call so as to avoid this error? Thank you!

I am getting exactly the same problem with tensorflow 2.12 on Linux-UBuntu:

My tensorflow/ System information:

OS: Linux-Ubuntu Focal Fossa 20.04
Python version: 3.8
Trieste version: 2.0.0
TensorFlow version: tensorflow==2.12
GPflow version: 2.9.0

Note that I have tensorflow working with tensorrt and CUDA 11.8

Thanks for raising this! Just to confirm: are you simply trying to run the expected improvement notebook, unmodified, in PyCharm? If so, could you please include the full stack trace of the error? That specific error usually happens when the code tries to save an unsupported model, but this shouldn't be happening here! Also the notebook is running fine in our tests.

Also, how did you set up your virtual environment? To use the constraints used in our tests you can run the following command in the top level directory of the repository:

pip install . -r notebooks/requirements.txt -c notebooks/constraints.txt

Update: this may be an issue with the latest release of gpflow (2.9.0). We're working on a fix, but for now downgrading to 2.8.1 may fix it.

Thank you for looking into it. I followed your instructions for installation of dependencies. On Windows, it creates a new problem with tensorflow-gpu==2.10 which Trieste doesnt recognise. I am reporting it here only becasue you advised regarding the "requirements" and "constraints" files which I duly followed for Linux bit not for Windows. I created my Virtual env on Linux from scratch and only maintain it from pip (no conda). On windows, it might be just a case of version name dependency check. As you are very well aware that Tensorflow GPU is not available or cannot be built from source for Windows after 2.10, upgrading to 2.12 is not an option. I cant imagine tensorflow of much use for heavy models without a GPU and want to avoid WSL as I use Linux separately. I will downgrade gpflow as per your suggestion. Thank you!

I can confirm that after downgrading to gpflow 2.8.1, the error was not encountered.

Thank you for investigating further and I'm glad downgrading worked. We've now release gpflow 2.9.1 with a fix, so you should be able to upgrade again if you like.