def apply_Rx(psi, theta, i, parametrize=False, **gate_opts): """Apply an X-rotation of ``theta`` to tensor network wavefunction ``psi``. """ mtags = _merge_tags({'RX'}, gate_opts) if parametrize: G = ops.PArray(rx_gate_param_gen, (float(theta), )) else: G = qu.Rx(float(theta)) psi.gate_(G, int(i), tags=mtags, **gate_opts)
def apply_Rx(psi, theta, i, **gate_opts): """Apply an X-rotation of ``theta`` to tensor network wavefunction ``psi``. """ mtags = _merge_tags({'RX'}, gate_opts) psi.gate_(qu.Rx(float(theta)), int(i), tags=mtags, **gate_opts)
itag, jtag = map(psi.site_tag, (i, j)) psi.reindex_({itag: jtag, jtag: itag}) APPLY_GATES = { 'RX': apply_Rx, 'RY': apply_Ry, 'RZ': apply_Rz, 'U3': apply_U3, 'H': build_gate_1(qu.hadamard(), tags='H'), 'X': build_gate_1(qu.pauli('X'), tags='X'), 'Y': build_gate_1(qu.pauli('Y'), tags='Y'), 'Z': build_gate_1(qu.pauli('Z'), tags='Z'), 'S': build_gate_1(qu.S_gate(), tags='S'), 'T': build_gate_1(qu.T_gate(), tags='T'), 'X_1_2': build_gate_1(qu.Rx(math.pi / 2), tags='X_1/2'), 'Y_1_2': build_gate_1(qu.Ry(math.pi / 2), tags='Y_1/2'), 'Z_1_2': build_gate_1(qu.Rz(math.pi / 2), tags='Z_1/2'), 'IDEN': lambda *args, **kwargs: None, 'CX': build_gate_2(qu.cX(), tags='CX'), 'CY': build_gate_2(qu.cY(), tags='CY'), 'CZ': build_gate_2(qu.cZ(), tags='CZ'), 'CNOT': build_gate_2(qu.CNOT(), tags='CNOT'), 'SWAP': apply_swap, } # --------------------------- main circuit class ---------------------------- # class Circuit: """Class for simulating quantum circuits using tensor networks.