array([[-0.8448179 , 0.53505394, 0. ], [-0.36817031, -0.92975837, 1. ]]) ''' # Step A: prepare the index qubit and ancilla qubit in superposition qc.h(q[0]) qc.h(q[1]) # Step B: entangle the test data (0.053, 0.999) with the ground state of the ancilla qc.cry(2 * math.acos(-0.36817031), q[0], q[2]) # qc.cu3(0, 0, math.pi, q[0], q[2]) qc.cz(q[0], q[2]) qc.x(q[0]) # Step C: entangle the training data (0, 1) with the excited state of the ancilla and the ground state of the index qubit qc.ccry(2 * math.acos(-0.99407732), q[0], q[1], q[2]) # qc.ccrz(math.pi, q[0], q[1], q[2]) qc.ccz(q[0], q[1], q[2]) qc.x(q[1]) # Step D: entangle the training data (0.789, 0.615) with the excited state of the ancilla and of the index qubit qc.ccry(2 * math.acos(-0.92072409), q[0], q[1], q[2]) # qc.ccrz(math.pi, q[0], q[1], q[2]) qc.ccz(q[0], q[1], q[2]) # Step E: Swap the data and the class qubits (due to the topology of IBM 5 QX) # and the class qubit is flipped given the index qubit is 1 qc.swap(q[2], q[3]) qc.cx(q[1], q[2]) # Step F: Hadamard gate on the ancilla qubit and measurement
''' # Step A: prepare the index qubit and ancilla qubit in superposition qc.h(q[0]) qc.h(q[1]) # Step B: entangle the test data with the ground state of the ancilla qc.cry(2 * math.acos(-0.26461538), q[0], q[2]) # qc.cry(2 * (2 * pi - math.acos(-0.23192983)), q[0], q[2]) # qc.cry(2 * math.acos(-0.23192983), q[0], q[2]) # qc.crz(math.pi, q[0], q[2]) # qc.cz(q[0], q[2]) qc.x(q[0]) # Step C: entangle the training data with the excited state of the ancilla and the ground state of the index qubit qc.ccry(2 * math.acos(-0.65752458), q[0], q[1], q[2]) qc.x(q[1]) # Step D: entangle the training data with the excited state of the ancilla and of the index qubit # qc.ccry(2 * (2 * pi - math.acos(0.92790088)), q[0], q[1], q[2]) qc.ccry(2 * math.acos(0.92790088), q[0], q[1], q[2]) # qc.ccrz(math.pi, q[0], q[1], q[2]) qc.ccz(q[0], q[1], q[2]) # Step E: Swap the data and the class qubits (due to the topology of IBM 5 QX) # and the class qubit is flipped given the index qubit is 1 qc.swap(q[2], q[3]) qc.cx(q[1], q[2]) # Step F: Hadamard gate on the ancilla qubit and measurement qc.h(q[0])
# Second test example # Step A: prepare the index qubit and ancilla qubit in superposition qc.h(q[0]) qc.h(q[1]) # Step B: entangle the test data (0.053, 0.999) with the ground state of the ancilla qc.cry(2 * math.acos(0.053), q[0], q[2]) qc.x(q[0]) # Step C: entangle the training data (0, 1) with the excited state of the ancilla and the ground state of the index qubit qc.ccx(q[0], q[1], q[2]) qc.x(q[1]) # Step D: entangle the training data (0.789, 0.615) with the excited state of the ancilla and of the index qubit qc.ccry(2 * math.acos(0.789), q[0], q[1], q[2]) # Step E: Swap the data and the class qubits (due to the topology of IBM 5 QX) # and the class qubit is flipped given the index qubit is 1 qc.swap(q[2], q[3]) qc.cx(q[1], q[2]) # Step F: Hadamard gate on the ancilla qubit and measurement qc.h(q[0]) # Measurement qc.barrier(q) qc.measure(q[0], c[3]) qc.measure(q[1], c[2]) qc.measure(q[2], c[1]) qc.measure(q[3], c[0])