You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to figure out how to run the vqe and I think my issue qiboteam/qibo#1530
was that tensorflow was moved to qiboml?
I tried
defvqe_loss(params, circuit, hamiltonian, nshots=None):
"""Evaluate the hamiltonian expectation values of the circuit final state."""circ=circuit.copy(deep=True)
circ.set_parameters(params)
ifisinstance(hamiltonian.backend, qiboml.backends.tensorflow.TensorflowBackend) andnshotsisnotNone:
expectation_value=_exp_with_tf(
circuit=circ, hamiltonian=hamiltonian, nshots=nshots
)
elifnshotsisNone:
expectation_value=_exact(circ, hamiltonian)
else:
expectation_value=_with_shots(circ=circ, ham=hamiltonian, nshots=nshots)
returnexpectation_value
and
defcompute_gradients(parameters, circuit, hamiltonian):
""" Compute gradients of circuit's parameters to check the problem trainability. The evaluated derivatives are the ones of the expectation of `hamiltonian` over the final state get running `circuit.execute` w.r.t. rotational angles. """qibo.set_backend(backend="qiboml", platform="tensorflow")
tf_backend=qibo.get_backend()
parameters=tf_backend.tf.Variable(parameters, dtype=tf_backend.tf.float64)
withtf_backend.tf.GradientTape() astape:
circuit.set_parameters(parameters)
final_state=tf_backend.execute_circuit(circuit).state()
expectation=tf_backend.calculate_expectation_state(
tf_backend.cast(hamiltonian.matrix), final_state, normalize=False
)
returnhamiltonian.backend.cast(tape.gradient(expectation, parameters))
but it sgd didn't run so I'm trying cma instead
The text was updated successfully, but these errors were encountered:
I was trying to figure out how to run the vqe and I think my issue
qiboteam/qibo#1530
was that tensorflow was moved to qiboml?
I tried
and
but it sgd didn't run so I'm trying cma instead
The text was updated successfully, but these errors were encountered: