def su2_to_circuit(act, param): phi0, phi1, phi2 = param th0 = phi0 th1 = 1 / 2 * (phi1 + phi2) th2 = 1 / 2 * (phi1 - phi2) S = R(act, np.pi / 2) Sd = R(act, -np.pi / 2) gates = [] gates.append(expIphiZ(act, th2)) gates.append(Sd | H(act) | expIphiZ(act, th0) | H(act) | S) gates.append(expIphiZ(act, th1)) return pyqcs.list_to_circuit(gates)
def expIphiZ(act, phi): gates = R(act, -phi) | X(act) | R(act, phi) | X(act) return gates
def CRk(act, control, k): angle = 2 * np.pi / 2**(k) return R(act, angle / 2) | CX(act, control) | (R(control, angle / 2) | R( act, -angle / 2)) | CX(act, control)
def phase(act, phi): return (X(act) | R(act, phi) | X(act) | R(act, phi))
def CRX(act, control, phi): return (CX(act, control) | (H(act) | R(act, -phi) | X(act) | R(act, phi) | X(act) | H(act)) | CX(act, control))
def CR(act, control, phi): return (R(act, phi / 2) | CX(act, control) | R(act, -phi / 2) | R(control, phi / 2) | CX(act, control))
def T(act): return R(act, np.pi / 4)
def RZ(act, phi): return R(act, -phi) | X(act) | R(act, phi) | X(act)
def CRY(act, control, phi): return (CX(act, control) | (S(act) | H(act) | R(act, -phi) | X(act) | R(act, phi) | X(act) | H(act) | S(act).get_dagger()) | CX(act, control))