Consider a simple Hamiltonian coupling two qubits:

The eigenvectors are just the computational basis states , with eigenvalues . To implement the unitary which evolves by time , we need to build a gate with the following action on basis states:

As you will check in a moment, this can be done using the following (non-trivial) circuit involving CNOTs and a rotation:

where .


Implement the circuit drawn above, allowing for the specification of an initial computational basis state.

Tip. Try using qml.BasisState to prepare the basis state.

n_bits = 2
dev = qml.device("default.qubit", wires=n_bits)

@qml.qnode(dev)
def zz_circuit(alpha, time, init):
"""Circuit for evolving two electrons with a ZZ interaction.
Args:
alpha (float): The strength of the interaction.
time (float): The time we evolve the electron wavefunction for.
init (numpy.array(int)): An initial state specified by two bits [x, y]. Prepare the
system in this state prior to applying the time evolution circuit.

Returns:
array[float]: Probabilities for observing different outcomes.
"""

##################
# YOUR CODE HERE #
##################
return qml.probs(wires=range(n_bits))

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Describe the utility of diagonalizing a Hamiltonian for simulation, and diagonalize a simple case.
  • See how nontrivial computational problems can be encoded in ground states.