def circuit(): # QHACK # # Create your circuit: the first three qubits will refer to the index, the fourth to the RY rotation. ## Create superposition of address qubits for i in range(3): qml.Hadamard(wires=i) ## Load thetas based on address for i in range(len(thetas)): binn = format(i, '03b') # rotate address qubits to 1 for j in range(len(binn)): if binn[j] == '0': qml.PauliX(wires=j) # controlled RY qml.ctrl(qml.RY, control=range(3))(thetas[i], wires=3) # uncompute address qubits for j in range(len(binn)): if binn[j] == '0': qml.PauliX(wires=j) # QHACK # return qml.state()
def test_single_par_op(self): """Test a single parametrized operation for the adjoint method of ControlledOperation""" op, par, control_wires, wires = qml.RY, np.array(0.3), qml.wires.Wires(1), [2] adjoint_of_controlled_op = qml.ctrl(op, control=control_wires)(par, wires=wires).adjoint() assert adjoint_of_controlled_op.control_wires == control_wires res_ops = adjoint_of_controlled_op.subtape.operations op1 = res_ops[0] op2 = qml.adjoint(op)(par, wires=wires) assert type(op1) == type(op2) assert op1.parameters == op2.parameters assert op1.wires == op2.wires
def test_template(self): """Test a template for the adjoint method of ControlledOperation""" op, par = qml.templates.StronglyEntanglingLayers, np.ones((1, 2, 3)) control_wires, wires = qml.wires.Wires(1), [2, 3] adjoint_of_controlled_op = qml.ctrl(op, control=control_wires)(par, wires=wires).adjoint() assert adjoint_of_controlled_op.control_wires == control_wires res_ops = adjoint_of_controlled_op.subtape.operations[0].operations expected = qml.adjoint(op)(par, wires=wires) for op1, op2 in zip(res_ops, expected): assert type(op1) == type(op2) assert op1.parameters == op2.parameters assert op1.wires == op2.wires
def test_cv_template(self): """Test a CV template that returns a list of operations for the adjoint method of ControlledOperation""" op, par = qml.templates.Interferometer, [[1], [0.3], [0.2, 0.3]] control_wires, wires = qml.wires.Wires(1), [2, 3] adjoint_of_controlled_op = qml.ctrl(op, control=control_wires)(*par, wires=wires).adjoint() assert adjoint_of_controlled_op.control_wires == control_wires res_ops = adjoint_of_controlled_op.subtape.operations[0].expand().operations expected = qml.adjoint(op)(*par, wires=wires).expand().operations for op1, op2 in zip(res_ops, expected): assert type(op1) == type(op2) assert op1.parameters == op2.parameters assert op1.wires == op2.wires
def circuit(): qml.ctrl(qml.Hadamard, control=0)(wires=1) return qml.expval(qml.PauliZ(0))