Skip to content

Commit

Permalink
Merge pull request #42 from qutech/hotfix/bloch_sphere
Browse files Browse the repository at this point in the history
Hotfix/bloch sphere
  • Loading branch information
thangleiter committed Jan 4, 2021
2 parents bc3b6a3 + ca2ea97 commit 3d5ca27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 5 additions & 7 deletions filter_functions/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def init_bloch_sphere(**bloch_kwargs) -> qt.Bloch:

bloch_kwargs.setdefault('view', [-150, 30])
b = qt.Bloch(**bloch_kwargs)

# https://github.com/qutip/qutip/issues/1385
if hasattr(b.axes, 'set_box_aspect'):
b.axes.set_box_aspect([1, 1, 1])

b.xlabel = [r'$|+\rangle$', '']
b.ylabel = [r'$|+_i\rangle$', '']
return b
Expand Down Expand Up @@ -212,13 +217,6 @@ def plot_bloch_vector_evolution(
n_samples = min([5000, 5*int(pulse.tau/np.diff(pulse.t).min())])

times = np.linspace(pulse.t[0], pulse.tau, n_samples)
n_cops = len(pulse.c_opers)
coeffs = np.zeros((n_cops, len(times)))
for i in range(n_cops):
for j, coeff in enumerate(pulse.c_coeffs[i]):
if coeff != 0:
coeffs[i] += coeff*(pulse.t[j] <= times)*(times <= pulse.t[j+1])

propagators = pulse.propagator_at_arb_t(times)
points = get_bloch_vector(get_states_from_prop(propagators, psi0))
b.add_points(points, meth='l')
Expand Down
6 changes: 6 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,9 @@ def test_plot_bloch_vector_evolution(self):
plotting.plot_bloch_vector_evolution(two_qubit_pulse)

plt.close('all')

def test_box_aspect(self):
"""Fix https://github.com/qutech/filter_functions/issues/41"""
b = plotting.plot_bloch_vector_evolution(simple_pulse, return_Bloch=True)
aspect = b.axes.get_box_aspect()
self.assertAlmostEqual(aspect.std(), 0)

0 comments on commit 3d5ca27

Please sign in to comment.