tensorflow / quantum

Hybrid Quantum-Classical Machine Learning in TensorFlow
https://www.tensorflow.org/quantum
Apache License 2.0
1.77k stars 560 forks source link

TypeError: __init__() got an unexpected keyword argument 'gate_getter' #729

Closed Shuhul24 closed 1 year ago

Shuhul24 commented 1 year ago

Following is the error occuring when the command I input is import tensorflow_quantum:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/__init__.py", line 18, in <module>
    from tensorflow_quantum.core import (append_circuit, get_expectation_op,
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/__init__.py", line 17, in <module>
    from tensorflow_quantum.core.ops import (get_expectation_op,
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/ops/__init__.py", line 18, in <module>
    from tensorflow_quantum.core.ops.circuit_execution_ops import (
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/ops/circuit_execution_ops.py", line 19, in <module>
    from tensorflow_quantum.core.ops import (cirq_ops, tfq_simulate_ops,
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/ops/cirq_ops.py", line 23, in <module>
    from tensorflow_quantum.core.ops import batch_util
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/ops/batch_util.py", line 25, in <module>
    from tensorflow_quantum.core.serialize import serializer
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/serialize/__init__.py", line 16, in <module>
    from tensorflow_quantum.core.serialize.serializer import (serialize_circuit,
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/serialize/serializer.py", line 303, in <module>
    ] + [
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/serialize/serializer.py", line 300, in <listcomp>
    _eigen_gate_serializer(g, g_name) for g, g_name in EIGEN_GATES_DICT.items()
  File "/home/shuhul.handoo/.conda/envs/shuhul/lib/python3.6/site-packages/tensorflow_quantum/core/serialize/serializer.py", line 114, in _eigen_gate_serializer
    gate_getter=lambda x: _symbol_extractor(x.exponent)),
TypeError: __init__() got an unexpected keyword argument 'gate_getter'

Following are the details for the other libraries:

tensorflow==2.6.2
cirq==0.11.0

How to resolve this?

lockwo commented 1 year ago

If you are using the latest version (either 0.7 or 0.6) of TFQ, you need to look at the requirements.txt and make sure you have them. It requires cirq 0.13.1 and TF 2.7.0.

Shuhul24 commented 1 year ago

Thanks a lot! This worked for me.