How to use the qutip.Qobj 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 qucontrol / krotov / tests / test_krotov.py View on Github external
def test_complex_control_rejection():
    """Test that complex controls are rejected"""
    H0 = qutip.Qobj(0.5 * np.diag([-1, 1]))
    H1 = qutip.Qobj(np.mat([[1, 2], [3, 4]]))

    psi0 = qutip.Qobj(np.array([1, 0]))
    psi1 = qutip.Qobj(np.array([0, 1]))

    def eps0(t, args):
        return 0.2 * np.exp(1j * t)

    def S(t):
        """Shape function for the field update"""
        return krotov.shapes.flattop(
            t, t_start=0, t_stop=5, t_rise=0.3, t_fall=0.3, func='sinsq'
        )

    H = [H0, [H1, eps0]]
github qucontrol / krotov / tests / test_functionals.py View on Github external
def cphase_lv_full_objectives(canonical_basis):
    L = qutip.Qobj()  # dummy Liouvillian (won't be used)
    return krotov.objectives.gate_objectives(
        canonical_basis,
        gate=qutip_gates.cphase(np.pi),
        H=L,
        liouville_states_set='full',
    )
github qucontrol / krotov / tests / test_structural_conversions.py View on Github external
def test_extract_controls():
    """Check that we can extract a list of controls from a list of
    objectives"""

    # dummy objects
    X = qutip.Qobj()
    Y = qutip.Qobj()
    f = lambda t: 0
    g = lambda t: 0
    h = lambda t: 0
    d = lambda t: 0

    # all of these dummy objects should be distinguishable
    assert f is not g
    assert g is not h
    assert h is not d
    assert X is not Y

    H1 = [X, [X, f], [X, g]]
    H2 = [X, [X, f], [X, h]]
    H3 = [X, [X, d], X]

    # check same Hamiltonian occuring in multiple objectives
github qucontrol / krotov / src / krotov / propagators.py View on Github external
def _initialize_data(self, L, rho, dt, c_ops, backwards):
        L_list = []
        control_indices = []
        if not (c_ops is None or len(c_ops) == 0):
            # in principle, we could convert c_ops to a Lindbladian, here
            raise NotImplementedError("c_ops not implemented")
        for (i, spec) in enumerate(L):
            if isinstance(spec, qutip.Qobj):
                l_op = spec
                l_coeff = 1
            elif isinstance(spec, list) and isinstance(spec[0], qutip.Qobj):
                l_op = spec[0]
                l_coeff = spec[1]
                control_indices.append(i)
            else:
                raise ValueError(
                    "Incorrect specification of time-dependent Liouvillian"
                )
            if l_op.type == 'super':
                L_list.append([l_op.data, l_coeff, False])
            else:
                raise ValueError(
                    "Incorrect specification of time-dependent Liouvillian"
                )
        self._L_list = L_list
        self._control_indices = control_indices
        if rho.type == 'oper':
github qutip / qutip / qutip / lattice.py View on Github external
for i in range(len(dof_ind)):
                if dof_ind[i] >= self.cell_site_dof[i]:
                    raise Exception("in basis(), dof_ind[", i, "] is required\
                                to be smaller than cell_num_site[", i, "]")
        else:
            raise Exception("dof_ind in basis() needs to be of the same \
                            dimensions as cell_site_dof.")

        doft = basis(self.cell_site_dof[0], dof_ind[0])
        for i in range(1, len(dof_ind)):
            doft = tensor(doft, basis(self.cell_site_dof[i], dof_ind[i]))
        vec_i = tensor(
                basis(self.num_cell, cell), basis(self.cell_num_site, site),
                doft)
        ltc = self.lattice_tensor_config
        vec_i = Qobj(vec_i, dims=[ltc, [1 for i, j in enumerate(ltc)]])
        return vec_i
github SoftwareQuTech / SimulaQron / simulaqron / virtNode / qutipSimulator.py View on Github external
def __init__(self, node, num, maxQubits=10):
        """
        Initialize the simple engine. If no number is given for maxQubits, the assumption will be 10.
        """
        super().__init__(node=node, num=num, maxQubits=maxQubits)

        # We start with no active qubits
        self.activeQubits = 0
        self.qubitReg = qp.Qobj()
github qutip / qutip / qutip / control / propcomp.py View on Github external
The propagtor is calculated for 'free' in this method
        and hence it is returned if compute_prop==True
        Returns:
            [prop], prop_grad
        """
        dyn = self.parent
        dg = dyn._get_phased_dyn_gen(k)
        aug = self._get_aug_mat(k, j)


        if dyn.oper_dtype == Qobj:
            aug_exp = aug.expm()
            prop_grad = Qobj(aug_exp.data[:dg.shape[0], dg.shape[1]:],
                         dims=dyn.dyn_dims)
            if compute_prop:
                prop = Qobj(aug_exp.data[:dg.shape[0], :dg.shape[1]],
                            dims=dyn.dyn_dims)
        else:
            aug_exp = la.expm(aug)
            prop_grad = aug_exp[:dg.shape[0], dg.shape[1]:]
            if compute_prop:
                prop = aug_exp[:dg.shape[0], :dg.shape[1]]

        if compute_prop:
            return prop, prop_grad
        else:
            return prop_grad
github qutip / qutip / qutip / lattice.py View on Github external
(vals, veks) = qH_k.eigenstates()
            plane_waves = np.kron(np.exp(-1j * (kx * range(self.num_cell))),
                                  np.ones(self._length_of_unit_cell))

            for eig_no in range(self._length_of_unit_cell):
                unit_cell_periodic = np.kron(
                    np.ones(self.num_cell), veks[eig_no].dag())
                vec_x = np.multiply(plane_waves, unit_cell_periodic)

                dim_H = [list(np.ones(len(self.lattice_tensor_config),
                                      dtype=int)), self.lattice_tensor_config]
                if self.is_real:
                    if np.count_nonzero(vec_x) > 0:
                        vec_x = np.real(vec_x)

                length_vec_x = np.sqrt((Qobj(vec_x) * Qobj(vec_x).dag())[0][0])
                vec_x = vec_x / length_vec_x
                vec_x = Qobj(vec_x, dims=dim_H)
                vec_xs[ks*self._length_of_unit_cell+eig_no] = vec_x.dag()

            for i in range(self._length_of_unit_cell):
                v0 = np.squeeze(veks[i].full(), axis=1)
                vec_kns[ks, i, :] = v0
            val_kns[:, ks] = vals[:]

        return (knxA, qH_ks, val_kns, vec_kns, vec_xs)
github yvdriess / qvm / scripts / plotbloch.py View on Github external
def main():
    b = qutip.Bloch()
    for file in sys.argv[1:]:
        a = parse_file(file)
        print "plotting: "
        print a
        b.add_states(qutip.Qobj(a))
    b.show()
github quantumsim / quantumsim / quantumsim / states / plotter.py View on Github external
.reshape(truncate_levels ** n_qubits,
                         truncate_levels ** n_qubits))
        trace = np.trace(rho2)
        rho2 += ((1 - trace) * np.identity(2**n_qubits) *
                 truncate_levels ** -n_qubits)
        assert np.allclose(np.trace(rho2), 1)
        dim = [truncate_levels] * n_qubits
    else:
        rho2 = rho
        dim = pv.dim_hilbert

    def tuple_to_string(tup):
        return "".join(str(x) for x in tup)

    labels = [tuple_to_string(x) for x in product(*(range(d) for d in dim))]
    rho_q = qutip.Qobj(rho2, dims=[dim, dim])
    qutip.matrix_histogram_complex(rho_q, ax=ax, xlabels=labels, ylabels=labels)

    return fig