Ejemplo n.º 1
0
    def test_07_1_dynamic_args(self):
        "sesolve: state feedback"
        tol = 1e-3

        def f(t, args):
            return np.abs(args["state_vec"][1])

        H = [qeye(2), [destroy(2) + create(2), f]]
        res = sesolve(H,
                      basis(2, 1),
                      tlist=np.linspace(0, 10, 11),
                      e_ops=[num(2)],
                      args={"state_vec": basis(2, 1)})
        assert_(max(abs(res.expect[0][5:])) < tol,
                msg="evolution with feedback not proceding as expected")

        def f(t, args):
            return np.sqrt(args["expect_op_0"])

        H = [qeye(2), [destroy(2) + create(2), f]]
        res = sesolve(H,
                      basis(2, 1),
                      tlist=np.linspace(0, 10, 11),
                      e_ops=[num(2)],
                      args={"expect_op_0": num(2)})
        assert_(max(abs(res.expect[0][5:])) < tol,
                msg="evolution with feedback not proceding as expected")
Ejemplo n.º 2
0
def spin_fockBASIS(j, m):
    n1 = int(j + m)
    n2 = int(j - m)
    modes = int(2 * j) + 1
    vacuum = qt.tensor(qt.basis(modes, 0), qt.basis(modes, 0))
    createX = qt.tensor(qt.create(modes), qt.identity(modes))
    createY = qt.tensor(qt.identity(modes), qt.create(modes))
    first = None
    second = None
    if n1 == 0:
        first = qt.tensor(qt.identity(modes), qt.identity(modes))
    elif n1 == 1:
        first = createX
    else:
        first = functools.reduce(lambda M, N: M * N,
                                 [createX for i in range(n1)])
    if n2 == 0:
        second = qt.tensor(qt.identity(modes), qt.identity(modes))
    elif n2 == 1:
        second = createY
    else:
        second = functools.reduce(lambda M, N: M * N,
                                  [createY for i in range(n2)])
    op = (first * second) / (math.sqrt(math.factorial(j + m)) *
                             math.sqrt(math.factorial(j - m)))
    return op * vacuum  #, (n1, n2)
Ejemplo n.º 3
0
def build_momentum_SHO(dim, power, zeta):
    if power == 1:
        op = 1j * sqrt(1 / (2 * zeta)) * (create(dim) - destroy(dim))
    elif power == 2:
        op = -(create(dim)**2 + destroy(dim)**2 - 2 * num(dim) - 1) / (2 *
                                                                       zeta)
    return op
Ejemplo n.º 4
0
 def __init__(self):
     N = 3
     self.t1 = QobjEvo([qeye(N)*(1.+0.1j),[create(N)*(1.-0.1j),f]])
     self.t2 = QobjEvo([destroy(N)*(1.-0.2j)])
     self.t3 = QobjEvo([[destroy(N)*create(N)*(1.+0.2j),f]])
     self.q1 = qeye(N)*(1.+0.3j)
     self.q2 = destroy(N)*(1.-0.3j)
     self.q3 = destroy(N)*create(N)*(1.+0.4j)
Ejemplo n.º 5
0
 def __init__(self):
     N = 3
     self.t1 = QobjEvo([qeye(N)*(1.+0.1j),[create(N)*(1.-0.1j),f]])
     self.t2 = QobjEvo([destroy(N)*(1.-0.2j)])
     self.t3 = QobjEvo([[destroy(N)*create(N)*(1.+0.2j),f]])
     self.q1 = qeye(N)*(1.+0.3j)
     self.q2 = destroy(N)*(1.-0.3j)
     self.q3 = destroy(N)*create(N)*(1.+0.4j)
Ejemplo n.º 6
0
def liouvillian(omega, g, gamma, beta,n,amp):
    """Liouvillian for the coupled system of qubit and TLS"""
    A=np.zeros((n,n))
    B=np.zeros((n,n))
    Mu=np.zeros((n,n))
    for i in range (n):
      for j in range (n):
        if j-i==1:
          A[i,j]=0.5
        elif i-j==1:
          B[i,j]=0.5
    Mu=A+B

    H0_q = qutip.Qobj(omega*np.array(np.dot(qutip.create(n),qutip.destroy(n))))
    # drive qubit Hamiltonian
    H1_q = omega*Mu 

    # drift TLS Hamiltonian
    H0_T = omega*np.array(np.dot(qutip.create(n),qutip.destroy(n)))

    # Lift Hamiltonians to joint system operators
    H0 = np.kron(H0_q, np.identity(n)) + np.kron(np.identity(n), H0_T)
    H1 = np.kron(H1_q, np.identity(n))

    # qubit-TLS interaction
    H_int =  g*(np.kron(np.array(qutip.create(n)),np.array(qutip.destroy(n)))+np.kron(np.array(qutip.destroy(n)),np.array(qutip.create(n))))

    # convert Hamiltonians to QuTiP objects
    H0 = qutip.Qobj(H0 + H_int)
    H1 = qutip.Qobj(H1)

    # Define Lindblad operators
    N = 1.0 / (np.exp(beta * omega) - 1.0)
    
    L=[]
    k=0
    for i in range (0,n-1):
    # Cooling on TLS
      L.append(np.sqrt(gamma * (N + 1)) * np.kron(np.array(qutip.basis(n,i)*qutip.basis(n,i+1).dag()),np.identity(n)))
      L.append(np.sqrt(gamma * N) * np.kron(np.array(qutip.basis(n,i+1)*qutip.basis(n,i).dag()),np.identity(n)))
      L[k]=qutip.Qobj(L[k])
      L[k+1]=qutip.Qobj(L[k+1])
      k=2*(i+1)
    # convert Lindblad operators to QuTiP objects

    # generate the Liouvillian

    L0 = qutip.liouvillian(H=H0, c_ops=L)
    L1 = qutip.liouvillian(H=H1)

    # Shift the qubit and TLS into resonance by default
    eps0 = lambda t, args: amp
    return [L0, [L1, eps0]]
Ejemplo n.º 7
0
def test_create():
    "Creation operator"
    b3 = basis(5, 3)
    c5 = create(5)
    test1 = c5 * b3
    assert_equal(np.allclose(test1.full(), 2.0 * basis(5, 4).full()), True)
    c3 = create(3)
    matrix3 = np.array([[0.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j],
                        [1.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j],
                        [0.00000000 + 0.j, 1.41421356 + 0.j, 0.00000000 + 0.j]])

    assert_equal(np.allclose(matrix3, c3.full()), True)
Ejemplo n.º 8
0
def full_hamiltonian(cav_dim, w_1, w_2, w_c, g_1, g_2):
    """Return a QObj denoting the full Hamiltonian including cavity
     and two qubits"""
    a = qt.destroy(cav_dim)
    num = a.dag() * a
    return (g_1 * qt.tensor(qt.create(cav_dim), SMinus, I) +
            g_1 * qt.tensor(qt.destroy(cav_dim), SPlus, I) +
            g_2 * qt.tensor(qt.create(cav_dim), I, SMinus) +
            g_2 * qt.tensor(qt.destroy(cav_dim), I, SPlus) +
            w_c * qt.tensor(num, I, I) +
            0.5 * w_1 * qt.tensor(qt.qeye(cav_dim), SZ, I) +
            0.5 * w_2 * qt.tensor(qt.qeye(cav_dim), I, SZ))
Ejemplo n.º 9
0
def full_hamiltonian(cav_dim, w_1, w_2, w_c, g_1, g_2):
    """Return a QObj denoting the full Hamiltonian including cavity
     and two qubits"""
    a = qt.destroy(cav_dim)
    num = a.dag() * a
    return (
            g_1 * qt.tensor(qt.create(cav_dim), SMinus, I) +
            g_1 * qt.tensor(qt.destroy(cav_dim), SPlus, I) +
            g_2 * qt.tensor(qt.create(cav_dim), I, SMinus) +
            g_2 * qt.tensor(qt.destroy(cav_dim), I, SPlus) +
            w_c * qt.tensor(num, I, I) +
            0.5 * w_1 * qt.tensor(qt.qeye(cav_dim), SZ, I) +
            0.5 * w_2 * qt.tensor(qt.qeye(cav_dim), I, SZ))
Ejemplo n.º 10
0
def test_create():
    "Creation operator"
    b3 = basis(5, 3)
    c5 = create(5)
    test1 = c5 * b3
    assert_equal(np.allclose(test1.full(), 2.0 * basis(5, 4).full()), True)
    c3 = create(3)
    matrix3 = np.array([[0.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j],
                        [1.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j],
                        [0.00000000 + 0.j, 1.41421356 + 0.j,
                         0.00000000 + 0.j]])

    assert_equal(np.allclose(matrix3, c3.full()), True)
Ejemplo n.º 11
0
def liouvillian(omega, g, gamma, beta):
    """Liouvillian for the coupled system of qubit and TLS"""

    H0_q = omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2))
    # drive qubit Hamiltonian
    H1_q = -0.5*qutip.operators.sigmax()

    # drift TLS Hamiltonian
    H0_T = qutip.tensor(omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz() + qutip.qeye(2)))

    # Lift Hamiltonians to joint system operators
    H0 = qutip.tensor(H0_q, qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2)) + qutip.tensor(qutip.qeye(2), H0_T)
    H1 = qutip.tensor(H1_q, qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))

    # qubit-TLS interaction
    H_int =  g*(qutip.tensor(qutip.destroy(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2)))

    # convert Hamiltonians to QuTiP objects
    H0 = qutip.Qobj(H0 + H_int)
    H1 = qutip.Qobj(H1)

    # Define Lindblad operators
    N = 1.0 / (np.exp(beta * omega) - 1.0)
    # Cooling on TLS
    L1 = np.sqrt(gamma * (N + 1)) * qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))
    # Heating on TLS
    L2 = np.sqrt(gamma * N) *qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))
    

    # convert Lindblad operators to QuTiP objects
    L1 = qutip.Qobj(L1)
    L2 = qutip.Qobj(L2)

    # generate the Liouvillian
    L0 = qutip.liouvillian(H=H0, c_ops=[L1, L2])
    L1 = qutip.liouvillian(H=H1)

    # Shift the qubit and TLS into resonance by default
    eps0 = lambda t, args: 1
    return [L0, [L1, eps0]]
Ejemplo n.º 12
0
def f(N, options):
    wa = 1
    wc = 0.9
    delta = wa - wc
    g = 2
    kappa = 0.5
    gamma = 0.1
    n_th = 0.75
    tspan = np.linspace(0, 10, 11)

    Ia = qt.qeye(2)
    Ic = qt.qeye(N)

    a = qt.destroy(N)
    at = qt.create(N)

    sm = qt.sigmam()
    sp = qt.sigmap()

    # H = wc*qt.tensor(n, Ia) + qt.tensor(Ic, wa/2.*sz) + g*(qt.tensor(at, sm) + qt.tensor(a, sp))
    Ha = g * qt.tensor(at, sm)
    Hb = g * qt.tensor(a, sp)
    H = [[Ha, lambda t, args: np.exp(-1j*delta*t)],
         [Hb, lambda t, args: np.exp(1j*delta*t)]]
    c_ops = [
        qt.tensor(np.sqrt(kappa*(1+n_th)) * a, Ia),
        qt.tensor(np.sqrt(kappa*n_th) * at, Ia),
        qt.tensor(Ic, np.sqrt(gamma) * sm),
    ]

    psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit())
    exp_n = qt.mesolve(H, psi0, tspan, c_ops, [qt.tensor(a, sp)], options=options).expect[0]
    return np.real(exp_n)
Ejemplo n.º 13
0
def construct_2dfock_operators(modes, freq=1):
    create = qt.create(modes)
    destroy = qt.destroy(modes)
    number = qt.num(modes)
    position = (qt.destroy(modes) + qt.destroy(modes).dag()) / np.sqrt(2)
    momentum = -1j * (qt.destroy(modes) - qt.destroy(modes).dag()) / np.sqrt(2)
    operators = {"X": {}, "Y": {}}
    operators["X"]["create"] = qt.tensor(create, qt.identity(modes))
    operators["X"]["destroy"] = qt.tensor(destroy, qt.identity(modes))
    operators["X"]["number"] = qt.tensor(number, qt.identity(modes))
    operators["X"]["position"] = qt.tensor(position, qt.identity(modes))
    operators["X"]["momentum"] = qt.tensor(momentum, qt.identity(modes))
    operators["Y"]["create"] = qt.tensor(qt.identity(modes), create)
    operators["Y"]["destroy"] = qt.tensor(qt.identity(modes), destroy)
    operators["Y"]["number"] = qt.tensor(qt.identity(modes), number)
    operators["Y"]["position"] = qt.tensor(qt.identity(modes), position)
    operators["Y"]["momentum"] = qt.tensor(qt.identity(modes), momentum)
    operators["position"] = qt.tensor(position, position)
    operators["little_position"] = position
    operators["momentum"] = qt.tensor(momentum, momentum)
    operators["little_momentum"] = momentum
    operators["T"] = 2 * np.pi * freq * ((operators["X"]["destroy"].dag() * operators["X"]["destroy"] + 0.5)+\
                        (operators["Y"]["destroy"].dag() * operators["Y"]["destroy"] + 0.5))
    operators["Jx"] = (
        1. / (2)) * (operators["X"]["create"] * operators["Y"]["destroy"] +
                     operators["Y"]["create"] * operators["X"]["destroy"])
    operators["Jy"] = -1 * 1j * (
        1. / (2)) * (operators["X"]["create"] * operators["Y"]["destroy"] -
                     operators["Y"]["create"] * operators["X"]["destroy"])
    operators["Jz"] = -1 * (
        1. / (2)) * (operators["X"]["create"] * operators["X"]["destroy"] -
                     operators["Y"]["create"] * operators["Y"]["destroy"])
    return operators
Ejemplo n.º 14
0
def single_hamiltonian(cav_dim, w_1, w_c, g_factor):
    """Return a QObj denoting a hamiltonian for one qubit coupled to a
    cavity."""
    return (w_c * qt.tensor(qt.num(cav_dim), I) +
            0.5 * w_1 * qt.tensor(qt.qeye(cav_dim), I) +
            g_factor * qt.tensor(qt.create(cav_dim), SMinus) +
            g_factor * qt.tensor(qt.destroy(cav_dim), SPlus))
Ejemplo n.º 15
0
def single_hamiltonian(cav_dim, w_1, w_c, g_factor):
    """Return a QObj denoting a hamiltonian for one qubit coupled to a
    cavity."""
    return (w_c * qt.tensor(qt.num(cav_dim), I) +
            0.5 * w_1 * qt.tensor(qt.qeye(cav_dim), I) +
            g_factor * qt.tensor(qt.create(cav_dim), SMinus) +
            g_factor * qt.tensor(qt.destroy(cav_dim), SPlus))
Ejemplo n.º 16
0
def define_qubit(frequency, levels=2, eta=0.0):
    '''
    

    Parameters
    ----------
    frequency : qubit frequency
    levels : number of qubit levels to calculate. The default is 2.
    eta : inharmonicity of transmon. The default is 0.0.

    Returns
    -------
    Qobj of the qubit under fock space

    '''
    return 2 * np.pi * (frequency * qt.create(levels) * qt.destroy(levels) \
        - eta/2 * qt.create(levels) * qt.create(levels) * qt.destroy(levels) * qt.destroy(levels))
Ejemplo n.º 17
0
 def __init__(self, dim):
     self.dim = dim
     self.a = qutip.destroy(dim)
     self.adag = qutip.create(dim)
     self.x = (self.a + self.adag) / np.sqrt(2)
     self.p = -1.j * (self.a - self.adag) / np.sqrt(2)
     self.H = qutip.num(dim)
     self.id = qutip.qeye(dim)
Ejemplo n.º 18
0
def couple_qubits_x(qubits, g, ctype='xx'):
    '''
    
    
    Parameters
    ----------
    qubits : a list or 1darray of qobjs
        Qubits to be coupled in order.
    g : float or matrix of float
        Single number represents all qubits have the same coupling, 
        the dimension of array should be the same as number of qubits number.
    ctype : 'xx' or 'zz', optional
        The default is 'xx'.

    Returns
    -------
    an Qobj of coupled qubits system in total fock space

    '''
    if type(g) == float:
        gs = np.zeros((len(qubits), len(qubits)))
        gs[:] = g * 2 * np.pi
    elif len(g[0]) == len(qubits) and len(g[1]) == len(qubits):
        gs = g * 2 * np.pi
    else:
        raise ValueError('g should be float or nd matrix!')

    qblevels = []
    for i in range(len(qubits)):
        qblevels.append(qubits[i].dims[0][0])

    bdag, b, hi = [], [], []
    H0 = 0.0
    for nj in range(len(qubits)):
        opbdag, opb, oph = [], [], []
        for k in range(len(qubits)):
            if k == nj:
                opbdag.append(qt.create(qblevels[k]))
                opb.append(qt.destroy(qblevels[k]))
                oph.append(qubits[k])
            else:
                opbdag.append(qt.qeye(qblevels[k]))
                opb.append(qt.qeye(qblevels[k]))
                oph.append(qt.qeye(qblevels[k]))

        bdag.append(qt.tensor(opbdag))
        b.append(qt.tensor(opb))
        hi.append(qt.tensor(oph))

    for i in range(len(qubits)):
        H0 += hi[i]
        for j in range(i):
            if ctype == 'xx':  #XX
                H0 += gs[i][j] * (bdag[i] * b[j] + b[i] * bdag[j])
            elif ctype == 'zz':  #ZZ
                H0 += gs[i][j] * bdag[i] * b[i] * bdag[j] * b[j]

    return H0
Ejemplo n.º 19
0
def thermal_in(Q, freq, T, dims):
    kappa = Q/freq
    qubit_indices,cav_index = parse_dims(dims)
    cav_dim = dims[cav_index]
    n_therm = get_n_therm(freq, T)
    ops = [0]*len(dims)
    ops[cav_index] = qt.create(cav_dim)
    ops = [qt.qeye(2) if op == 0 else op for op in ops]
    return np.sqrt(kappa * n_therm / 2) * qt.tensor(ops)
Ejemplo n.º 20
0
def thermal_in(Q, freq, T, dims):
    kappa = Q / freq
    qubit_indices, cav_index = parse_dims(dims)
    cav_dim = dims[cav_index]
    n_therm = get_n_therm(freq, T)
    ops = [0] * len(dims)
    ops[cav_index] = qt.create(cav_dim)
    ops = [qt.qeye(2) if op == 0 else op for op in ops]
    return np.sqrt(kappa * n_therm / 2) * qt.tensor(ops)
def QRM_interaction_term(N, symmetry_sector='down'):
    Hint = -qutip.tensor(qutip.create(N) + qutip.destroy(N), qutip.sigmax())
    if symmetry_sector == 'full':
        return Hint
    elif symmetry_sector == 'up' or symmetry_sector == 'down':
        indices = _symmetry_sector_indices(N=N, which=symmetry_sector)
        return qutip.Qobj(Hint.full()[np.ix_(indices, indices)])
    else:
        raise ValueError('symmetry_sector must be `up`, `down`, or `full`.')
Ejemplo n.º 22
0
def test_N():
    H = LocalSpace(hs_name(), dimension=5)
    ad = Create(hs=H)
    a = Create(hs=H).adjoint()
    aq = qutip.dag(convert_to_qutip(a))
    assert aq == qutip.create(5)
    n = ad * a
    nq = convert_to_qutip(n)
    for k in range(H.dimension):
        assert abs(nq[k, k] - k) < 1e-10
Ejemplo n.º 23
0
def get_V_expected(dim, omega, eta):
    """
    voltage expectation operator
    """
    a  = q.destroy(dim)
    ad = q.create(dim)
    
    phi = np.sqrt(eta/float(2.0*omega))*(ad+a)
    u   = 1.0j*np.sqrt(omega/float(2.0*eta))*(ad-a)

    return eta*u
def parity_op(N):
    """Compute the parity operator for the QRM model.

    This assumes that the state lives in the FULL space (so that it was not
    already projected in a parity subspace).
    """
    operator = (qutip.tensor(qutip.create(N) * qutip.destroy(N), qutip.qeye(2)) + 
                qutip.tensor(qutip.qeye(N), (qutip.sigmaz() + qutip.qeye(2)) / 2))
    operator = scipy.linalg.expm(1j * np.pi * operator.full())
    operator = qutip.Qobj(operator)
    operator.dims = [[N, 2], [N, 2]]
    return operator
Ejemplo n.º 25
0
def get_cops(dim, omega, T_bath, gamma):
    """
    collapse operators for equidistant eigenvalues
    """
    a  = q.destroy(dim)
    ad = q.create(dim)

    if T_bath == 0:
        return [0.5*gamma*a]

    n_bath = 1.0/(np.exp(omega/T_bath)-1.0)

    return [np.sqrt(0.5*gamma*(n_bath + 1))*a, np.sqrt(0.5*gamma*n_bath)*ad]
Ejemplo n.º 26
0
def construct_1dfock_operators(modes, freq=1):
    create = qt.create(modes)
    destroy = qt.destroy(modes)
    number = qt.num(modes)
    position = (qt.destroy(modes) + qt.destroy(modes).dag()) / np.sqrt(2)
    momentum = -1j * (qt.destroy(modes) - qt.destroy(modes).dag()) / np.sqrt(2)
    energy = 2 * np.pi * freq * (destroy.dag() * destroy + 0.5)
    return {"create": create,\
            "destroy": destroy,\
            "number": number,\
            "position": position,\
            "momentum": momentum,\
            "energy": energy}
Ejemplo n.º 27
0
def hamiltonian(omega, ampl0, g):

    H0_q = omega * 0.5 * (-qutip.operators.sigmaz() + qutip.qeye(2))
    # drive qubit Hamiltonian
    H1_q = -0.5 * qutip.operators.sigmax()

    # drift TLS Hamiltonian
    H0_T = qutip.tensor(omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2))\
                        +qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)))

    # Lift Hamiltonians to joint system operators
    H0 = qutip.tensor(H0_q, qutip.qeye(2), qutip.qeye(2), qutip.qeye(2),
                      qutip.qeye(2), qutip.qeye(2),
                      qutip.qeye(2)) + qutip.tensor(qutip.qeye(2), H0_T)
    H1 = qutip.tensor(H1_q, qutip.qeye(2), qutip.qeye(2), qutip.qeye(2),
                      qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))

    # qubit-TLS interaction
    H_int =  g*(qutip.tensor(qutip.destroy(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2))\
                +qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2))\
                +qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2)))

    # convert Hamiltonians to QuTiP objects
    H0 = qutip.Qobj(H0 + H_int)
    H1 = qutip.Qobj(H1)

    def guess_control(t, args):
        return ampl0 * krotov.shapes.flattop(
            t, t_start=0, t_stop=T, t_rise=0.5, func="blackman")

    return [H0, [H1, guess_control]]
Ejemplo n.º 28
0
def get_hamiltonian(dim, eta, omega):
    """
    linear hamiltonian with range (for mesolve-cuda)
    """
    a  = q.destroy(dim)
    ad = q.create(dim)
    
    phi = np.sqrt(eta/float(2.0*omega))*(ad+a)
    u   = 1.0j*np.sqrt(omega/float(2.0*eta))*(ad-a)

    H0 = omega*(ad*a + 0.5)
    Hp = -phi/eta

    return [H0, [Hp, 'I0 * cos(wp[range_1]*t)']]
Ejemplo n.º 29
0
def get_hamiltonian_qutip(dim, eta, omega):
    """
    linear hamiltonian for qutip
    """
    a  = q.destroy(dim)
    ad = q.create(dim)
    
    phi = np.sqrt(eta/float(2.0*omega))*(ad+a)
    u   = 1.0j*np.sqrt(omega/float(2.0*eta))*(ad-a)

    H0 = omega*(ad*a + 0.5)
    Hp = -phi/eta

    return [H0, [Hp, 'I0 * cos(wp*t)']]
Ejemplo n.º 30
0
def emitter_decay_sims() -> None:
    """Runs simulations of emitter decay with non ideal MPS."""
    # Some Parameter values for the system being simulated.
    gamma = 1.0  # Decay rate of the emitter.
    delta = 0.0  # Detuning of emitter frequency from reference frequency.
    delay = 4.0 / gamma  # Delay between emitter and mirror.
    ph_mirror = 0  # Reflection phases of the mirror.
    refls_mirror = [0.2, 0.4, 0.6, 0.8, 1.0]  # reflection coefficients.
    ph_delay = np.pi  # Phase corresponding to the delay between emitter to
    # mirror and back at the reference frequency.

    # Numerical parameters.
    dims = 2  # Dimensionality of each waveguide bin.
    dt = 0.05 / gamma  # Time-step. Also used for meshing waveguide in MPS.
    num_tsteps = 1000  # Number of time-steps to perform.
    thresh = 1e-2  # Threshold at which to truncate Schmidth decomposition at
    # each step of MPS.

    # Open a h5 file for storing simulation results.
    data = h5py.File("results/impact_emitter_decay.h5", "w")
    param_grp = data.create_group("parameters")
    param_grp.create_dataset("gamma", data=gamma)
    param_grp.create_dataset("delta", data=delta)
    param_grp.create_dataset("delay", data=delay)
    param_grp.create_dataset("ph_mirror", data=ph_mirror)
    param_grp.create_dataset("refls_mirror", data=np.array(refls_mirror))
    param_grp.create_dataset("ph_delay", data=ph_delay)
    param_grp.create_dataset("dims", data=dims)
    param_grp.create_dataset("dt", data=dt)
    param_grp.create_dataset("num_tsteps", data=num_tsteps)
    param_grp.create_dataset("thresh", data=thresh)
    sim_res_grp = data.create_group("simulation_results")

    # MPS with non-ideal mirror MPS code but with reflectivity = 1.
    print("Running nonideal mirror MPS simulations.")
    results_nonideal = []
    for refl_mirror in refls_mirror:
        print("On refl_mirror = {}".format(refl_mirror))
        # Define the system.
        sys = low_dim_sys.TwoLevelSystem(gamma, delta)
        mps_ideal = oqs_mirror_mps.WgPartialMirror(qutip.basis(2, 1), delay,
                                                   refl_mirror, ph_mirror,
                                                   ph_delay, dims, sys, dt,
                                                   thresh)
        result = mps_ideal.simulate(num_tsteps,
                                    [qutip.create(2) * qutip.destroy(2)], 50)
        results_nonideal.append(result[0])
    sim_res_grp.create_dataset("mps_nonideal", data=np.array(results_nonideal))
    data.close()
Ejemplo n.º 31
0
    def _operators(self):
        self.qblevels = np.array(self.H0.dims[0])
        self.nqb = len(self.qblevels)
        self.bdag, self.b = [], []
        for nj in range(self.nqb):
            opbdag, opb = [], []
            for k in range(self.nqb):
                if k == nj:
                    opbdag.append(qt.create(self.qblevels[k]))
                    opb.append(qt.destroy(self.qblevels[k]))
                else:
                    opbdag.append(qt.qeye(self.qblevels[k]))
                    opb.append(qt.qeye(self.qblevels[k]))

            self.bdag.append(qt.tensor(opbdag))
            self.b.append(qt.tensor(opb))
def hamiltonians_n_atoms_C2(NH1, NH2, N_atoms):
    #Contructs the Jaynes_cummings hamiltonians for the interaction of each atom with C2
    #The result is given as a list of hamiltonians in the same order as in the tensor product
    hamiltonians = []
    Hd_temp = qt.tensor(qt.qeye(NH1), qt.destroy(NH2))
    Hc_temp = qt.tensor(qt.qeye(NH1), qt.create(NH2))
    for i in range(N_atoms):
        for j, H in enumerate(hamiltonians):
            hamiltonians[j] = qt.tensor(qt.qeye(2), hamiltonians[j])
        hamiltonians = [
            .5 *
            (qt.tensor(qt.sigmap(), Hd_temp) + qt.tensor(qt.sigmam(), Hc_temp))
        ] + hamiltonians
        Hd_temp = qt.tensor(qt.qeye(2), Hd_temp)
        Hc_temp = qt.tensor(qt.qeye(2), Hc_temp)
    return (hamiltonians)
def f(N, options):
    eta = 1.5
    wc = 1.8
    wl = 2.
    delta_c = wl - wc
    alpha0 = 0.3 - 0.5j
    tspan = np.linspace(0, 10, 11)

    a = qt.destroy(N)
    at = qt.create(N)
    n = at * a

    H = delta_c * n + eta * (a + at)

    psi0 = qt.coherent(N, alpha0)
    exp_n = qt.mesolve(H, psi0, tspan, [], [n], options=options).expect[0]
    return np.real(exp_n)
Ejemplo n.º 34
0
    def __init__(self, init_state, target_state, num_focks, num_steps, alpha_list=[1]):
        self.init_state = init_state
        self.target_state = target_state
        self.num_focks = num_focks

        Sp = tensor(sigmap(), qeye(num_focks))
        Sm = tensor(sigmam(), qeye(num_focks))
        a = tensor(qeye(2), destroy(num_focks))
        adag = tensor(qeye(2), create(num_focks))

        # Control Hamiltonians
        self._ctrl_hamils = [Sp + Sm, Sp * a + Sm * adag, Sp * adag + Sm * a,
                             1j * (Sp - Sm), 1j * (Sp * a - Sm * adag), 1j * (Sp * adag - Sm * a)]
        # Number operator
        self._adaga = adag * a
        self.num_steps = num_steps
        self.alpha_list = np.array(alpha_list + [0] * (3 - len(alpha_list)))
Ejemplo n.º 35
0
def _convert_local_operator_to_qutip(expr, full_space, mapping):
    """Convert a LocalOperator instance to qutip."""
    n = full_space.dimension
    if full_space != expr.space:
        all_spaces = full_space.local_factors
        own_space_index = all_spaces.index(expr.space)
        return qutip.tensor(
            *([qutip.qeye(s.dimension) for s in all_spaces[:own_space_index]] +
              [convert_to_qutip(expr, expr.space, mapping=mapping)] + [
                  qutip.qeye(s.dimension)
                  for s in all_spaces[own_space_index + 1:]
              ]))
    if isinstance(expr, Create):
        return qutip.create(n)
    elif isinstance(expr, Jz):
        return qutip.jmat((expr.space.dimension - 1) / 2.0, "z")
    elif isinstance(expr, Jplus):
        return qutip.jmat((expr.space.dimension - 1) / 2.0, "+")
    elif isinstance(expr, Jminus):
        return qutip.jmat((expr.space.dimension - 1) / 2.0, "-")
    elif isinstance(expr, Destroy):
        return qutip.destroy(n)
    elif isinstance(expr, Phase):
        arg = complex(expr.operands[1]) * arange(n)
        d = np_cos(arg) + 1j * np_sin(arg)
        return qutip.Qobj(np_diag(d))
    elif isinstance(expr, Displace):
        alpha = expr.operands[1]
        return qutip.displace(n, alpha)
    elif isinstance(expr, Squeeze):
        eta = expr.operands[1]
        return qutip.displace(n, eta)
    elif isinstance(expr, LocalSigma):
        j = expr.j
        k = expr.k
        if isinstance(j, str):
            j = expr.space.basis_labels.index(j)
        if isinstance(k, str):
            k = expr.space.basis_labels.index(k)
        ket = qutip.basis(n, j)
        bra = qutip.basis(n, k).dag()
        return ket * bra
    else:
        raise ValueError("Cannot convert '%s' of type %s" %
                         (str(expr), type(expr)))
Ejemplo n.º 36
0
def convergence_with_dt() -> None:
    """Runs simulations with different discretization dt."""
    # The parameters assumed here lead to a bound state. We only study
    # convergence of a system with these parameters.
    gamma = 1.0
    delta = 0.0
    delay = 4.0 / gamma
    ph_mirror = 0
    ph_delay = np.pi
    sim_time = 50

    # Numerical parameters.
    dims = 2  # Enough while considering a decay problem.
    dt_fdtd = 0.001  # Use a very small `dt` for FDTD simulations, since these
    # are very fast.
    thresh = 0.01

    #dt_mps = [0.15, 0.1, 0.075,  0.05, 0.025]
    dt_mps = [1.0, 0.5, 0.15, 0.1, 0.05]

    # Open h5 file for storing simulations.
    data = h5py.File("results/mps_convergence_dt.h5")
    data.create_dataset("dt", data=np.array(dt_mps))

    # Run the FDTD simulations.
    result_fdtd = fdtd.tls_ideal_mirror(gamma, delay, ph_delay, ph_mirror,
                                        dt_fdtd, int(sim_time // dt_fdtd))
    data.create_dataset("fdtd", data=np.array(result_fdtd))

    # Run the MPS simulations.
    mps_grp = data.create_group("mps")
    results_mps = []
    for dt in dt_mps:
        print("On dt = {}".format(dt))
        sys = low_dim_sys.TwoLevelSystem(gamma, delta)
        mps_ideal = oqs_mirror_mps.WgPartialMirror(qutip.basis(2, 1), delay,
                                                   1.0, ph_mirror, ph_delay,
                                                   dims, sys, dt, thresh)
        result = mps_ideal.simulate(int(sim_time // dt),
                                    [qutip.create(2) * qutip.destroy(2)], 50)
        mps_grp.create_dataset("dt_{}".format(dt), data=np.array(result[0]))
    data.close()
Ejemplo n.º 37
0
def f(N, options):
    kappa = 1.
    eta = 1.5
    wc = 1.8
    wl = 2.
    delta_c = wl - wc
    alpha0 = 0.3 - 0.5j
    tspan = np.linspace(0, 10, 11)

    a = qt.destroy(N)
    at = qt.create(N)
    n = at * a

    H = delta_c * n + eta * (a + at)
    J = [np.sqrt(kappa) * a]

    psi0 = qt.coherent(N, alpha0)
    exp_n = qt.mcsolve(H, psi0, tspan, J, [n], ntraj=evals,
                       options=options).expect[0]
    return np.real(exp_n)
def f(N, options):
    kappa = 1.
    eta = 1.5
    wc = 1.8
    wl = 2.
    # delta_c = wl - wc
    alpha0 = 0.3 - 0.5j
    tspan = np.linspace(0, 10, 11)

    a = qt.destroy(N)
    at = qt.create(N)
    n = qt.num(N)

    J = [np.sqrt(kappa) * a]
    psi0 = qt.coherent(N, alpha0)
    H = [
        wc * n, [eta * a, lambda t, args: np.exp(1j * wl * t)],
        [eta * at, lambda t, args: np.exp(-1j * wl * t)]
    ]
    alpha_t = qt.mesolve(H, psi0, tspan, J, [a], options=options).expect[0]
    return np.real(alpha_t)
Ejemplo n.º 39
0
def solve_lindblad(gamma1, gamma2, nbar_omega, nbar_delta, kappa,
                   rho0, tlist, is_mc=False, opts=None):
    # define system
    adag = qutip.create(N)
    a = adag.dag()
    H = hbar * omega * adag * a
    nbar2_omega = nbar_omega ** 2 / (1 + 2 * nbar_omega)
    # define collapse operators
    C_arr = []
    C_arr.append(gamma1 * (1 + nbar_omega) * a)
    C_arr.append(gamma2 * (1 + nbar2_omega) * a * a)
    C_arr.append(kappa * (1 + nbar_delta) * adag)
    if nbar_omega > 0:
        C_arr.append(gamma1 * nbar_omega * adag)
        C_arr.append(gamma2 * nbar2_omega * adag * adag)
    if nbar_delta > 0:
        C_arr.append(kappa * nbar_delta * a)
    # solve master eq.
    if is_mc:
        return qutip.mcsolve(H, rho0, tlist, C_arr, [])
    else:
        return qutip.mesolve(H, rho0, tlist, C_arr, [], options=opts)
Ejemplo n.º 40
0
def f(N, options):
    wa = 1
    wc = 1
    g = 2
    kappa = 0.5
    gamma = 0.1
    n_th = 0.75
    tspan = np.linspace(0, 10, 11)

    Ia = qt.qeye(2)
    Ic = qt.qeye(N)

    a = qt.destroy(N)
    at = qt.create(N)
    n = at * a

    sm = qt.sigmam()
    sp = qt.sigmap()
    sz = qt.sigmaz()

    H = wc * qt.tensor(n, Ia) + qt.tensor(
        Ic, wa / 2. * sz) + g * (qt.tensor(at, sm) + qt.tensor(a, sp))
    c_ops = [
        qt.tensor(np.sqrt(kappa * (1 + n_th)) * a, Ia),
        qt.tensor(np.sqrt(kappa * n_th) * at, Ia),
        qt.tensor(Ic,
                  np.sqrt(gamma) * sm),
    ]

    psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit())
    exp_n = qt.mcsolve(H,
                       psi0,
                       tspan,
                       c_ops, [qt.tensor(n, Ia)],
                       ntraj=evals,
                       options=options).expect[0]
    return np.real(exp_n)
Ejemplo n.º 41
0
    return nominator/denominator * M0



# Calculating steady-state solutions using the qutip library

def H(w):
    """ Hamiltonian of a spin 1/2 in B0 + Brf using the RWA. """
    return (w0 - w)/2 * qt.sigmaz() + w1/2 * qt.sigmax()

# Collsapse operators which should describe the relaxation of the system
c1 = np.sqrt(1.0/T1) * qt.destroy(2)
c2 = np.sqrt(1.0/T2)/2 * qt.destroy(2)
c3 = np.sqrt(1.0/(T1*T2)) * qt.destroy(2)
c4 = np.sqrt(1.0/T2) /2 * qt.create(2)
c5 = np.sqrt(1.0/(T1*T2)) * qt.create(2)


wHVals = np.linspace(-2 * np.pi, 6 * np.pi, 31)
MxH = [qt.expect(qt.sigmax(), qt.steadystate(H(w), [c1,c2,c3], maxiter=10)) for w in wHVals]
MyH = [qt.expect(qt.sigmay(), qt.steadystate(H(w), [c2,c5], maxiter=10)) for w in wHVals]
MzH = [qt.expect(qt.sigmaz(), qt.steadystate(H(w), [c1], maxiter=10)) for w in wHVals]

wVals = np.linspace(-2 * np.pi, 6 * np.pi, 100)

# Plot results of the algebraic formula and the solution given by qutip

plt.ylim([-1.0, 1.0])

plt.plot(wVals, Mx(wVals), label='Mx')
Ejemplo n.º 42
0
def test_create_type():
    "Operator CSR Type: create"
    op = create(5)
    assert_equal(isspmatrix_csr(op.data), True)
Ejemplo n.º 43
0
"""Helpful states and operators"""
import numpy as np
import qutip as qt

__all__ = ["I", "SX", "SY", "SZ", "iSWAP", "root_iSWAP", "SPlus", "SMinus"]

I = qt.qeye(2)
SX = qt.sigmax()
SY = qt.sigmay()
SZ = qt.sigmaz()
iSWAP = np.zeros((4,4), dtype=np.complex_)
iSWAP[0, 0], iSWAP[3,3] = 1, 1 
iSWAP[1,2],iSWAP[2,1] = 1j,1j
iSWAP = qt.Qobj(iSWAP,dims=[[2,2],[2,2]])
root_iSWAP = iSWAP.sqrtm()
#We're treating '1' as the excited state
SPlus = qt.create(2)
SMinus = qt.destroy(2)