I created a very specific circuit, and something weird is happening : if I add some doubly controlled H gates, and then their adjoint operation, I don’t get the initial state. I first thought it could be a bug, but as I’m not very experienced in quantum computing I wanted to check I didn’t do a mistake.
More concretely, here is a portion of code showing the problem:
dev = qml.device("default.qubit", wires=10, shots=5)
def CHadamard(wires):
matrix = qml.matrix(qml.Hadamard)(wires=0)
qml.ControlledQubitUnitary(matrix, control_wires=wires[0], wires=[wires[1]])
def CCHadamard(wires):
matrix = qml.matrix(CHadamard)(wires=range(2))
qml.ControlledQubitUnitary(matrix, control_wires=wires[0], wires=[wires[1],wires[2]])
@qml.qnode(dev)
def test():
qml.Hadamard(0)
qml.Hadamard(1)
qml.Hadamard(2)
qml.Hadamard(3)
qml.Hadamard(4)
qml.Hadamard(5)
qml.Hadamard(6)
CCHadamard(wires=(0,1,9))
CCHadamard(wires=(0,1,8))
qml.adjoint(CCHadamard)(wires=(0,1,8))
qml.adjoint(CCHadamard)(wires=(0,1,9))
return qml.state()
res = test()
for state in res:
if state.real < 0:
print(state)
This shows 64 states with a negative real part. However, this should display 0 state, because the CCH gates and their adjoints are supposed to cancel each other.
And if I run the same code without the CCH part, I indeed get no negative state.
What’s going on, did I miss something or is it a bug ? (if that’s the case I can of course create a github issue)
Thanks for your help.