Crash when trying to run tfq.layers
See original GitHub issueHi,
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:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.0devwe managed to re-introduce the problem somewhere. I’ll take a look into this.I will also mention that leaving
backend=Noneis 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 specifybackendin 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.Circuitsthat contain noise channels. For more info on this there is the discussion here: https://github.com/tensorflow/quantum/issues/250hey @lockwo - I really don’t remember this, so it didn’t become a bigger issue, so please close - many thanks