Skip to content

Commit

Permalink
Merge branch 'master' into fix/add-do-3d-projection-to-arrow-3d-for-m…
Browse files Browse the repository at this point in the history
…atplotlib-3-5
  • Loading branch information
hodgestar committed Mar 5, 2022
2 parents c276326 + 9d05a69 commit 2576058
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions doc/guide/dynamics/dynamics-time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ A very general way to write a time-dependent Hamiltonian or collapse operator is

>>> H = [H0, [H1, py_coeff1], [H2, py_coeff2], ...] # doctest: +SKIP

where ``H0`` is a time-independent Hamiltonian, while ``H1``,``H2``, are time dependent. The same format can be used for collapse operators:
where ``H0`` is a time-independent Hamiltonian, while ``H1``and ``H2`` are time dependent. The same format can be used for collapse operators:

>>> c_ops = [[C0, py_coeff0], C1, [C2, py_coeff2], ...] # doctest: +SKIP

Here we have demonstrated that the ordering of time-dependent and time-independent terms does not matter. In addition, any or all of the collapse operators may be time dependent.

.. note:: While, in general, you can arrange time-dependent and time-independent terms in any order you like, it is best to place all time-independent terms first.

As an example, we will look at an example that has a time-dependent Hamiltonian of the form :math:`H=H_{0}-f(t)H_{1}` where :math:`f(t)` is the time-dependent driving strength given as :math:`f(t)=A\exp\left[-\left( t/\sigma \right)^{2}\right]`. The follow code sets up the problem
As an example, we will look at an example that has a time-dependent Hamiltonian of the form :math:`H=H_{0}-f(t)H_{1}` where :math:`f(t)` is the time-dependent driving strength given as :math:`f(t)=A\exp\left[-\left( t/\sigma \right)^{2}\right]`. The following code sets up the problem

.. plot::
:context:
Expand Down
6 changes: 4 additions & 2 deletions qutip/bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ def add_arc(self, start, end, fmt="b", steps=None, **kwargs):
A matplotlib format string for rendering the arc.
steps : int, default: None
The number of segments to use when rendering the arc. The default
uses one segment per 1/4 degree of the arc.
uses 100 steps times the distance between the start and end points,
with a minimum of 2 steps.
**kwargs : dict
Additional parameters to pass to the matplotlib .plot function
when rendering this arc.
Expand Down Expand Up @@ -472,7 +473,8 @@ def add_arc(self, start, end, fmt="b", steps=None, **kwargs):
)

if steps is None:
steps = int(np.linalg.norm(pt1 - pt2)/(np.pi/(2*360)))
steps = int(np.linalg.norm(pt1 - pt2) * 100)
steps = max(2, steps)
t = np.linspace(0, 1, steps)
# All the points in this line are contained in the plane defined
# by pt1, pt2 and the origin.
Expand Down
20 changes: 8 additions & 12 deletions qutip/lattice.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
__all__ = ['Lattice1d', 'cell_structures']

import numpy as np
from scipy.sparse import (csr_matrix)
from qutip import (Qobj, tensor, basis, qeye, isherm, sigmax, sigmay, sigmaz)

import numpy as np
from qutip import (Qobj, tensor, basis, qeye, isherm, sigmax, sigmay, sigmaz)

try:
import matplotlib.pyplot as plt
except:
except ImportError:
pass

__all__ = ['Lattice1d', 'cell_structures']


def cell_structures(val_s=None, val_t=None, val_u=None):
"""
Expand Down Expand Up @@ -224,7 +224,6 @@ class Lattice1d():
def __init__(self, num_cell=10, boundary="periodic", cell_num_site=1,
cell_site_dof=[1], Hamiltonian_of_cell=None,
inter_hop=None):

self.num_cell = num_cell
self.cell_num_site = cell_num_site
if (not isinstance(cell_num_site, int)) or cell_num_site < 0:
Expand Down Expand Up @@ -1052,8 +1051,7 @@ def display_unit_cell(self, label_on=False):
Qin[i, j] = self._H_intra[
i0*self._length_for_site+i,
j0*self._length_for_site+j]
dim_site = list(np.delete(self.cell_tensor_config, [0], None))
dims_site = [dim_site, dim_site]
dims_site = [self.cell_site_dof, self.cell_site_dof]
Hcell[i0][j0] = Qobj(Qin, dims=dims_site)

fig = plt.figure(figsize=[CNS*2, CNS*2.5])
Expand Down Expand Up @@ -1152,8 +1150,7 @@ def display_lattice(self):
Qin[i, j] = self._H_intra[
i0*self._length_for_site+i,
j0*self._length_for_site+j]
dim_site = list(np.delete(self.cell_tensor_config, [0], None))
dims_site = [dim_site, dim_site]
dims_site = [self.cell_site_dof, self.cell_site_dof]
Hcell[i0][j0] = Qobj(Qin, dims=dims_site)

j0 = 0
Expand Down Expand Up @@ -1242,6 +1239,5 @@ def display_lattice(self):
plt.axis('off')
plt.show()
plt.close()
dim_site = list(np.delete(self.cell_tensor_config, [0], None))
dims_site = [dim_site, dim_site]
dims_site = [self.cell_site_dof, self.cell_site_dof]
return Qobj(inter_T, dims=dims_site)
13 changes: 11 additions & 2 deletions qutip/tests/test_bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def _error(*args, **kw):
check_pngs_equal = check_figures_equal(extensions=["png"])


@pytest.mark.skipif(plt is None, reason="matplotlib not installed")
class TestBloch:
def plot_arc_test(self, fig, *args, **kw):
b = Bloch(fig=fig)
Expand All @@ -30,7 +29,8 @@ def plot_arc_ref(self, fig, start, end, **kw):
start = np.array(start)
end = np.array(end)
if steps is None:
steps = int(np.linalg.norm(start - end) / (np.pi / (2*360)))
steps = int(np.linalg.norm(start - end) * 100)
steps = max(2, steps)

t = np.linspace(0, 1, steps)
line = start[:, np.newaxis] * t + end[:, np.newaxis] * (1 - t)
Expand All @@ -45,6 +45,15 @@ def plot_arc_ref(self, fig, start, end, **kw):
], [
pytest.param(
(1, 0, 0), (1, 0, 0), (0, 1, 0), (0, 1, 0), {}, id="arrays"),
pytest.param(
(0.1, 0, 0), (0.1, 0, 0), (0, 0.1, 0), (0, 0.1, 0), {},
id="small-radius"),
pytest.param(
(1e-5, 0, 0), (1e-5, 0, 0), (0, 1e-5, 0), (0, 1e-5, 0), {},
id="tiny-radius"),
pytest.param(
(1.2, 0, 0), (1.2, 0, 0), (0, 1.2, 0), (0, 1.2, 0), {},
id="large-radius"),
pytest.param(
(1, 0, 0), (1, 0, 0), (0, 1, 0), (0, 1, 0),
{"fmt": "r", "linestyle": "-"}, id="fmt-and-kwargs",
Expand Down
13 changes: 8 additions & 5 deletions qutip/tests/test_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,22 @@ def test_k(self):
k_tC = k_t - (2*np.pi/L) * ((L-1) // 2)
np.testing.assert_allclose(k_tC, k_q, atol=1e-12)

@pytest.mark.parametrize(["lattice", "k_expected", "energies_expected"], [
pytest.param(qutip.Lattice1d(num_cell=8),
@pytest.mark.parametrize([
"lattice_func", "k_expected", "energies_expected",
], [
pytest.param(lambda: qutip.Lattice1d(num_cell=8),
_k_expected(8),
np.array([[2, np.sqrt(2), 0, -np.sqrt(2), -2,
-np.sqrt(2), 0, np.sqrt(2)]]),
id="atom chain"),
pytest.param(_ssh_lattice(-0.5, -0.6,
cells=6, sites_per_cell=2, freedom=[2, 2]),
pytest.param(lambda: _ssh_lattice(
-0.5, -0.6, cells=6, sites_per_cell=2, freedom=[2, 2]),
_k_expected(6),
np.array([-_ssh_energies]*4 + [_ssh_energies]*4),
id="ssh model")
])
def test_get_dispersion(self, lattice, k_expected, energies_expected):
def test_get_dispersion(self, lattice_func, k_expected, energies_expected):
lattice = lattice_func()
k_test, energies_test = lattice.get_dispersion()
_assert_angles_close(k_test, k_expected, atol=1e-8)
np.testing.assert_allclose(energies_test, energies_expected, atol=1e-8)
Expand Down

0 comments on commit 2576058

Please sign in to comment.