Parametrized Quantum Circuits for Reinforcement Learning stuck if using qsim backend
Maintainers usually reply within 1 day
@mhucka is already working on this.
Since Jun 5, 2026.
Assessment
This issue has not been assessed yet.
Description
I've ran this notebook with no problem. However, if I try to use qsim as a backend by passing the backend backend = qsimcirq.QSimSimulator() explicitly to ReUploadingPQC, then I get the following message
2023-04-26 09:20:03.862016: W tensorflow/core/grappler/optimizers/loop_optimizer.cc:907] Skipping loop optimization for Merge node with control input: cond/branch_executed/_12
and it gets stuck there indefinitely.
Any idea of what might be going on?
To reproduce:
replace
def generate_model_policy(
qubits: List[cirq.GridQubit],
n_layers: int,
n_actions: int,
beta: float,
observables: List[cirq.PauliString],
) -> tf.keras.Model:
"""Generates a Keras model for a data re-uploading PQC policy."""
input_tensor = tf.keras.Input(shape=(len(qubits),), dtype=tf.dtypes.float32, name="input")
re_uploading_pqc = ReUploadingPQC(qubits, n_layers, observables)([input_tensor])
process = tf.keras.Sequential(
[Alternating(n_actions), tf.keras.layers.Lambda(lambda x: x * beta), tf.keras.layers.Softmax()],
name="observables-policy",
)
policy = process(re_uploading_pqc)
model = tf.keras.Model(inputs=[input_tensor], outputs=policy)
return model
with
def generate_model_policy(
qubits: List[cirq.GridQubit],
n_layers: int,
n_actions: int,
beta: float,
observables: List[cirq.PauliString],
backend="noiseless",
) -> tf.keras.Model:
"""Generates a Keras model for a data re-uploading PQC policy."""
input_tensor = tf.keras.Input(shape=(len(qubits),), dtype=tf.dtypes.float32, name="input")
re_uploading_pqc = ReUploadingPQC(qubits, n_layers, observables, backend=backend)([input_tensor])
process = tf.keras.Sequential(
[Alternating(n_actions), tf.keras.layers.Lambda(lambda x: x * beta), tf.keras.layers.Softmax()],
name="observables-policy",
)
policy = process(re_uploading_pqc)
model = tf.keras.Model(inputs=[input_tensor], outputs=policy)
return model
and then replace
model = generate_model_policy(qubits, n_layers, n_actions, 1.0, observables)
backend = qsimcirq.QSimSimulator()
model = generate_model_policy(qubits, n_layers, n_actions, 1.0, observables, backend=backend)
versions:
gym = "==0.22.0"
tensorflow = "2.7.0"
tensorflow-quantum = "0.7.2"
qsimcirq = "0.13.3" # <0.16.0 because of incompatibility with tensorflow-quantum
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 674
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorflow/quantum
-
area/c++ area/core kind/bug-report
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tensorflow/quantum#1140 ·
Maintainers usually reply within 1 day
-
Avoid hard-coding "quantum" in `scripts/` scriptsPossibly taken @openbotgit claimed this 23 days ago. Openarea/devops help wanted no QC knowledge needed priority/before-0.7.7
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tensorflow/quantum#1082 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
area/c++ area/core kind/bug-report
Difficulty 3/5 1-2 days Newbie friendliness 74/100
tensorflow/quantum#1141 ·
Maintainers usually reply within 1 day
-
Bug (likely typo) in `core/serialize/serializer_test.py`Possibly taken @mhucka claimed this 15 days ago. Openarea/serialization area/tests
tensorflow/quantum#1129 · 1 assignee ·
Maintainers usually reply within 1 day
-
Support Keras 3May be free again @rosspeili claimed this 118 days ago, and no pull request is open. Openarea/keras help wanted skill-level/intermediate
tensorflow/quantum#1090 · 5 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in tensorflow/quantum
Similar issues
-
release
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
MichaelYcJo/SpecSeal#1535 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
valentinfrlch/ha-llmvision#769 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 75/100
daniel-ospina/tortoise#11937 · 1 comment ·
Maintainers usually reply within 1 day
-
good first issue help wanted python up-for-grabs
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
andrewsiah/agentswarm-data-tasks#238 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
cadence-workflow/cadence-ai-samples#175 ·
Maintainers usually reply within 1 day