question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash when trying to run tfq.layers

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MichaelBroughtoncommented, Nov 12, 2020

Hmmm looks like either the windows fix didn’t translate well over to Mac or over the course of releases from 0.3.1 -> 0.5.0dev we managed to re-introduce the problem somewhere. I’ll take a look into this.

I will also mention that leaving backend=None is definitely the preferred method of use when doing simulations with TensorFlow Quantum. It is the fastest and most reliable going directly through to qsim. We initially wanted to be able to specify backend in order to support using backends like this which are not super fast (since you’re already going over the internet and through a lot of other software layers). It turns out that you can use other simulation backends, but that was really just a nice bonus and they are unlikely to be any faster than the default C++ backend that is provided.

Going forward we do plan to incorporate noisy simulation capabilities into qsim so that our fast C++ backends can support cirq.Circuits that contain noise channels. For more info on this there is the discussion here: https://github.com/tensorflow/quantum/issues/250

0reactions
calmacxcommented, Aug 24, 2022

hey @lockwo - I really don’t remember this, so it didn’t become a bigger issue, so please close - many thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common issues - TensorFlow 2 Object Detection API tutorial
Below is a list of common issues encountered while using TensorFlow for objects detection. Python crashes - TensorFlow GPU¶. If you are using...
Read more >
tfq.layers.NoisyPQC | TensorFlow Quantum
This layer is for training noisy parameterized quantum models. Given a parameterized circuit, this layer initializes the parameters and manages them in a ......
Read more >
python - Why does adding convolution/pool layer crash Keras ...
I recognized this was a package included in the cudnn library and copy and pasted it from the bin folder in cudnn to...
Read more >
Game crashed and this window appeared , doesn't anyone ...
You don't have enough RAM to run tf2 at your current settings. ... Check your console during the game if it's full of...
Read more >
Team Fortress 2 - PCGamingWiki PCGW - bugs, fixes, crashes ...
Official wiki - Run by the TF2 community and hosted by Valve ... This is caused by multiple players trying to connect to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found