

This is compatible with TensorFlow gradient taking and backpropagation (where you give the sum of the gradients over all observables as the gradient for a particular symbol).

This means that the gradient of a particular symbol in a circuit is equal to the sum of the gradients with regards to each observable for that symbol applied to that circuit. Defining more than one observable in TensorFlow Quantum to use along with a circuit is equivalent to adding on more terms to \(g\). Return op.expectation_from_state_vector(final_state_vector, (\alpha)\). """Compute ⟨Y(alpha)| `op` | Y(alpha)⟩"""įinal_state_vector = sim.simulate(my_circuit, params).final_state_vector Looking at this operator you know that \(⟨Y(\alpha)| X | Y(\alpha)⟩ = \sin(\pi \alpha)\) def my_expectation(op, alpha):

Falling back to DejaVu Sans.Īlong with an observable: pauli_x = cirq.X(qubit) My_circuit = cirq.Circuit(cirq.Y(qubit)**sympy.Symbol('alpha'))įindfont: Font family not found. Suppose you have a parameterized circuit like this one: qubit = cirq.GridQubit(0, 0) Let's make the notion of gradient calculation for quantum circuits a little more concrete. 11:35:46.858923: E tensorflow/stream_executor/cuda/cuda_:271] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected Now import TensorFlow and the module dependencies: import tensorflow as tf
Gradient symbol install#
Install TensorFlow Quantum: pip install tensorflow-quantum=0.7.2 # Update package resources to account for version changes. This tutorial compares and contrasts two different differentiation schemes. As a result, there are different quantum gradient calculation methods that come in handy for different scenarios. Expectation values of observables do not have the luxury of having analytic gradient formulas that are always easy to write down-unlike traditional machine learning transformations such as matrix multiplication or vector addition that have analytic gradient formulas which are easy to write down. This tutorial explores gradient calculation algorithms for the expectation values of quantum circuits.Ĭalculating the gradient of the expectation value of a certain observable in a quantum circuit is an involved process.
