Beispiel #1
0
 def test_iterate_and_precompute_are_equivalent(self, size, n_xs, n_ys, g):
     xs = np.linspace(-1, 1, n_xs)
     ys = np.linspace(0, 2, n_ys)
     state = qutip.rand_dm(size)
     iterate = qutip.qfunc(state, xs, ys, g, precompute_memory=None)
     precompute = qutip.qfunc(state, xs, ys, g, precompute_memory=np.inf)
     np.testing.assert_allclose(iterate, precompute)
Beispiel #2
0
 def test_qfunc_warns_if_insufficient_memory(self):
     xs = np.linspace(-1, 1, 11)
     state = qutip.rand_dm(4)
     with pytest.warns(UserWarning) as e:
         qutip.qfunc(state, xs, xs, precompute_memory=0)
     assert (e[0].message.args[0].startswith(
         "Falling back to iterative algorithm"))
Beispiel #3
0
 def test_failure_if_not_a_Qobj(self, obj):
     xs = np.linspace(-1, 1, 11)
     with pytest.raises(TypeError) as e:
         qutip.qfunc(obj, xs, xs)
     assert e.value.args[0].startswith("state must be Qobj")
     qfunc = qutip.QFunc(xs, xs)
     with pytest.raises(TypeError) as e:
         qfunc(obj)
     assert e.value.args[0].startswith("state must be Qobj")
Beispiel #4
0
 def test_failure_if_tensor_hilbert_space(self, dm):
     if dm:
         state = qutip.rand_dm(4, dims=[[2, 2], [2, 2]])
     else:
         state = qutip.rand_ket(4, dims=[[2, 2], [1, 1]])
     xs = np.linspace(-1, 1, 5)
     with pytest.raises(ValueError) as e:
         qutip.qfunc(state, xs, xs)
     assert "must not have tensor structure" in e.value.args[0]
     with pytest.raises(ValueError) as e:
         qutip.QFunc(xs, xs)(state)
     assert "must not have tensor structure" in e.value.args[0]
Beispiel #5
0
 def test_failure_if_not_a_state(self, state):
     xs = np.linspace(-1, 1, 11)
     state = state()
     with pytest.raises(ValueError) as e:
         qutip.qfunc(state, xs, xs)
     assert (e.value.args[0].startswith(
         "state must be a ket or density matrix"))
     qfunc = qutip.QFunc(xs, xs)
     with pytest.raises(ValueError) as e:
         qfunc(state)
     assert (e.value.args[0].startswith(
         "state must be a ket or density matrix"))
Beispiel #6
0
 def test_failure_if_non_arraylike_coordinates(self, xs):
     state = qutip.rand_ket(4)
     valid = np.linspace(-1, 1, 5)
     with pytest.raises(TypeError) as e:
         qutip.qfunc(state, xs, valid)
     assert "must be array-like" in e.value.args[0]
     with pytest.raises(TypeError) as e:
         qutip.qfunc(state, valid, xs)
     assert "must be array-like" in e.value.args[0]
     with pytest.raises(TypeError) as e:
         qutip.QFunc(xs, valid)
     assert "must be array-like" in e.value.args[0]
     with pytest.raises(TypeError) as e:
         qutip.QFunc(valid, xs)
     assert "must be array-like" in e.value.args[0]
Beispiel #7
0
 def test_failure_if_coordinates_not_1d(self, ndim):
     state = qutip.rand_ket(4)
     valid = np.linspace(-1, 1, 5)
     bad = valid.reshape((-1, ) + (1, ) * (ndim - 1))
     with pytest.raises(ValueError) as e:
         qutip.qfunc(state, bad, valid)
     assert "must be 1D" in e.value.args[0]
     with pytest.raises(ValueError) as e:
         qutip.qfunc(state, valid, bad)
     assert "must be 1D" in e.value.args[0]
     with pytest.raises(ValueError) as e:
         qutip.QFunc(bad, valid)
     assert "must be 1D" in e.value.args[0]
     with pytest.raises(ValueError) as e:
         qutip.QFunc(valid, bad)
     assert "must be 1D" in e.value.args[0]
Beispiel #8
0
 def test_function_and_class_are_equivalent(self, size, dm, n_xs, n_ys, g):
     xs = np.linspace(-1, 1, n_xs)
     ys = np.linspace(0, 2, n_ys)
     state = qutip.rand_dm(size) if dm else qutip.rand_ket(size)
     function = qutip.qfunc(state, xs, ys, g)
     class_ = qutip.QFunc(xs, ys, g)(state)
     np.testing.assert_allclose(function, class_)
Beispiel #9
0
 def qps(self):
     self.qps = []
     for rho in self.density_matrix_list:
         if self.functype != 'Q':
             self.qps.append(qt.wigner(rho, self.xvec, self.yvec))
         else:
             self.qps.append(qt.qfunc(rho, self.xvec, self.yvec))
     return self.qps
 def qps(self):
     self.qps = []
     for rho in self.density_matrix_list:
         if self.functype != "Q":
             self.qps.append(qt.wigner(rho, self.xvec, self.yvec))
         else:
             self.qps.append(qt.qfunc(rho, self.xvec, self.yvec))
     return self.qps
Beispiel #11
0
 def test_against_naive_implementation(self, xs, ys, g, size):
     state = qutip.rand_dm(size)
     state_np = state.full()
     x, y = np.meshgrid(xs, ys)
     alphas = 0.5 * g * (x + 1j * y)
     naive = np.empty(alphas.shape, dtype=np.float64)
     for i, alpha in enumerate(alphas.flat):
         coh = qutip.coherent(size, alpha, method='analytic').full()
         naive.flat[i] = (coh.conj().T @ state_np @ coh).real
     naive *= (0.5 * g)**2 / np.pi
     np.testing.assert_allclose(naive, qutip.qfunc(state, xs, ys, g))
     np.testing.assert_allclose(naive, qutip.QFunc(xs, ys, g)(state))
def f(state, xvec, yvec):
    return qt.qfunc(state, xvec, yvec)
Beispiel #13
0
ax[1].set_xlabel('$\omega_c-\omega_d$')
ax[1].set_ylabel('$|\langle a \\rangle | ^2 $')
print('saving data ... ', end='', flush=True)
np.save('resonant.npy', data)
print('done')
print('starting qps ', end='', flush=True)

### Q function plots along right hand side

xvec = np.linspace(-8, 8, 100)
yvec = np.linspace(-8, 8, 100)

for sys in enumerate(carmichael_systems[::2][0:4]): 
    '''for every other system, truncated to four. 
    get colors for qp backgrounds from lines'''
    qp = qt.qfunc(sys[1].rhos_ss[width//2].ptrace(0), xvec, yvec)
    print('.', end='', flush=True)
    ax[sys[0]+2].contour(xvec, yvec, qp, 40, 
            linewidths=0.8, 
            cmap='inferno')

    # Set plot parameters
    ax[sys[0]+2].set_xlabel('Im(Q)')
    ax[sys[0]+2].set_ylabel('Re(Q)')
    ax[sys[0]+2].set_title('Q', 
                      loc='right', 
                      fontdict={'fontsize':12, 'verticalalignment':'bottom', 'color': res_childs[0].get_colors()[::2][0:4][sys[0]], 
                      'weight':'bold'})

print('done')