示例#1
0
    def testRWSeparatorDetection(self):
        "Read and write with automatic separator detection"

        # create some random data
        N = 10
        data = (1 - 2 * scipy.rand(N, N)) + 1j * (1 - 2 * scipy.rand(N, N))

        # comma separated values
        file_data_store("test.dat", data, "complex", "exp", ",")
        data2 = file_data_read("test.dat")
        assert_(amax(abs((data - data2))) < 1e-8)

        # semicolon separated values
        file_data_store("test.dat", data, "complex", "exp", ";")
        data2 = file_data_read("test.dat")
        assert_(amax(abs((data - data2))) < 1e-8)

        # tab separated values
        file_data_store("test.dat", data, "complex", "exp", "\t")
        data2 = file_data_read("test.dat")
        assert_(amax(abs((data - data2))) < 1e-8)

        # space separated values
        file_data_store("test.dat", data, "complex", "exp", " ")
        data2 = file_data_read("test.dat")
        assert_(amax(abs((data - data2))) < 1e-8)

        # mixed-whitespace separated values
        file_data_store("test.dat", data, "complex", "exp", " \t ")
        data2 = file_data_read("test.dat")
        assert_(amax(abs((data - data2))) < 1e-8)
        os.remove("test.dat")
示例#2
0
 def case(self, filename, kwargs):
     data = 1 - 2 * np.random.rand(_dimension, _dimension)
     if kwargs.get('numtype', 'complex') == 'complex':
         data = data * (0.5 * 0.5j)
     qutip.file_data_store(filename, data, **kwargs)
     out = qutip.file_data_read(filename)
     np.testing.assert_allclose(data, out, atol=1e-8)
示例#3
0
    def testRWComplexDecimal(self):
        "Read and write complex valued decimal formatted data"

        # create some random data
        N = 10
        data = (1 - 2 * scipy.rand(N, N)) + 1j * (1 - 2 * scipy.rand(N, N))

        file_data_store("test.dat", data, "complex", "decimal")
        data2 = file_data_read("test.dat", ",")
        # make sure the deviation is small:
        assert_(amax(abs((data - data2))) < 1e-8)
        os.remove("test.dat")
示例#4
0
    def testRWRealExp(self):
        "Read and write real valued exp formatted data"

        # create some random data
        N = 10
        data = (1 - 2 * scipy.rand(N, N))

        file_data_store("test.dat", data, "real", "exp")
        data2 = file_data_read("test.dat", ",")
        # make sure the deviation is small:
        assert_(amax(abs((data - data2))) < 1e-8)
        os.remove("test.dat")
示例#5
0
def load_obj(filename, path):
    # grab the sole pickled python object from path directory
    # WARNING - returns None if the file does not exist! Use with caution
    # default return for no object found: "None"
    with cd(path):
        # Loading qobjs
        if ".qt" in filename:
            try:
                obj = qt.file_data_read(filename, sep=",")

            except FileNotFoundError:
                return None

            return qt.Qobj(obj)

        # in the case of anything NOT qobj, I would like not to use their unpacking method
        else:
            try:
                obj = json.load(open(filename))
                return obj

            except IOError:
                return None
示例#6
0
    print('Calculate echoed CR gate')
    print('|psi0> = |00>')
    result_down = \
        np.array(qt.parallel_map(CR_echo, tlist_echo, task_args=(psidown,),
                                 progress_bar=True)).T
    print('|psi0> = |10>')
    result_up = \
        np.array(qt.parallel_map(CR_echo, tlist_echo, task_args=(psiup,),
                                 progress_bar=True)).T
    print('Finished')
    # Save result to file
    print('Save data')
    data = np.vstack((tlist_echo, result_down, result_up))
    qt.file_data_store('CR2.dat', data, numtype='real')
    # %% Plot results
    data = qt.file_data_read('CR0.dat')
    tlist = data[0]
    result_down = data[1:7]
    result_up = data[7:13]

    plt.close('all')
    plt.figure(1)
    plt.subplot(211)
    plt.plot(tlist, np.real(result_down[4]), tlist, np.real(result_up[4]))
    plt.ylabel(r'$\langle\sigma_2^y\rangle$')
    plt.legend(
        [r'$|\psi_0\rangle=|00\rangle$', r'$|\psi_0\rangle=|10\rangle$'])
    plt.title('Simple CR gate')
    plt.subplot(212)
    plt.plot(tlist, np.real(result_down[5]), tlist, np.real(result_up[5]))
    plt.xlabel(r'Time ($\mu$s)')