def test_estimates() -> None: """ Check that the resource estimator gives reasonable results. """ b = QsharpEstimatorBackend() c = Circuit(3) c.H(0) c.CX(0, 1) c.CCX(0, 1, 2) c.Rx(0.3, 1) c.Ry(0.4, 2) c.Rz(1.1, 0) c.S(1) c.SWAP(0, 2) c.T(1) c.X(0) c.Y(1) c.Z(2) pbox = PauliExpBox([Pauli.X, Pauli.I, Pauli.Z], 0.25) c.add_pauliexpbox(pbox, [2, 0, 1]) b.compile_circuit(c, 0) resources = b.get_resources(c) assert resources["CNOT"] >= 1 assert resources["QubitClifford"] >= 1 assert resources["R"] >= 1 assert resources["T"] >= 1 assert resources["Depth"] >= 1 assert resources["Width"] == 3 assert resources["BorrowedWidth"] == 0
def test_statevector() -> None: b = AerStateBackend() circ = Circuit(3, name="test") circ.H(2) circ.X(0) circ.H(0) circ.CX(0, 1) circ.CZ(1, 2) circ.Sdg(0) circ.Tdg(1) circ.Z(1) circ.T(2) circ.Rx(0.3333, 1) circ.Rz(0.3333, 1) zxcirc = tk_to_pyzx(circ) assert zxcirc.name == circ.name b.compile_circuit(circ) state = b.get_state(circ) circ2 = pyzx_to_tk(zxcirc) assert circ2.name == circ.name b.compile_circuit(circ2) state2 = b.get_state(circ2) assert np.allclose(state, state2, atol=1e-10)
# # ## Passes # The basic mechanism of compilation is the 'pass', which is a transform that can be applied to a circuit. There is an extensive library of passes in `pytket`, and several standard ways in which they can be combined to form new passes. For example: from pytket.passes import DecomposeMultiQubitsIBM pass1 = DecomposeMultiQubitsIBM() # This pass converts all multi-qubit gates into CX and single-qubit gates. So let's create a circuit containing some non-CX multi-qubit gates: from pytket.circuit import Circuit circ = Circuit(3) circ.CRz(0.5, 0, 1) circ.T(2) circ.CSWAP(2, 0, 1) # In order to apply a pass to a circuit, we must first create a `CompilationUnit` from it. We can think of this as a 'bridge' between the circuit and the pass. The `CompilationUnit` is constructed from the circuit; the pass is applied to the `CompilationUnit`; and the transformed circuit is extracted from the `CompilationUnit`: from pytket.predicates import CompilationUnit cu = CompilationUnit(circ) pass1.apply(cu) circ1 = cu.circuit # Let's have a look at the result of the transformation: print(circ1.get_commands()) # ## Predicates