Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NeuralNetworkClassifier save error #601

Closed
prncoprs opened this issue Apr 13, 2023 · 2 comments
Closed

NeuralNetworkClassifier save error #601

prncoprs opened this issue Apr 13, 2023 · 2 comments

Comments

@prncoprs
Copy link

Environment

  • Qiskit Machine Learning version: 0.6.0
  • Python version: 3.11.2
  • Operating system: MacOS 13.3.1

What is happening?

When I run the 11_quantum_convolutional_neural_networks.ipynb to learn, I want to save the classifier model, and I run the following code.

classifier.save("qcnn.classifier")

However, it will produce following error logs.

Traceback (most recent call last):
  File "/Users/xxx/Projects/iu/qaml-qiskit/qcnn.py", line 246, in <module>
    classifier.save("qcnn.classifier")
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/qiskit_machine_learning/algorithms/serializable_model.py", line 36, in save
    dill.dump(self, handler)
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/dill/_dill.py", line 336, in dump
    Pickler(file, protocol, **_kwds).dump(obj)
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/dill/_dill.py", line 620, in dump
    StockPickler.dump(self, obj)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 487, in dump
    self.save(obj)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 603, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 717, in save_reduce
    save(state)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self
    ^^^^^^^^^^^^
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/dill/_dill.py", line 1251, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 972, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 998, in _batch_setitems
    save(v)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self
    ^^^^^^^^^^^^
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/dill/_dill.py", line 1963, in save_function
    _save_with_postproc(pickler, (_create_function, (
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/dill/_dill.py", line 1140, in _save_with_postproc
    pickler.save_reduce(*reduction, obj=obj)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 692, in save_reduce
    save(args)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self
    ^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 902, in save_tuple
    save(element)
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self
    ^^^^^^^^^^^^
  File "/Users/xxx/Projects/iu/qaml-qiskit/venv/lib/python3.11/site-packages/dill/_dill.py", line 1187, in save_code
    obj.co_firstlineno, obj.co_lnotab, obj.co_endlinetable,
                                       ^^^^^^^^^^^^^^^^^^^
AttributeError: 'code' object has no attribute 'co_endlinetable'. Did you mean: 'co_linetable'?

Process finished with exit code 1

How can we reproduce the issue?

Run the code in 11_quantum_convolutional_neural_networks.ipynb](https://github.com/Qiskit/qiskit-machine-learning/blob/main/docs/tutorials/11_quantum_convolutional_neural_networks.ipynb), and try to save the model using following code.

classifier.save("qcnn.classifier")

What should happen?

The classifier should be saved into a file.

Any suggestions?

No response

@woodsp-ibm
Copy link
Member

What version of dill are you using. I believe that was a 3.11 issue in dill that was corrected in their 0.3.6 release.

Note that Qiskit ML does not yet officially support 3.11 #512

I will also note dill was pinned here earlier #498 so installing 0.3.6 would conflict with that in your installation. Can you use an earlier Python e.g. 3.10?

@prncoprs
Copy link
Author

Thanks for your help! I changed to 3.10 and it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants