def test_decomp_stdgates() -> None: gate0 = qf.IdentityGate([0, 1]) gate1 = qf.canonical_decomposition(gate0).asgate() assert qf.gates_close(gate0, gate1) gate2 = qf.CNot(0, 1) gate3 = qf.canonical_decomposition(gate2).asgate() assert qf.gates_close(gate2, gate3) gate4 = qf.Swap(0, 1) gate5 = qf.canonical_decomposition(gate4).asgate() assert qf.gates_close(gate4, gate5) gate6 = qf.ISwap(0, 1) gate7 = qf.canonical_decomposition(gate6).asgate() assert qf.gates_close(gate6, gate7) gate8 = qf.CNot(0, 1)**0.5 gate9 = qf.canonical_decomposition(gate8).asgate() assert qf.gates_close(gate8, gate9) gate10 = qf.Swap(0, 1)**0.5 gate11 = qf.canonical_decomposition(gate10).asgate() assert qf.gates_close(gate10, gate11) gate12 = qf.ISwap(0, 1)**0.5 gate13 = qf.canonical_decomposition(gate12).asgate() assert qf.gates_close(gate12, gate13)
def test_gate_mul() -> None: # three cnots same as one swap gate0 = qf.IdentityGate([0, 1]) gate1 = qf.CNot(1, 0) gate2 = qf.CNot(0, 1) gate3 = qf.CNot(1, 0) gate = gate1 @ gate0 gate = gate2 @ gate gate = gate3 @ gate assert qf.gates_close(gate, qf.Swap(0, 1)) # Again, but with labels gate0 = qf.IdentityGate(["a", "b"]) gate1 = qf.CNot("b", "a") gate2 = qf.CNot("a", "b") gate3 = qf.CNot("b", "a") gate = gate1 @ gate0 gate = gate2 @ gate gate = gate3 @ gate assert qf.gates_close(gate, qf.Swap("a", "b")) gate4 = qf.X("a") _ = gate4 @ gate with pytest.raises(NotImplementedError): _ = gate4 @ 3 # type: ignore
def test_moment() -> None: circ = qf.Circuit() circ += qf.X(0) circ += qf.Swap(1, 2) moment = qf.Moment(circ) assert moment.qubits == (0, 1, 2) assert moment.run() assert moment.evolve() assert isinstance(moment.H, qf.Moment) circ += qf.Y(0) with pytest.raises(ValueError): moment = qf.Moment(circ) assert moment.asgate() assert moment.aschannel() circ1 = qf.Circuit(moment) assert len(circ1) == 2 assert isinstance(moment[1], qf.Swap) moment1 = moment.on("a", "b", "c") moment2 = moment1.rewire({"a": 0, "b": 1, "c": 2}) assert str(moment) == str(moment2)
def test_fubini_study_angle() -> None: for _ in range(REPS): theta = random.uniform(-np.pi, +np.pi) ang = qf.fubini_study_angle(qf.I(0).tensor, qf.Rx(theta, 0).su().tensor) assert np.isclose(2 * ang / abs(theta), 1.0) ang = qf.fubini_study_angle(qf.I(0).tensor, qf.Ry(theta, 0).tensor) assert np.isclose(2 * ang / abs(theta), 1.0) ang = qf.fubini_study_angle(qf.I(0).tensor, qf.Rz(theta, 0).tensor) assert np.isclose(2 * ang / abs(theta), 1.0) ang = qf.fubini_study_angle(qf.Swap(0, 1).tensor, qf.PSwap(theta, 0, 1).tensor) assert np.isclose(2 * ang / abs(theta), 1.0) ang = qf.fubini_study_angle(qf.I(0).tensor, qf.PhaseShift(theta, 0).tensor) assert np.isclose(2 * ang / abs(theta), 1.0) assert qf.fubini_study_close(qf.Rz(theta, 0).tensor, qf.Rz(theta, 0).tensor) for n in range(1, 6): eye = qf.IdentityGate(list(range(n))) assert np.isclose(qf.fubini_study_angle(eye.tensor, eye.tensor), 0.0) with pytest.raises(ValueError): qf.fubini_study_angle(qf.RandomGate([1]).tensor, qf.RandomGate([0, 1]).tensor)
def test_control_gate() -> None: gate0 = qf.ControlGate([0], qf.X(1)) gate1 = qf.CNot(0, 1) assert qf.gates_close(gate0, gate1) gateb = qf.ControlGate([1], qf.X(0)) gate2 = qf.CNot(1, 0) assert qf.gates_close(gateb, gate2) gate3 = qf.ControlGate([0], qf.Y(1)) gate4 = qf.CY(0, 1) assert qf.gates_close(gate3, gate4) gate5 = qf.ControlGate([0], qf.Z(1)) gate6 = qf.CZ(0, 1) assert qf.gates_close(gate5, gate6) gate7 = qf.ControlGate([0], qf.H(1)) gate8 = qf.CH(0, 1) assert qf.gates_close(gate7, gate8) gate9 = qf.ControlGate([0, 1], qf.X(2)) gate10 = qf.CCNot(0, 1, 2) assert qf.gates_close(gate9, gate10) gate11 = qf.ControlGate([0], qf.Swap(1, 2)) gate12 = qf.CSwap(0, 1, 2) assert qf.gates_close(gate11, gate12)
def test_circuit_to_qutip() -> None: q0, q1, q2 = 0, 1, 2 circ0 = qf.Circuit() circ0 += qf.I(q0) circ0 += qf.Ph(0.1, q0) circ0 += qf.X(q0) circ0 += qf.Y(q1) circ0 += qf.Z(q0) circ0 += qf.S(q1) circ0 += qf.T(q2) circ0 += qf.H(q0) circ0 += qf.H(q1) circ0 += qf.H(q2) circ0 += qf.CNot(q0, q1) circ0 += qf.CNot(q1, q0) circ0 += qf.Swap(q0, q1) circ0 += qf.ISwap(q0, q1) circ0 += qf.CCNot(q0, q1, q2) circ0 += qf.CSwap(q0, q1, q2) circ0 == qf.I(q0) circ0 += qf.Rx(0.1, q0) circ0 += qf.Ry(0.2, q1) circ0 += qf.Rz(0.3, q2) circ0 += qf.V(q0) circ0 += qf.H(q1) circ0 += qf.CY(q0, q1) circ0 += qf.CZ(q0, q1) circ0 += qf.CS(q1, q2) circ0 += qf.CT(q0, q1) circ0 += qf.SqrtSwap(q0, q1) circ0 += qf.SqrtISwap(q0, q1) circ0 += qf.CCNot(q0, q1, q2) circ0 += qf.CSwap(q0, q1, q2) circ0 += qf.CPhase(0.1, q1, q2) # Not yet supported # circ0 += qf.B(q1, q2) # circ0 += qf.Swap(q1, q2) ** 0.1 qbc = xqutip.circuit_to_qutip(circ0) U = gate_sequence_product(qbc.propagators()) gate0 = qf.Unitary(U.full(), qubits=[0, 1, 2]) assert qf.gates_close(gate0, circ0.asgate()) circ1 = xqutip.qutip_to_circuit(qbc) assert qf.gates_close(circ0.asgate(), circ1.asgate())
def test_circuit_params() -> None: circ = qf.Circuit() circ += qf.X(0) ** 0.3 circ += qf.Swap(1, 2) assert len(circ.params) == 1 assert circ.params == (0.3,) with pytest.raises(ValueError): _ = circ.param("theta")
def test_moment_params() -> None: circ = qf.Circuit() circ += qf.X(0)**0.3 circ += qf.Swap(1, 2) moment = qf.Moment(circ) assert len(moment.params) == 1 assert moment.params == (0.3, ) with pytest.raises(ValueError): _ = moment.param("theta")
def _cli(): gates = [ qf.I(0), qf.X(0), qf.Y(0), qf.Z(0), qf.S(0), qf.T(0), qf.H(0), qf.XPow(0.2, 0), qf.YPow(0.2, 0), qf.ZPow(0.2, 0), qf.CNot(0, 1), qf.CZ(0, 1), qf.Swap(0, 1), qf.ISwap(0, 1), qf.CCNot(0, 1, 2), qf.CCZ(0, 1, 2), qf.CSwap(0, 1, 2), ] print() print("Gate QF GOPS Cirq GOPS") # for n in range(4): # circ = benchmark_circuit(QUBITS, GATES, qf.RandomGate([0,1])) # t = timeit.timeit(lambda: circ.run(), number=REPS, # timer=time.process_time) # gops = int((GATES*REPS)/t) # gops = int((gops * 100) + 0.5) / 100.0 # print(f"gate qubits: {n} gops:{gops}") for gate in gates: circ = benchmark_circuit(QUBITS, GATES, gate) t = timeit.timeit(lambda: circ.run(), number=REPS, timer=time.process_time) cq = qf.xcirq.CirqSimulator(circ) t2 = timeit.timeit(lambda: cq.run(), number=REPS, timer=time.process_time) gops = int((GATES * REPS) / t) gops = int((gops * 100) + 0.5) / 100.0 gops2 = int((GATES * REPS) / t2) gops2 = int((gops2 * 100) + 0.5) / 100.0 if gops / gops2 > 0.8: print(gate.name, "\t", gops, "\t", gops2) else: print(gate.name, "\t", gops, "\t", gops2, "\t☹️")
def test_gate2_to_diagrams() -> None: circ = qf.Circuit() circ += qf.CNot(0, 1) circ += qf.CZ(0, 1) circ += qf.CV(0, 1) circ += qf.CV_H(0, 1) circ += qf.CH(0, 1) circ += qf.Swap(0, 1) circ += qf.ISwap(0, 1) circ += qf.CNot(0, 2) circ += qf.CZ(0, 2) circ += qf.CV(0, 2) circ += qf.CV_H(0, 2) circ += qf.CH(0, 2) circ += qf.Swap(0, 2) circ += qf.ISwap(0, 2) circ += qf.CNot(2, 1) circ += qf.CZ(2, 1) circ += qf.CV(2, 1) circ += qf.CV_H(2, 1) circ += qf.CH(2, 1) circ += qf.Swap(2, 1) circ += qf.ISwap(2, 1) print() diag = qf.circuit_to_diagram(circ) print(diag) diag = qf.circuit_to_diagram(circ, use_unicode=False) print(diag) latex = qf.circuit_to_latex(circ) if os.environ.get("QF_VIZTEST"): qf.latex_to_image(latex).show()
def test_circuit_to_circ() -> None: q0, q1, q2 = "q0", "q1", "q2" circ0 = qf.Circuit() circ0 += qf.I(q0) circ0 += qf.X(q1) circ0 += qf.Y(q2) circ0 += qf.Z(q0) circ0 += qf.S(q1) circ0 += qf.T(q2) circ0 += qf.H(q0) circ0 += qf.H(q1) circ0 += qf.H(q2) circ0 += qf.XPow(0.6, q0) circ0 += qf.YPow(0.6, q1) circ0 += qf.ZPow(0.6, q2) circ0 += qf.XX(0.2, q0, q1) circ0 += qf.YY(0.3, q1, q2) circ0 += qf.ZZ(0.4, q2, q0) circ0 += qf.CZ(q0, q1) circ0 += qf.CNot(q0, q1) circ0 += qf.Swap(q0, q1) circ0 += qf.ISwap(q0, q1) circ0 += qf.CCZ(q0, q1, q2) circ0 += qf.CCNot(q0, q1, q2) circ0 += qf.CSwap(q0, q1, q2) circ0 += qf.FSim(1, 2, q0, q1) diag0 = qf.circuit_to_diagram(circ0) # print() # print(diag0) cqc = circuit_to_cirq(circ0) # print(cqc) circ1 = cirq_to_circuit(cqc) diag1 = qf.circuit_to_diagram(circ1) # print() # print(diag1) assert diag0 == diag1
def test_cirq_simulator() -> None: q0, q1, q2 = "q0", "q1", "q2" circ0 = qf.Circuit() circ0 += qf.I(q0) circ0 += qf.I(q1) circ0 += qf.I(q2) circ0 += qf.X(q1) circ0 += qf.Y(q2) circ0 += qf.Z(q0) circ0 += qf.S(q1) circ0 += qf.T(q2) circ0 += qf.H(q0) circ0 += qf.H(q1) circ0 += qf.H(q2) circ0 += qf.XPow(0.6, q0) circ0 += qf.YPow(0.6, q1) circ0 += qf.ZPow(0.6, q2) circ0 += qf.XX(0.2, q0, q1) circ0 += qf.YY(0.3, q1, q2) circ0 += qf.ZZ(0.4, q2, q0) circ0 += qf.CZ(q0, q1) circ0 += qf.CNot(q0, q1) circ0 += qf.Swap(q0, q1) circ0 += qf.ISwap(q0, q1) circ0 += qf.CCZ(q0, q1, q2) circ0 += qf.CCNot(q0, q1, q2) circ0 += qf.CSwap(q0, q1, q2) ket0 = qf.random_state([q0, q1, q2]) ket1 = circ0.run(ket0) sim = CirqSimulator(circ0) ket2 = sim.run(ket0) assert ket1.qubits == ket2.qubits print(qf.state_angle(ket1, ket2)) assert qf.states_close(ket1, ket2) assert qf.states_close(circ0.run(), sim.run())
def test_qsim_translate() -> None: q0, q1, q2 = "q0", "q1", "q2" circ0 = qf.Circuit() circ0 += qf.H(q0) circ0 += qf.X(q1) circ0 += qf.S_H(q0) circ0 += qf.XX(0.2, q0, q1) circ0 += qf.Can(0.2, 0.1, 0.4, q0, q2) circ0 += qf.Swap(q0, q1) ket1 = circ0.run() sim = QSimSimulator(circ0, translate=True) # print(sim._circuit) ket2 = sim.run() assert qf.states_close(ket1, ket2)
def test_multiswapgate() -> None: # Should be same as a swap. perm0 = qf.MultiSwapGate([0, 1], [1, 0]) gate0 = qf.Swap(0, 1) assert qf.gates_close(perm0.asgate(), gate0) assert qf.gates_close(perm0.asgate(), perm0.H.asgate()) perm1 = qf.MultiSwapGate.from_gates(qf.Circuit([gate0])) assert qf.gates_close(perm0.asgate(), perm1.asgate()) perm2 = qf.MultiSwapGate.from_gates(qf.Circuit([perm1])) assert qf.gates_close(perm0, perm2) with pytest.raises(ValueError): qf.MultiSwapGate.from_gates(qf.Circuit(qf.CNot(0, 1))) N = 8 qubits_in = list(range(N)) qubits_out = np.random.permutation(qubits_in) permN = qf.MultiSwapGate(qubits_in, qubits_out) assert qf.gates_close(perm0.asgate(), perm1.asgate()) iden = qf.Circuit([permN, permN.H]) assert qf.almost_identity(iden.asgate()) assert qf.circuits_close(iden, qf.Circuit([qf.IdentityGate(qubits_in)])) swaps = qf.Circuit(permN.decompose()) # Add identity so we don't lose qubits swaps += qf.IdentityGate(permN.qubits_in) permN2 = qf.MultiSwapGate.from_gates(swaps) assert qf.circuits_close(swaps, qf.Circuit([permN])) assert qf.circuits_close(swaps, qf.Circuit([permN2])) assert qf.circuits_close(qf.Circuit([permN]), qf.Circuit([permN2])) with pytest.raises(ValueError): _ = qf.MultiSwapGate([0, 1], [1, 2]) # Channels assert qf.channels_close(perm0.aschannel(), gate0.aschannel()) rho0 = qf.random_state([0, 1, 3]).asdensity() rho1 = perm0.evolve(rho0) rho2 = gate0.aschannel().evolve(rho0) assert qf.densities_close(rho1, rho2)
def test_transpose_map() -> None: # The transpose map is a superoperator that transposes a 1-qubit # density matrix. Not physical. # quant-ph/0202124 q0 = 0 ops = [ qf.Unitary(np.asarray([[1, 0], [0, 0]]), [q0]), qf.Unitary(np.asarray([[0, 0], [0, 1]]), [q0]), qf.Unitary(np.asarray([[0, 1], [1, 0]]) / np.sqrt(2), [q0]), qf.Unitary(np.asarray([[0, 1], [-1, 0]]) / np.sqrt(2), [q0]), ] kraus = qf.Kraus(ops, weights=(1, 1, 1, -1)) rho0 = qf.random_density(1) rho1 = kraus.evolve(rho0) op0 = rho0.asoperator() op1 = rho1.asoperator() assert np.allclose(op0.T, op1) # The Choi matrix should be same as Swap operator choi = kraus.aschannel().choi() assert np.allclose(choi, qf.Swap(0, 2).asoperator())
def test_interchangeable() -> None: assert qf.Swap(0, 1).cv_interchangeable assert not qf.CNot(0, 1).cv_interchangeable
def test_pswap() -> None: assert qf.gates_close(qf.Swap(2, 4), qf.PSwap(0, 2, 4)) assert qf.gates_close(qf.ISwap(3, 2), qf.PSwap(np.pi / 2, 3, 2))
def test_visualize_circuit() -> None: circ = qf.Circuit() circ += qf.I(7) circ += qf.X(0) circ += qf.Y(1) circ += qf.Z(2) circ += qf.H(3) circ += qf.S(4) circ += qf.T(5) circ += qf.S_H(6) circ += qf.T_H(7) circ += qf.Rx(-0.5 * pi, 0) circ += qf.Ry(0.5 * pi, 4) circ += qf.Rz((1 / 3) * pi, 5) circ += qf.Ry(0.222, 6) circ += qf.XPow(0.5, 0) circ += qf.YPow(0.5, 2) circ += qf.ZPow(0.4, 2) circ += qf.HPow(0.5, 3) circ += qf.ZPow(0.47276, 1) # Gate with symbolic parameter # gate = qf.Rz(Symbol('\\theta'), 1) # circ += gate circ += qf.CNot(1, 2) circ += qf.CNot(2, 1) # circ += qf.IDEN(*range(8)) circ += qf.ISwap(4, 2) circ += qf.ISwap(6, 5) circ += qf.CZ(1, 3) circ += qf.Swap(1, 5) # circ += qf.Barrier(0, 1, 2, 3, 4, 5, 6) # Not yet supported in latex circ += qf.CCNot(1, 2, 3) circ += qf.CSwap(4, 5, 6) circ += qf.P0(0) circ += qf.P1(1) circ += qf.Reset(2) circ += qf.Reset(4, 5, 6) circ += qf.H(4) circ += qf.XX(0.25, 1, 4) circ += qf.XX(0.25, 1, 2) circ += qf.YY(0.75, 1, 3) circ += qf.ZZ(1 / 3, 3, 1) circ += qf.CPhase(0, 0, 1) circ += qf.CPhase(pi * 1 / 2, 0, 4) circ += qf.Can(1 / 3, 1 / 2, 1 / 2, 0, 1) circ += qf.Can(1 / 3, 1 / 2, 1 / 2, 2, 4) circ += qf.Can(1 / 3, 1 / 2, 1 / 2, 6, 5) # circ += qf.Measure(0) # circ += qf.Measure(1, 1) circ += qf.PSwap(pi / 2, 6, 7) circ += qf.Ph(1 / 4, 7) circ += qf.CH(1, 6) circ += qf.visualization.NoWire([0, 1, 2]) # circ += qf.visualization.NoWire(4, 1, 2) if os.environ.get("QF_VIZTEST"): print() print(qf.circuit_to_diagram(circ)) qf.circuit_to_diagram(circ) qf.circuit_to_latex(circ) qf.circuit_to_latex(circ, package="qcircuit") qf.circuit_to_latex(circ, package="quantikz") qf.circuit_to_diagram(circ) qf.circuit_to_diagram(circ, use_unicode=False) latex = qf.circuit_to_latex(circ, package="qcircuit") print(latex) if os.environ.get("QF_VIZTEST"): qf.latex_to_image(latex).show() latex = qf.circuit_to_latex(circ, package="quantikz") print(latex) if os.environ.get("QF_VIZTEST"): qf.latex_to_image(latex).show()
def w16_circuit() -> qf.Circuit: """ Return a circuit that prepares the the 16-qubit W state using\ sqrt(iswaps) and local gates, respecting linear topology """ gates = [ qf.X(7), qf.ISwap(7, 8)**0.5, qf.S(8), qf.Z(8), qf.Swap(7, 6), qf.Swap(6, 5), qf.Swap(5, 4), qf.Swap(8, 9), qf.Swap(9, 10), qf.Swap(10, 11), qf.ISwap(4, 3)**0.5, qf.S(3), qf.Z(3), qf.ISwap(11, 12)**0.5, qf.S(12), qf.Z(12), qf.Swap(3, 2), qf.Swap(4, 5), qf.Swap(11, 10), qf.Swap(12, 13), qf.ISwap(2, 1)**0.5, qf.S(1), qf.Z(1), qf.ISwap(5, 6)**0.5, qf.S(6), qf.Z(6), qf.ISwap(10, 9)**0.5, qf.S(9), qf.Z(9), qf.ISwap(13, 14)**0.5, qf.S(14), qf.Z(14), qf.ISwap(1, 0)**0.5, qf.S(0), qf.Z(0), qf.ISwap(2, 3)**0.5, qf.S(3), qf.Z(3), qf.ISwap(5, 4)**0.5, qf.S(4), qf.Z(4), qf.ISwap(6, 7)**0.5, qf.S(7), qf.Z(7), qf.ISwap(9, 8)**0.5, qf.S(8), qf.Z(8), qf.ISwap(10, 11)**0.5, qf.S(11), qf.Z(11), qf.ISwap(13, 12)**0.5, qf.S(12), qf.Z(12), qf.ISwap(14, 15)**0.5, qf.S(15), qf.Z(15), ] circ = qf.Circuit(gates) return circ
def test_su() -> None: su = qf.Swap(0, 1).su() assert np.isclose(np.linalg.det(su.asoperator()), 1.0)
def test_circuit_to_quirk() -> None: # 2-qubit gates quirk = "https://algassert.com/quirk#circuit={%22cols%22:[[1,%22X%22,%22%E2%80%A2%22],[%22%E2%80%A2%22,1,%22Z%22],[1,%22%E2%80%A2%22,%22Y%22],[%22Swap%22,1,%22Swap%22]]}" # noqa: E501 circ = qf.Circuit([qf.CNot(2, 1), qf.CZ(0, 2), qf.CY(1, 2), qf.Swap(0, 2)]) print() print(urllib.parse.unquote(quirk)) print(quirk_url(circuit_to_quirk(circ))) assert urllib.parse.unquote(quirk) == quirk_url(circuit_to_quirk(circ)) # 3-qubit gates quirk = "https://algassert.com/quirk#circuit={%22cols%22:[[%22%E2%80%A2%22,%22%E2%80%A2%22,%22X%22],[%22%E2%80%A2%22,%22%E2%80%A2%22,%22Z%22],[%22%E2%80%A2%22,%22Swap%22,%22Swap%22]]}" # noqa: E501 circ = qf.Circuit([qf.CCNot(0, 1, 2), qf.CCZ(0, 1, 2), qf.CSwap(0, 1, 2)]) print() print(urllib.parse.unquote(quirk)) print(quirk_url(circuit_to_quirk(circ))) assert urllib.parse.unquote(quirk) == quirk_url(circuit_to_quirk(circ)) test0 = "https://algassert.com/quirk#circuit={%22cols%22:[[%22Z%22,%22Y%22,%22X%22,%22H%22]]}" # noqa: E501 test0 = urllib.parse.unquote(test0) circ = qf.Circuit([qf.Z(0), qf.Y(1), qf.X(2), qf.H(3)]) print(test0) print(quirk_url(circuit_to_quirk(circ))) assert test0 == quirk_url(circuit_to_quirk(circ)) test_halfturns = "https://algassert.com/quirk#circuit={%22cols%22:[[%22X^%C2%BD%22,%22Y^%C2%BD%22,%22Z^%C2%BD%22],[%22X^-%C2%BD%22,%22Y^-%C2%BD%22,%22Z^-%C2%BD%22]]}" # noqa: E501 test_halfturns = urllib.parse.unquote(test_halfturns) circ = qf.Circuit( [qf.V(0), qf.SqrtY(1), qf.S(2), qf.V(0).H, qf.SqrtY(1).H, qf.S(2).H]) print(test_halfturns) print(quirk_url(circuit_to_quirk(circ))) assert test_halfturns == quirk_url(circuit_to_quirk(circ)) quarter_turns = "https://algassert.com/quirk#circuit={%22cols%22:[[%22Z^%C2%BC%22],[%22Z^-%C2%BC%22]]}" # noqa: E501 s = urllib.parse.unquote(quarter_turns) circ = qf.Circuit([qf.T(0), qf.T(0).H]) assert s == quirk_url(circuit_to_quirk(circ)) # GHZ circuit quirk = "https://algassert.com/quirk#circuit={%22cols%22:[[%22H%22],[%22%E2%80%A2%22,%22X%22],[1,%22%E2%80%A2%22,%22X%22]]}" # noqa: E501 circ = qf.Circuit([qf.H(0), qf.CNot(0, 1), qf.CNot(1, 2)]) print(urllib.parse.unquote(quirk)) print(quirk_url(circuit_to_quirk(circ))) assert urllib.parse.unquote(quirk) == quirk_url(circuit_to_quirk(circ)) test_formulaic = "https://algassert.com/quirk#circuit={%22cols%22:[[{%22id%22:%22X^ft%22,%22arg%22:%220.1%22},{%22id%22:%22Y^ft%22,%22arg%22:%220.2%22},{%22id%22:%22Z^ft%22,%22arg%22:%220.3%22}],[{%22id%22:%22Rxft%22,%22arg%22:%220.4%22},{%22id%22:%22Ryft%22,%22arg%22:%220.5%22},{%22id%22:%22Rzft%22,%22arg%22:%220.6%22}]]}" # noqa: E501 s = urllib.parse.unquote(test_formulaic) circ = qf.Circuit([ qf.XPow(0.1, 0), qf.YPow(0.2, 1), qf.ZPow(0.3, 2), qf.Rx(0.4, 0), qf.Ry(0.5, 1), qf.Rz(0.6, 2), ]) assert s == quirk_url(circuit_to_quirk(circ))