示例#1
0
def dict_to_qutip(dictrep, encoded_params=None):
    """
    Takes a DictRep Ising Hamiltonian and converts it to a QuTip Ising Hamiltonian.
    Encoded params must be passed if dictrep weights are variables (abstract) and
    not actual numbers.
    """
    # make useful operators
    sigmaz = qto.sigmaz()
    nqbits = len(dictrep.qubits)
    zeros = [qto.qzero(2) for m in range(nqbits)]
    finalH = qt.tensor(*zeros)

    for key, value in dictrep.H.items():
        if key[0] == key[1]:
            if encoded_params:
                finalH += encoded_params[value] * nqubit_1pauli(
                    sigmaz, key[0], nqbits)
            else:
                finalH += value * nqubit_1pauli(sigmaz, key[0], nqbits)
        else:
            if encoded_params:
                finalH += encoded_params[value] * nqubit_2pauli(
                    sigmaz, sigmaz, key[0], key[1], nqbits)
            else:
                finalH += value * nqubit_2pauli(sigmaz, sigmaz, key[0], key[1],
                                                nqbits)

    return finalH
示例#2
0
文件: utils.py 项目: naezzell/qanic
def dict_to_qutip(dictH):
    """
    Converts ising H to QuTip Hz and makes QuTip Hx of D-Wave
    in the process to avoid redundant function calls.
    """
    # make useful operators
    X = qto.sigmax()
    Z = qto.sigmaz()
    nqbits = len([key for key in dictH.keys() if key[0] == key[1]])
    Hx = sum([nqubit_1pauli(X, m, nqbits) for m in range(nqbits)])
    
    zeros = [qto.qzero(2) for m in range(nqbits)]
    Hz = qt.tensor(*zeros)

    for key, value in dictH.items():
        if key[0] == key[1]:
            Hz += value*nqubit_1pauli(Z, key[0], nqbits)
        else:
            Hz += value*nqubit_2pauli(Z, Z, key[0], key[1], nqbits)

    return [Hz, Hx]
示例#3
0
def ode2es(L, rho0):
    """Creates an exponential series that describes the time evolution for the
    initial density matrix (or state vector) `rho0`, given the Liouvillian
    (or Hamiltonian) `L`.

    .. deprecated:: 4.6.0
        :obj:`~ode2es` will be removed in QuTiP 5.  Please use
        :obj:`Qobj.eigenstates` to get the eigenstates and -values, and use
        :obj:`~QobjEvo` for general time-dependence.

    Parameters
    ----------
    L : qobj
        Liouvillian of the system.

    rho0 : qobj
        Initial state vector or density matrix.

    Returns
    -------
    eseries : :class:`qutip.eseries`
        ``eseries`` represention of the system dynamics.

    """
    if issuper(L):
        # check initial state
        if isket(rho0):
            # Got a wave function as initial state: convert to density matrix.
            rho0 = rho0 * rho0.dag()
        # check if state is below error threshold
        if abs(rho0.full()).sum() < 1e-10 + 1e-24:
            # enforce zero operator
            return eseries(qzero(rho0.dims[0]))
        w, v = L.eigenstates()
        v = np.hstack([ket.full() for ket in v])
        # w[i]   = eigenvalue i
        # v[:,i] = eigenvector i

        rlen = np.prod(rho0.shape)
        r0 = mat2vec(rho0.full())
        v0 = la.solve(v, r0)
        vv = v * sp.spdiags(v0.T, 0, rlen, rlen)

        out = None
        for i in range(rlen):
            qo = Qobj(vec2mat(vv[:, i]), dims=rho0.dims, shape=rho0.shape)
            if out:
                out += eseries(qo, w[i])
            else:
                out = eseries(qo, w[i])

    elif isoper(L):

        if not isket(rho0):
            raise TypeError('Second argument must be a ket if first' +
                            'is a Hamiltonian.')

        # check if state is below error threshold
        if abs(rho0.full()).sum() < 1e-5 + 1e-20:
            # enforce zero operator
            dims = rho0.dims
            return eseries(
                Qobj(sp.csr_matrix((dims[0][0], dims[1][0]), dtype=complex)))

        w, v = L.eigenstates()
        v = np.hstack([ket.full() for ket in v])
        # w[i]   = eigenvalue i
        # v[:,i] = eigenvector i

        rlen = np.prod(rho0.shape)
        r0 = rho0.full()
        v0 = la.solve(v, r0)
        vv = v * sp.spdiags(v0.T, 0, rlen, rlen)

        out = None
        for i in range(rlen):
            qo = Qobj(np.array(vv[:, i]).T, dims=rho0.dims, shape=rho0.shape)
            if out:
                out += eseries(qo, -1.0j * w[i])
            else:
                out = eseries(qo, -1.0j * w[i])

    else:
        raise TypeError('First argument must be a Hamiltonian or Liouvillian.')

    return estidy(out)
示例#4
0
def ode2es(L, rho0):
    """Creates an exponential series that describes the time evolution for the
    initial density matrix (or state vector) `rho0`, given the Liouvillian
    (or Hamiltonian) `L`.

    Parameters
    ----------
    L : qobj
        Liouvillian of the system.

    rho0 : qobj
        Initial state vector or density matrix.

    Returns
    -------
    eseries : :class:`qutip.eseries`
        ``eseries`` represention of the system dynamics.

    """

    if issuper(L):

        # check initial state
        if isket(rho0):
            # Got a wave function as initial state: convert to density matrix.
            rho0 = rho0 * rho0.dag()

        # check if state is below error threshold
        if abs(rho0.full().sum()) < 1e-10 + 1e-24:
            # enforce zero operator
            return eseries(qzero(rho0.dims[0]))

        w, v = L.eigenstates()
        v = np.hstack([ket.full() for ket in v])
        # w[i]   = eigenvalue i
        # v[:,i] = eigenvector i

        rlen = np.prod(rho0.shape)
        r0 = mat2vec(rho0.full())
        v0 = la.solve(v, r0)
        vv = v * sp.spdiags(v0.T, 0, rlen, rlen)

        out = None
        for i in range(rlen):
            qo = Qobj(vec2mat(vv[:, i]), dims=rho0.dims, shape=rho0.shape)
            if out:
                out += eseries(qo, w[i])
            else:
                out = eseries(qo, w[i])

    elif isoper(L):

        if not isket(rho0):
            raise TypeError("Second argument must be a ket if first" + "is a Hamiltonian.")

        # check if state is below error threshold
        if abs(rho0.full().sum()) < 1e-5 + 1e-20:
            # enforce zero operator
            dims = rho0.dims
            return eseries(Qobj(sp.csr_matrix((dims[0][0], dims[1][0]), dtype=complex)))

        w, v = L.eigenstates()
        v = np.hstack([ket.full() for ket in v])
        # w[i]   = eigenvalue i
        # v[:,i] = eigenvector i

        rlen = np.prod(rho0.shape)
        r0 = rho0.full()
        v0 = la.solve(v, r0)
        vv = v * sp.spdiags(v0.T, 0, rlen, rlen)

        out = None
        for i in range(rlen):
            qo = Qobj(np.matrix(vv[:, i]).T, dims=rho0.dims, shape=rho0.shape)
            if out:
                out += eseries(qo, -1.0j * w[i])
            else:
                out = eseries(qo, -1.0j * w[i])

    else:
        raise TypeError("First argument must be a Hamiltonian or Liouvillian.")

    return estidy(out)