Skip to content

Commit

Permalink
Merge b65d79d into 0b42bfa
Browse files Browse the repository at this point in the history
  • Loading branch information
thangleiter committed Jul 3, 2020
2 parents 0b42bfa + b65d79d commit a3ece0c
Show file tree
Hide file tree
Showing 30 changed files with 24,275 additions and 3,379 deletions.
2 changes: 2 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ python:
path: .
extra_requirements:
- doc
- plotting
- bloch_sphere_visualization
- fancy_progressbar
31 changes: 18 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
os: linux

dist: xenial

language: python

python:
- '3.6'
- '3.7'
- '3.8'
- 3.6
- 3.7
- 3.8
env:
- INSTALL_EXTRAS=[plotting,bloch_sphere_visualization,fancy_progressbar,tests]
- INSTALL_EXTRAS=[plotting,fancy_progressbar,tests]
- INSTALL_EXTRAS=[tests]

#these directories are persistent
cache: pip

#manually install these dependencies so that qutip can be installed via pip
before_install:
- pip install --upgrade pip
- pip install numpy scipy cython

install:
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda config --append channels conda-forge
- conda info -a
- conda env create -f ./environment.yml
- source activate filter_functions
- pip install .[fancy_progressbar,doc,tests]
- pip install .$INSTALL_EXTRAS

script:
- coverage run --rcfile=coverage.ini -m pytest
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ hadamard = ff.PulseSequence(H_c, H_n, dt) # Central object representing a cont
omega = ff.util.get_sample_frequencies(hadamard)
F = hadamard.get_filter_function(omega)

ff.plot_filter_function(hadamard) # Filter function cached from before
from filter_functions import plotting
plotting.plot_filter_function(hadamard) # Filter function cached from before
```

![Hadamard dephasing filter function](./doc/source/_static/hadamard.png)
Expand Down Expand Up @@ -59,16 +60,16 @@ infidelity = ff.infidelity(hadamard, spectrum, omega)
```

## Installation
To install the package from PyPI, run `pip install filter_functions`. It is recommended to install QuTiP before by following the [instructions on their website](http://qutip.org/docs/latest/installation.html) rather than installing it through `pip`. To install the package from source run `python setup.py develop` to install using symlinks or `python setup.py install` without.
To install the package from PyPI, run `pip install filter_functions`. If you require the optional features provided by QuTiP (visualizing Bloch sphere trajectories), it is recommended to install QuTiP before by following the [instructions on their website](http://qutip.org/docs/latest/installation.html) rather than installing it through `pip`. To install the package from source run `python setup.py develop` to install using symlinks or `python setup.py install` without.

To install the optional dependencies (`tqdm` and `requests` for a fancy progress bar), run `pip install -e .[fancy_progressbar]` from the root directory.
To install dependencies of optional extras (`tqdm` and `requests` for a fancy progress bar, `matplotlib` for plotting, `QuTiP` for Bloch sphere visualization), run `pip install -e .[extra]` where `extra` is one or more of `fancy_progressbar`, `plotting`, `bloch_sphere_visualization` from the root directory. To install all dependencies, including those needed to build the documentation and run the tests, use the extra `all`.

## Documentation
You can find the documentation on [Readthedocs](https://filter-functions.readthedocs.io/en/latest/). It is built from Jupyter notebooks that can also be run interactively and are located [here](doc/source/examples). The notebooks explain how to use the package and thus make sense to follow chronologically as a first step. Furthermore, there are also a few example scripts in the [examples](examples) folder.

The documentation including the example notebooks and an automatically generated API documentation can be built by running `make <format>` inside the *doc* directory where `<format>` is for example `html`.

Building the documentation requires the following additional dependencies: `nbsphinx`, `numpydoc`, `sphinx_rtd_theme`, `jupyter_client`, `ipython`, `ipykernel`, as well as `pandoc`. The last can be installed via conda (`conda install pandoc`) or downloaded from [Github](https://github.com/jgm/pandoc/releases/) and the rest automatically by running `pip install -e .[doc]`.
Interactively using the documentation requires `jupyter`, and building a static version additionally requires `nbsphinx`, `numpydoc`, `sphinx_rtd_theme`,, as well as `pandoc`. The last can be installed via conda (`conda install pandoc`) or downloaded from [Github](https://github.com/jgm/pandoc/releases/) and the rest automatically by running `pip install -e .[doc]`.

## References
[1]: Cywinski, L., Lutchyn, R. M., Nave, C. P., & Das Sarma, S. (2008). How to enhance dephasing time in superconducting qubits. Physical Review B - Condensed Matter and Materials Physics, 77(17), 1–11. [https://doi.org/10.1103/PhysRevB.77.174509](https://doi.org/10.1103/PhysRevB.77.174509)
Expand Down
Binary file modified doc/source/_static/hadamard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions doc/source/examples/advanced_concatenation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"d = 2\n",
"H = np.empty((2, d, d), dtype=complex)\n",
"\n",
"Id, Px, Py, Pz = ff.util.P_np\n",
"Id, Px, Py, Pz = ff.util.paulis\n",
"H[0] = 1/2*Px\n",
"H[1] = 1/2*Pz\n",
"\n",
Expand Down Expand Up @@ -184,8 +184,11 @@
"metadata": {},
"outputs": [],
"source": [
"from filter_functions import plotting\n",
"\n",
"for gate in gate_types:\n",
" ff.plot_bloch_vector_evolution(H[gate], n_samples=501, figsize=(4, 4))"
" plotting.plot_bloch_vector_evolution(H[gate], n_samples=501,\n",
" figsize=(4, 4))"
]
},
{
Expand All @@ -203,9 +206,8 @@
"source": [
"pulses = ('Y', 'X_1', 'X_2')\n",
"for gate_type, hadamard in H.items():\n",
" fig, ax, leg = ff.plot_pulse_correlation_filter_function(hadamard,\n",
" xscale='linear',\n",
" figsize=(9, 6))\n",
" fig, ax, leg = plotting.plot_pulse_correlation_filter_function(\n",
" hadamard, xscale='linear', figsize=(9, 6))\n",
"\n",
" # Adjust the titles to something more meaningful\n",
" for i in range(3):\n",
Expand Down
13,961 changes: 13,921 additions & 40 deletions doc/source/examples/calculating_error_transfer_matrices.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions doc/source/examples/extending_pulses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"import filter_functions as ff\n",
"from filter_functions import util\n",
"\n",
"I, X, Y, Z = util.P_np\n",
"I, X, Y, Z = util.paulis\n",
"\n",
"# In order to be able to remap cached filter functions, we need a separable\n",
"# basis like the Pauli basis\n",
Expand Down Expand Up @@ -209,8 +209,10 @@
"metadata": {},
"outputs": [],
"source": [
"from filter_functions import plotting\n",
"\n",
"print(swap_14_23.is_cached('F'))\n",
"_ = ff.plot_filter_function(swap_14_23)"
"_ = plotting.plot_filter_function(swap_14_23)"
]
}
],
Expand Down
12 changes: 7 additions & 5 deletions doc/source/examples/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"metadata": {},
"outputs": [],
"source": [
"from filter_functions import analytic\n",
"from filter_functions import analytic, plotting\n",
"\n",
"# Generate logarithmically spaced frequencies over an interval which generally\n",
"# captures the important regions of the filter function. Since the filter\n",
Expand All @@ -135,7 +135,7 @@
"omega = ff.util.get_sample_frequencies(FID, n_samples=200, spacing='log',\n",
" symmetric=False)\n",
"# Plot the filter function.\n",
"fig, ax, legend = ff.plot_filter_function(FID, omega)\n",
"fig, ax, legend = plotting.plot_filter_function(FID, omega)\n",
"# Plot the analytic solution into the same plot\n",
"ax.plot(omega*tau, analytic.FID(omega*tau)/omega**2,\n",
" 'x-', label='Analytical', zorder=0)\n",
Expand All @@ -161,7 +161,8 @@
"# Initial state the +1 eigenstate of X\n",
"psi_i = (qt.basis(2, 0) + qt.basis(2, 1))/np.sqrt(2)\n",
"\n",
"ff.plot_bloch_vector_evolution(FID, psi0=psi_i, n_samples=101, figsize=(4, 4))"
"plotting.plot_bloch_vector_evolution(FID, psi0=psi_i, n_samples=101,\n",
" figsize=(4, 4))"
]
},
{
Expand Down Expand Up @@ -261,14 +262,15 @@
"omega = ff.util.get_sample_frequencies(SE, n_samples=400, spacing='log',\n",
" symmetric=False)\n",
"# Plot the filter function\n",
"fig, ax, legend = ff.plot_filter_function(SE, omega, yscale='log')\n",
"fig, ax, legend = plotting.plot_filter_function(SE, omega, yscale='log')\n",
"ax.set_ylim(bottom=1e-13)\n",
"# Plot the analytical solution\n",
"ax.plot(omega*tau, analytic.SE(omega*tau)/omega**2, '--',\n",
" label='Analytical (Bang-Bang)', zorder=0)\n",
"legend = ax.legend()\n",
"\n",
"ff.plot_bloch_vector_evolution(SE, psi0=psi_i, n_samples=101, figsize=(4, 4))"
"plotting.plot_bloch_vector_evolution(SE, psi0=psi_i, n_samples=101,\n",
" figsize=(4, 4))"
]
},
{
Expand Down
3,655 changes: 3,626 additions & 29 deletions doc/source/examples/periodic_driving.ipynb

Large diffs are not rendered by default.

8,246 changes: 5,435 additions & 2,811 deletions doc/source/examples/quantum_fourier_transform.ipynb

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions doc/source/examples/qutip_integration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from filter_functions import plotting\n",
"\n",
"identifiers = ['XI', 'YI', 'IX', 'IY', 'ZZ']\n",
"pulses = {\n",
Expand All @@ -104,12 +105,12 @@
"fig, ax = plt.subplots(2, 3, figsize=(12, 6))\n",
"for i, (p_type, pulse) in enumerate(pulses.items()):\n",
" # Plot the pulse train\n",
" *_, = ff.plot_pulse_train(pulse, fig=fig, axes=ax[0, i])\n",
" *_, = plotting.plot_pulse_train(pulse, fig=fig, axes=ax[0, i])\n",
" ax[0, i].set_title(p_type)\n",
" # Plot the filter functions\n",
" omega = ff.util.get_sample_frequencies(pulse, spacing='log',\n",
" symmetric=False)\n",
" *_, = ff.plot_filter_function(pulse, omega, fig=fig, axes=ax[1, i])\n",
" *_, = plotting.plot_filter_function(pulse, omega, fig=fig, axes=ax[1, i])\n",
" \n",
"fig.tight_layout()"
]
Expand Down Expand Up @@ -138,7 +139,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.1"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
3 changes: 2 additions & 1 deletion examples/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import numpy as np

import filter_functions as ff
from filter_functions import plotting
import qutip as qt
from qutip import qip

Expand Down Expand Up @@ -149,6 +150,6 @@ def QFT_pulse(N: int = 4, tau: float = 1):
print('Correct action: ',
ff.util.oper_equiv(prop, qip.algorithms.qft.qft(N), eps=1e-14))

fig, ax, _ = ff.plot_filter_function(QFT, omega)
fig, ax, _ = plotting.plot_filter_function(QFT, omega)
# Move the legend to the side because of many entries
ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
10 changes: 2 additions & 8 deletions filter_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,17 @@
# =============================================================================
"""Package for efficient calculation of generalized filter functions"""

from . import analytic, basis, numeric, plotting, pulse_sequence, util
from . import analytic, basis, numeric, pulse_sequence, util
from .basis import Basis
from .numeric import (error_transfer_matrix, infidelity,
liouville_representation)
from .plotting import (
plot_bloch_vector_evolution, plot_error_transfer_matrix,
plot_filter_function, plot_pulse_correlation_filter_function,
plot_pulse_train)
from .pulse_sequence import (PulseSequence, concatenate, concatenate_periodic,
extend, remap)

__all__ = ['Basis', 'PulseSequence', 'analytic', 'basis', 'concatenate',
'concatenate_periodic', 'error_transfer_matrix', 'extend',
'infidelity', 'liouville_representation', 'numeric',
'plot_bloch_vector_evolution', 'plot_error_transfer_matrix',
'plot_filter_function', 'plot_pulse_correlation_filter_function',
'plot_pulse_train', 'plotting', 'pulse_sequence', 'remap', 'util']
'pulse_sequence', 'remap', 'util']

__version__ = '0.2.4'
__license__ = 'GNU GPLv3+'
Expand Down
9 changes: 4 additions & 5 deletions filter_functions/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import opt_einsum as oe
from numpy import linalg as nla
from numpy.core import ndarray
from qutip import Qobj
from scipy import linalg as sla
from sparse import COO

Expand Down Expand Up @@ -172,11 +171,11 @@ def __new__(cls, basis_array: Sequence, traceless: Optional[bool] = None,
basis = np.empty((len(basis_array), *basis_array[0].shape),
dtype=complex)
for i, elem in enumerate(basis_array):
if isinstance(elem, ndarray):
if isinstance(elem, ndarray): # numpy array
basis[i] = elem
elif isinstance(elem, Qobj):
elif hasattr(elem, 'full'): # qutip.Qobj
basis[i] = elem.full()
elif isinstance(elem, COO):
elif hasattr(elem, 'todense'): # sparse array
basis[i] = elem.todense()
else:
raise TypeError('At least one element invalid type!')
Expand Down Expand Up @@ -424,7 +423,7 @@ def pauli(cls, n: int) -> 'Basis':
"""
normalization = np.sqrt(2**n)
combinations = np.indices((4,)*n).reshape(n, 4**n)
sigma = util.tensor(*np.array(util.P_np)[combinations], rank=2)
sigma = util.tensor(*util.paulis[combinations], rank=2)
sigma /= normalization
return cls(sigma, btype='Pauli', skip_check=True)

Expand Down
Loading

0 comments on commit a3ece0c

Please sign in to comment.