Skip to content

Crash when trying to run tfq.layers #430

@calmacx

Description

@calmacx

Hi,

I'm trying to follow some tutorial examples and came across the same problem seen in #160.
I had followed the instructions to update modules (though that seemed to be a windows fix) but it still gives me the same problem.

Mysetup

  • OS == macOS Catalina 10.15.7
  • python == 3.8.0
  • tf == 2.3.1
  • tfg == 0.5.0 (installed via pip tfq-nightly)
  • cirq == 0.9.1

Error

~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
   6841   message = e.message + (" name: " + name if name is not None else "")
   6842   # pylint: disable=protected-access
-> 6843   six.raise_from(core._status_to_exception(e.code, message), None)
   6844   # pylint: enable=protected-access
   6845 

~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: TypeError: cannot pickle 'module' object
Traceback (most recent call last):
...
File "/Users/calummacdonald/.pyenv/versions/3.8.0/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)

TypeError: cannot pickle 'module' object

 [Op:EagerPyFunc]

Code I'm trying to run

q = cirq.GridQubit(0, 0)
(a, b, c) = sp.symbols("a b c")
circuit = cirq.Circuit(
    cirq.rz(a)(q),
    cirq.rx(b)(q),
    cirq.rz(c)(q),
    cirq.rx(-b)(q),
    cirq.rz(-a)(q)
)
measurement = [cirq.X(q), cirq.Y(q), cirq.Z(q)]
outputs = tfq.layers.PQC(
    circuit,
    measurement,
    repetitions=5000,
    backend=cirq.Simulator(),
    differentiator=tfq.differentiators.ParameterShift())
quantum_data = tfq.convert_to_tensor([
    cirq.Circuit(),
    cirq.Circuit(cirq.X(q))
])
res = outputs(quantum_data)
res

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug-reportSomething doesn't seem to work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions