Esempio n. 1
0
 def _optimize(self, c):
     c_tket = pyzx_to_tk(c)
     cost = lambda c : c.n_gates_of_type(OpType.CX)
     comp = RepeatWithMetricPass(SequencePass([CommuteThroughMultis(), RemoveRedundancies()]), cost)
     comp.apply(c_tket)
     c_opt = tk_to_pyzx(c_tket)
     return c_opt
Esempio n. 2
0
    def _optimize(self, c):
        c_tket = pyzx_to_tk(c)
        FullPeepholeOptimise().apply(c_tket)

        # FIXME: Failing equality!
        # RebasePyZX().apply(c_tket)
        # c_opt = tk_to_pyzx(c_tket)

        # FIXME: Failing equality!
        qasm_str = circuit_to_qasm_str(c_tket)
        c_opt = zx.Circuit.from_qasm(qasm_str)

        return c_opt
def tket_pass_base(c, g, _pass):
    orig_tcount = c.tcount()
    orig_2qubitcount = c.twoqubitcount()

    c_tket = pyzx_to_tk(c)
    _pass.apply(c_tket)
    RebasePyZX().apply(c_tket)
    c_opt = tk_to_pyzx(c_tket)

    opt_tcount = c_opt.tcount()
    opt_2qubitcount = c_opt.twoqubitcount()

    # Quick and dirty. In theory, should depend on score function
    if orig_tcount == opt_tcount and orig_2qubitcount == opt_2qubitcount:
        return False, (c, g)
    return True, (c_opt, c_opt.to_graph())
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)
Esempio n. 5
0
 def _optimize(self, c):
     c_tket = pyzx_to_tk(c)
     RemoveRedundancies().apply(c_tket)
     c_opt = tk_to_pyzx(c_tket)
     return c_opt