Hints for Codebook problem H.F.2

I am trying to solve H.F.2, and this is the code I have so far

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

@qml.qnode(dev)
def two_close_spins_X(alpha, beta, time, n):
    """Circuit for evolving the state of two electrons with an X coupling.
    
    Args:
        alpha (float): The coefficient related to the strength of the field, assumed to point in the z direction.
        beta (float): The coefficient related to the strength of the coupling between electrons.
        time (float): The time we evolve the electron wavefunction for.
        n (int): The number of steps in our Trotterization.

    Returns: 
        array[complex]: The quantum state after evolution.
    """
    for _ in range(n):
        qml.IsingXX(-2 * beta * time/n, wires=[0, 1])
        qml.RZ(-2 * alpha * time/n, wires=[0])
        qml.RZ(-2 * alpha * time/n, wires=[1])
    
    return qml.state()

I am getting the error Incorrect: your circuit isn't giving the right answers. Any suggestions?

I already checked the earlier discussion Stuck with H.5.2 but looks like the expected code has changed slightly.

Hi, @soham
Welcome to the forum!
You are very close to the answer.
Why are you including minus signs in the arguments for your three gates? See the definition for qml.RZ

Let me know if this was helpful.

Hi Daniela,
Thanks for the tip! That did it.

1 Like