-
Notifications
You must be signed in to change notification settings - Fork 90
Tensorflow Backend Questions #193
-
Hi,
Two questions about using TC with the TensorFlow backend:
- When using the Tensorflow backend and keras.Sequential, does TensorCircuit support putting additional Keras layers before the qml_layer, such as a dense layer to transform the input before being fed to a qml_layer defined in TC? If yes, would it be possible to let TC fine-tune the input embeddings? Something like this:
model = tf.keras.Sequential()
model.add(tf.keras.layers.Embedding(100, 5))
model.add(tf.keras.layers.Dense(num_params))
model.add(qml_layer)
model.add(tf.keras.layers.Dense(1, activation="sigmoid"))
- What's the best way to debug and print the variables in the debugger when using the TF backend? tf.print() doesn't seem to work?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
K = tc.set_backend("tensorflow") def f(param, weights): c = tc.Circuit(2) print(param) return 1.0 qmllayer = tc.keras.HardwareLayer(f, [2]) qmllayer(K.ones([2]))
what about this, HardwareLayer
is a non jit version wrapper for keras layer, after you debug, you can switch back to KerasLayer
Replies: 1 comment 4 replies
-
- of course, qmllayer is just a keras layer, you can compose any computational graph with all kinds of classical and quantum layers in one model
- you can always directly
print(model.variables)
outside a jitted function?
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks! Is there a good recommended way to debug and print within a quantum layer such as (when used as a Keras layer -- set run_eagerly=True doesn't seem to help):
def qlayer(x):
c = tc.Circuit(n, inputs=x)
### print here???
for j in range(max_sent_len):
for i in range(n):
c.rx(i, theta=x[i])
Beta Was this translation helpful? Give feedback.
All reactions
-
K = tc.set_backend("tensorflow") def f(param, weights): c = tc.Circuit(2) print(param) return 1.0 qmllayer = tc.keras.HardwareLayer(f, [2]) qmllayer(K.ones([2]))
what about this, HardwareLayer
is a non jit version wrapper for keras layer, after you debug, you can switch back to KerasLayer
Beta Was this translation helpful? Give feedback.
All reactions
-
One quick additional question:
If the JAX backend is used, would it be possible to use jax.lax.scan or jax.lax.fori_loop in place of standard for loops to speed up circuit compile especially for deep circuits?
Beta Was this translation helpful? Give feedback.
All reactions
-
yes, of course, pls see this nice example: https://github.com/tencent-quantum-lab/tensorcircuit/blob/master/examples/jax_scan_jit_acc.py
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1