Hi. What seeds do I have to set to obtain a reproducible result when training a hybrid circuit with pennylane and tensorflow?
If I want to make the results completely different, what do I need to instantiate again to make sure it follows a different seed?
I am getting very similar results between different runs.
What I am doing is using a function to reset these seeds:
def ResetSeed(seed=None):
np.random.seed(seed) # Seed for NumPy random number generator
tf.random.set_seed(seed) # Seed for TensorFlow random number generator
keras.utils.set_random_seed(seed)
However, the results are very very similar every time.
The code is quite long so I will give you the gist of it here and maybe you can help me find out if this behaviour is expected.
I define a device and a circuit and JIT compile the circuit with circuit = tf.function(circuit, jit_compile=True)
. Then, create a layer from it with QuantumLayer = qml.qnn.KerasLayer(circuit, params_shape, output_dim=n_qubits, trainable=True)
.
In a loop I train the hybrid model 10 times with different seeds. Inside the loop, I reset the seed, define the hybrid model with Tensorflow, compile it and train it with model.fit(...)
.
Should I redefine the device, the quantum circuit and the QuantumLayer everytime I reset the seed? Or does resetting the seed afterwards already change their behaviour?
Thanks,
João