(1) | # Define the new gate from a matrix | (2) | theta = Parameter(“theta”) | (3) | cry = np.array([ | (4) | [1, 0, 0, 0] | (5) | [0, 1, 0, 0] | (6) | [0, 0, quil_sqrt(1 − theta ∗ theta), −theta ∗ theta] | (7) | [0, 0, theta ∗ theta, quil_sqrt(1 − theta ∗ theta)] | (8) | ]) | (9) | gate_definition = DefGate(“CRY”, cry, [theta]) | (10) | CRY = gate_definition.get_constructor() | (11) | # Create our program and use the new parametric gate | (12) | p = Program( | (13) | gate_definition, X(1), H(2), H(4), H(5), X(2), X(5) | (14) | CCNOT(2, 5, 18), X(2), X(5), CRY(1) (18, 0) | (15) | SWAP(0, 1), X(10), H(11), H(12), H(13), X(14) | (16) | X(11), X(12), CCNOT(11, 12, 17), X(11), X(12) | (17) | CRY(1) (17, 9), H(19), CSWAP(19, 0, 9) | (18) | CSWAP(19, 1, 10), CSWAP(19, 2, 11) | (19) | CSWAP(19, 4, 12), CSWAP(19, 5, 13) | (20) | CSWAP(19, 6, 14), CSWAP(19, 7, 15) | (21) | CSWAP(19, 8, 16), H(19) | (22) | ) | (23) | # print the circuit | (24) | print(p) | (25) | # get a QPU, 20q − Acorn is just a string naming the device | (26) | qc = get_qc(“20q − Acorn”) | (27) | # run and measure | (28) | result = qc.run_and_measure(p, trials = 1024) |
|