How to use the qutip.basis function in qutip

To help you get started, we’ve selected a few qutip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SoftwareQuTech / SimulaQron / tests / auto / pythonLib / test_single_qubit.py View on Github external
def prep_rot_qutip(n, a):
    q = qutip.basis(2)
    nNorm = np.linalg.norm(n)
    R = (-1j * a / (2 * nNorm) * (n[0] * qutip.sigmax() + n[1] * qutip.sigmay() + n[2] * qutip.sigmaz())).expm()
    return R * q
github SoftwareQuTech / SimulaQron / tests / auto / pythonLib / test_single_qubit.py View on Github external
def prep_Z_qutip():
    q = qutip.basis(2)
    Z = qutip.sigmaz()
    return Z * q
github SoftwareQuTech / SimulaQron / tests / auto / pythonLib / test_single_qubit.py View on Github external
def prep_K_qutip():
    q = qutip.basis(2)
    K = 1 / np.sqrt(2) * (qutip.sigmay() + qutip.sigmaz())
    return K * q
github SoftwareQuTech / SimulaQron / tests / auto / pythonLib / test_two_qubit.py View on Github external
def calc_exp_values(q):
    """
    Calculates the expected value for measurements in the X,Y and Z basis and returns these in a tuple.
    q should be a qutip object representing a density matrix
    """
    # eigenvectors
    z0 = qutip.basis(2, 0)
    z1 = qutip.basis(2, 1)
    x1 = 1 / np.sqrt(2) * (z0 - z1)
    y1 = 1 / np.sqrt(2) * (z0 - 1j * z1)

    # projectors
    P_X1 = x1 * x1.dag()
    P_Y1 = y1 * y1.dag()
    P_Z1 = z1 * z1.dag()

    # probabilities
    p_x = (P_X1 * q).tr()
    p_y = (P_Y1 * q).tr()
    p_z = (P_Z1 * q).tr()

    return (p_x, p_y, p_z)
github SoftwareQuTech / SimulaQron / tests / auto / pythonLib / test_two_qubit.py View on Github external
def prep_H_qutip():
    q = qutip.basis(2)
    H = 1 / np.sqrt(2) * (qutip.sigmax() + qutip.sigmaz())
    return qutip.ket2dm(H * q)
github mabuchilab / QNET / src / qnet / convert / to_qutip.py View on Github external
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)))
github qutip / qutip / qutip / scattering.py View on Github external
temporal_basis_vector : :class: qutip.Qobj
        A basis vector representing photon scattering at the specified indices.
        If there are W waveguides, T times, and N photon emissions, then the
        basis vector has dimensionality (W*T)^N.
    """
    # Cast waveguide_emission_indices to list for mutability
    waveguide_emission_indices = [list(i) for i in waveguide_emission_indices]

    # Calculate total number of waveguides
    W = len(waveguide_emission_indices)

    # Calculate total number of emissions
    num_emissions = sum([len(waveguide_indices) for waveguide_indices in
                         waveguide_emission_indices])
    if num_emissions == 0:
        return basis(W * n_time_bins, 0)

    # Pad the emission indices with zeros
    offset_indices = []
    for i, wg_indices in enumerate(waveguide_emission_indices):
        offset_indices += [index + (i * n_time_bins) for index in wg_indices]

    # Return an appropriate tensor product state
    return tensor([basis(n_time_bins * W, i) for i in offset_indices])
github zlatko-minev / pyEPR / pyEPR / calcs / hamiltonian.py View on Github external
def fock_state_on(d: dict, fock_trunc: int, N_modes: int):
        ''' d={mode number: # of photons} In the bare eigen basis
        '''
        # give me the value d[i]  or 0 if d[i] does not exist
        return qutip.tensor(*[qutip.basis(fock_trunc, d.get(i, 0))
                              for i in range(N_modes)])
github qutip / qutip / qutip / qip / circuit.py View on Github external
-------
        collapsed_states : List of Qobjs
                        the collapsed state obtained after measuring the qubits
                        and obtaining the qubit specified by the target in the
                        state specified by the index.
        probabilities : List of floats
                        the probability of measuring a state in a the state
                        specified by the index.
        '''

        n = int(np.log2(state.shape[0]))
        target = self.targets[0]

        if target < n:
            op0 = basis(2, 0) * basis(2, 0).dag()
            op1 = basis(2, 1) * basis(2, 1).dag()
            measurement_ops = [op0, op1]
        else:
            raise ValueError("target is not valid")

        return measurement_statistics(state, measurement_ops,
                                      targets=self.targets)