Hi everyone,
I’m working on the QSVT exercise where we need to implement the circuit_cos(t)
and circuit_sin(t)
In my circuit_cos(t)
implementation, I apply a Hadamard to the control wire, then call block_encode()
once (controlled on wire 1), and finally apply all the phase gates from cos_projectors(t)
in order, followed by another Hadamard.
However, I keep getting the error:
Incorrect: your cosine circuit isn't quite right yet!
Here is my entire code:
control_wires = [2,3]
work_wires = [4,5]
dev = qml.device("default.qubit")
@qml.qnode(dev)
def circuit_cos(t):
"""
Uses QSVT to apply an approximate cosine transformation to a block-encoded matrix
"""
qml.Hadamard(wires=1) # QSP starts with Hadamard on the control wire
qml.ctrl(block_encode, control=1)
for gate in cos_projectors(t):
qml.apply(gate)
qml.Hadamard(wires=1)
return qml.state()
matrix_1 = qml.matrix(circuit_cos, wire_order=[1] + control_wires + work_wires)(0.5)
print("The cosine of the H*t for t = 0.5 is: \n")
print(np.round(matrix_1[: 2 ** len(work_wires), : 2 ** len(work_wires)], 4))
@qml.qnode(dev)
def circuit_sin(t):
"""
Uses QSVT to apply an approximate sine transformation to a block-encoded matrix
"""
qml.Hadamard(wires=1) # QSP starts with Hadamard on the control wire
qml.ctrl(block_encode, control=1)
for gate in sin_projectors(t):
qml.apply(gate)
qml.Hadamard(wires=1)
return qml.state()
matrix_2 = qml.matrix(circuit_sin, wire_order=[1] + control_wires + work_wires)(0.5)
print("The sine of the H*t for t = 0.5 is: \n")
print(np.round(matrix_2[: 2 ** len(work_wires), : 2 ** len(work_wires)], 4))
I’m not sure what I’m missing. Could it be the order of operations in the QSP sequence?
Any help or clarification would be greatly appreciated!
Thanks in advance!