Skip to content

Commit

Permalink
Merge pull request #3 from XanaduAI/sfv0.11_update
Browse files Browse the repository at this point in the history
Update to support SF v0.11
  • Loading branch information
josh146 committed Jul 11, 2019
2 parents 2f87f67 + fd71981 commit b7ebd31
Show file tree
Hide file tree
Showing 29 changed files with 890 additions and 1,083 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# .coveragerc to control coverage.py
[run]
source = sfopenboson
omit =
sfopenboson/tests/*.py

[report]
# Regexes for lines to exclude from consideration
Expand Down
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
language: python
cache: pip
python:
- 3.5
- 3.6
dist: xenial
matrix:
include:
- python: 3.6
env:
- TF=1
- COVERAGE=1
- python: 3.7
env:
- TF=0
- COVERAGE=0
env:
- LOGGING=info
install:
- pip install pip --upgrade
- pip install -e git+https://github.com/XanaduAI/pennylane.git#egg=pennylane
- pip install -e git+https://github.com/XanaduAI/strawberryfields.git#egg=strawberryfields
- if [ "$TF" = "1" ]; then pip install tensorflow==1.3; fi
- pip install -r requirements.txt
- pip install wheel codecov
- pip install pytest pytest-cov wheel codecov --upgrade
- python3 setup.py bdist_wheel
- pip install dist/SFOpenBoson*.whl
script:
- coverage3 run -m unittest discover sfopenboson/tests
- make coverage
after_success:
- codecov
- if [ "$COVERAGE" = "1" ]; then codecov; fi
notifications:
slack:
secure: FfvzFoLEPy+O1hkz+co7W/P2DAeGTqUYRTh7cA90wkhZNN+qHBXdhKzNOAZs4V462/AHHi13K95ltBCuW9nE6eJveZGQkPlLr9ojZtVKzIzNP2TgpnYRdAhogW1cmRdquPcPUXNBfs71DOPFTI2J8Kr1U3uZNkJ0HSURPlF05M11ESXPMzeMSNMjCAanFD+62+hsV8Jsx7vmLtiTCpMbatTgKYB/IE3nV2khILWMGcokxX5cSJ1/RRittLWMqLrmUPZnZ3f5G6YbkeV40Z//1/DK2/Mgw4ryZzZzCe3L4HQMxry5YeCJucnfGJmqJzRzB+JxNn0gRT4RX4SCJJBAa6BISwVvP89HFN5tkXGl8RYsKBJ0sdzbwQ0MFnS4rVoQP1IEAkx+TZ3fUzPZ68KDhspSxght6H+oRQCcaNFoHjh6xJSvAJQem6BQVyGErcjrmoxcPWmdNfiLs8lENcBSbN8fiZia8leCo5jzyl7dvBtlkRgvtx9pLSkevDLbPDMPVQokmXuVIG3psKCPZuAGAUTOP/FRYlZXCmXALsNAe7nuetXUSKL6P0YlA5PNPzstDEKe0LX50eiQV2olPPuLYed/Z6v7/VVIV4jgUXYVbnhbjY+g4pL1ikg58kbBY6afxXW4AGpvYoFEgdVmlBTvldlIXl84n3lH5hBHIVQiLiY=
20 changes: 6 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
PYTHON3 := $(shell which python3 2>/dev/null)
COVERAGE3 := $(shell which coverage3 2>/dev/null)

PYTHON := python3
COVERAGE := coverage3
COPTS := run #--append
TESTRUNNER := -m unittest discover sfopenboson/tests
PYTHON := $(shell which python3 2>/dev/null)
TESTRUNNER := -m pytest sfopenboson/tests -p no:warnings
COVERAGE := --cov=sfopenboson --cov-report=term --cov-report=html:coverage_html_report

.PHONY: help
help:
Expand All @@ -14,10 +10,8 @@ help:
@echo " dist to package the source distribution"
@echo " clean to delete all temporary, cache, and build files"
@echo " clean-docs to delete all built documentation"
@echo " test to run the test suite for all backends"
@echo " test-[backend] to run the test suite for backend fock, tf, or gaussian"
@echo " coverage to generate a coverage report for all backends"
@echo " coverage-[backend] to generate a coverage report for backend fock, tf, or gaussian"
@echo " test to run the test suite"
@echo " coverage to generate a coverage report"

.PHONY: install
install:
Expand Down Expand Up @@ -53,6 +47,4 @@ test:

coverage:
@echo "Generating coverage report..."
$(COVERAGE) $(COPTS) $(TESTRUNNER)
$(COVERAGE) report
$(COVERAGE) html
$(PYTHON) $(TESTRUNNER) $(COVERAGE)
2 changes: 0 additions & 2 deletions doc/code/ops.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.. automodule:: sfopenboson.ops
:members:
:inherited-members:
:private-members:
38 changes: 17 additions & 21 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,27 @@ class TypeMock(type):

# xanadu theme options (see theme.conf for more information)
html_theme_options = {

# Set the path to a special layout to include for the homepage
# "index_template": "special_index.html",
# "homepage": "special_index.html",

# Set the name of the project to appear in the left sidebar.
"project_nav_name": "SFOpenBoson",

# Set your Disqus short name to enable comments
# "disqus_comments_shortname": "my_disqus_comments_short_name",

# Set you GA account ID to enable tracking
# "google_analytics_account": "UA-112607589-1",

# Path to a touch icon
"touch_icon": "logo_new.png",

# Specify a base_url used to generate sitemap.xml links. If not
# specified, then no sitemap will be built.
# "base_url": ""

# Allow a separate homepage from the master_doc
# "homepage": "index",

# Allow the project link to be overriden to a custom URL.
# "projectlink": "http://myproject.url",
"touch_icon": "_static/logo_new.png",
"touch_icon_small": "_static/logo_new_small.png",
"large_toc": False,

# colors
"navigation_button": "#2ccca9",
"navigation_button_hover": "#1bab8b",
"toc_caption": "#2ccca9",
"toc_hover": "#2ccca9",
"table_header_bg": "#e8f9f6",
"table_header_border": "#2ccca9",
"download_button": "#2ccca9",

# gallery options
"github_repo": "XanaduAI/SFOpenBoson",
# "gallery_dirs": sphinx_gallery_conf['gallery_dirs']
}

edit_on_github_project = 'XanaduAI/SFOpenBoson'
Expand Down
7 changes: 0 additions & 7 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,3 @@ SFOpenBoson is **free** and **open source**, released under the Apache License,
code/ops
code/hamiltonians
code/auxillary

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
2 changes: 1 addition & 1 deletion doc/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Dependencies

SFOpenBoson depends on the following Python packages:

* `Strawberry Fields <http://strawberryfields.readthedocs.io/>`_ >=0.7.3
* `Strawberry Fields <http://strawberryfields.readthedocs.io/>`_ >=0.11
* `OpenFermion <https://github.com/quantumlib/OpenFermion>`_ >=0.7

These can be installed using pip, or, if on linux, using your package manager (i.e., ``apt`` if on a Debian-based system.)
Expand Down
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinxcontrib-bibtex
strawberryfields>=0.7.3
strawberryfields>=0.11
6 changes: 3 additions & 3 deletions doc/research.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Research and contribution
Research
---------------

If you are doing research using SFOpenBoson and Strawberry Fields, please cite the `Strawberry Fields <https://arxiv.org/abs/1804.03159>`_ and `OpenFermion <https://arxiv.org/abs/1710.07629>`_ papers:

Nathan Killoran, Josh Izaac, Nicolás Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook. Strawberry Fields: A Software Platform for Photonic Quantum Computing. *arXiv*, 2018. arXiv:1804.03159
If you are doing research using SFOpenBoson and Strawberry Fields, please cite the `Strawberry Fields <https://quantum-journal.org/papers/q-2019-03-11-129>`_ and `OpenFermion <https://arxiv.org/abs/1710.07629>`_ papers:

Nathan Killoran, Josh Izaac, Nicolás Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook. "Strawberry Fields: A Software Platform for Photonic Quantum Computing", Quantum, 3, 129 (2019).

..
Jarrod R. McClean, Ian D. Kivlichan, Kevin J. Sung, Damian S. Steiger, Yudong Cao, Chengyu Dai, E. Schuyler Fried, Craig Gidney, Brendan Gimby, Thomas Häner, Tarini Hardikar, Vojtĕch Havlíček, Cupjin Huang, Zhang Jiang, Matthew Neeley, Thomas O'Brien, Isil Ozfidan, Maxwell D. Radin, Jhonathan Romero, Nicholas Rubin, Nicolas P. D. Sawaya, Kanav Setia, Sukin Sim, Mark Steudtner, Wei Sun, Fang Zhang and Ryan Babbush. OpenFermion: The Electronic Structure Package for Quantum Computers. *arXiv*, 2017. arXiv:1710.07629.

Expand Down
14 changes: 8 additions & 6 deletions doc/tutorials/bosehubbard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ Alternatively, you can set ``mode='global'``, and the Hamiltonian is instead app

Let's set up the two qumode quantum circuit — each mode corresponds to a node in the lattice — and propagating the Bose-Hubbard Hamiltonian ``H`` we defined in the previous section, starting from the initial state :math:`\ket{0,2}` in the Fock space, for time :math:`t=1.086` and Lie product truncation :math:`k=20`:

>>> eng, q = sf.Engine(2)
>>> with eng:
>>> prog = sf.Program(2)
>>> with prog.context as q:
... Fock(2) | q[1]
... BoseHubbardPropagation(H, 1.086, 20) | q

Now, we can run this simulation using the `Fock backend of Strawberry Fields <https://strawberryfields.readthedocs.io/en/latest/code/backend.fock.html>`_, and output the Fock state probabilities at time :math:`t=1.086`:

.. note:: In the Bose-Hubbard model, the number of particles in the system remains constant, so we do not need to increase the cutoff dimension of the simulation beyond the total number of photons in the initial state.

>>> state = eng.run('fock', cutoff_dim=3)
>>> eng = sf.Engine("fock", backend_options={"cutoff_dim": 3})
>>> state = eng.run(prog).state
>>> state.fock_prob([2,0])
0.52240124572001967
>>> state.fock_prob([1,1])
Expand Down Expand Up @@ -96,14 +97,15 @@ Next, let's add an on-site interaction term, with strength :math:`U=1.5`:

As before, we use :class:`~.BoseHubbardPropagation` to simulate this model for time :math:`t=1.086`, starting from initial state :math:`\ket{2,0}`. Due to the increased size of this model, let's increase the Lie product truncation to :math:`k=100`:

>>> eng, q = sf.Engine(3)
>>> with eng:
>>> prog = sf.Program(3)
>>> with prog.context as q:
... Fock(2) | q[0]
... BoseHubbardPropagation(H, 1.086, 100) | q

Running the circuit, and checking some output probabilities:

>>> state = eng.run('fock', cutoff_dim=3)
>>> eng = sf.Engine("fock", backend_options={"cutoff_dim": 3})
>>> state = eng.run(prog).state
>>> for i in ([2,0,0], [1,1,0], [1,0,1], [0,2,0], [0,1,1], [0,0,2]):
>>> print(state.fock_prob(i))
0.0854670760113
Expand Down
17 changes: 10 additions & 7 deletions doc/tutorials/gaussian.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ Alternatively, you can set ``mode='global'``, and the Hamiltonian is instead app

Let's set up the one qumode quantum circuit, propagating the forced oscillator Hamiltonian ``H`` we defined in the previous section, starting from the initial location :math:`(1,0.5)` in phase space, for time :math:`t=1.43`:

>>> eng, q = sf.Engine(1)
>>> with eng:
>>> prog = sf.Program(1)
>>> with prog.context as q:
... Xgate(1) | q[0]
... Zgate(0.5) | q[0]
... GaussianPropagation(H, 1.43) | q

Now, we can run this simulation using the `Gaussian backend of Strawberry Fields <https://strawberryfields.readthedocs.io/en/latest/code/backend.gaussian.html>`_, and output the location of the oscillator in phase space at time :math:`t=1.43`:

>>> state = eng.run('gaussian')
>>> eng = sf.Engine("gaussian")
>>> state = eng.run(prog).state
>>> state.means()
array([ 2.35472067, 1.06027036])

Expand Down Expand Up @@ -107,19 +108,21 @@ Consider the following example:

.. code-block:: python
eng, q = sf.Engine(1, hbar=2)
eng = sf.Engine("gaussian")
t_vals = np.arange(0, 6, 0.02)
results = np.zeros([2, len(t_vals)])
for step, t in enumerate(t_vals):
eng.reset()
with eng:
prog = sf.Program(1)
with prog.context as q:
Xgate(1) | q[0]
Zgate(0.5) | q[0]
GaussianPropagation(H, t) | q
state = eng.run('gaussian')
state = eng.run(prog).state
eng.reset()
results[:, step] = state.means()
Here, we are looping over the same circuit as above for values of :math:`t` within the domain :math:`0\leq t<6`, and storing the resulting expectation values :math:`(\braket{\q(t)}, \braket{\p(t)})` in the array ``results``. We can plot this array in phase space:
Expand Down
61 changes: 50 additions & 11 deletions doc/xanadu_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<link rel="stylesheet" type="text/css" href="{{ pathto('_static/fonts/open-sans/stylesheet.css', 1) }}" />
<!-- Licensed under the SIL Open Font License -->
<link rel="stylesheet" type="text/css" href="{{ pathto('_static/fonts/source-serif-pro/source-serif-pro.css', 1) }}" />
<link href="https://fonts.googleapis.com/css?family=Noto+Serif" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Noto+Serif" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{{ pathto('_static/css/bootstrap.min.css', 1) }}" />
<link rel="stylesheet" type="text/css" href="{{ pathto('_static/css/bootstrap-theme.min.css', 1) }}" />
<link rel="stylesheet" type="text/css" href="{{ pathto('_static/css/nanoscroller.css', 1) }}" />
<script defer src="https://use.fontawesome.com/releases/v5.0.2/js/all.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
"HTML-CSS": { scale: 90, linebreaks: { automatic: true } },
"HTML-CSS": { scale: 90, linebreaks: { automatic: true } },
TeX: {
Macros: {
pr : ['|\#1\\rangle\\langle\#1|',1],
Expand All @@ -38,19 +38,17 @@
vac: ['\\text{vac}',0],
I: ['I',0],
x: ['\\hat{x}',0],
q: ['\\hat{q}',0],
p: ['\\hat{p}',0],
p: ['\\hat{p}',0],
a: ['\\hat{a}',0],
ad: ['\\hat{a}^\\dagger',0],
r: ['\\hat{\\mathbf{r}}',0],
av: ['\\hat{\\mathbf{a}}',0],
n: ['\\hat{n}',0],
nbar: ['\\overline{n}',0],
sech: ['\\mathrm{sech~}',0],
tanh: ['\\mathrm{tanh~}',0],
re: ['\\text{Re}',0],
im: ['\\text{Im}',0],
tr: ['\\mathrm{Tr} #1',1],
diag: ['\\mathrm{diag} #1',1],
sign: ['\\text{sign}',0],
overlr: ['\\overset\\leftrightarrow{\#1}',1],
overl: ['\\overset\leftarrow{\#1}',1],
Expand All @@ -63,7 +61,7 @@
}
});
</script>

{%- block ga %}
{%- if theme_google_analytics_account %}
<!-- Global site tag (gtag.js) - Google Analytics -->
Expand Down Expand Up @@ -206,6 +204,25 @@
</div>
{% endblock %}
<div class="document clearer body">

{% if theme_gallery_dirs in pagename %}
<div class="xanadu-call-to-action-links">
<div id="tutorial-type">{{ pagename }}</div>
<div id="download-python-link">
<i class="fab fa-python"></i>&nbsp;
<div class="call-to-action-desktop-view">Download Python script</div>
</div>
<div id="download-notebook-link">
<i class="fas fa-download"></i>&nbsp;
<div class="call-to-action-desktop-view">Download Notebook</div>
</div>
<div id="github-view-link">
<i class="fab fa-github"></i>&nbsp;
<div class="call-to-action-desktop-view">View on GitHub</div>
</div>
</div>
{% endif %}

{% block body %} {% endblock %}
</div>
{%- block bottom_rel_links %}
Expand Down Expand Up @@ -250,9 +267,11 @@
$('.logo-small').addClass('active');
$(".nano").nanoScroller({ scrollTo: $('.current') });
} else {
// $('.text-logo').addClass('active');
// $('.logo').removeClass('active');
// $('.logo-small').addClass('active');
{% if theme_large_toc %}
$('.text-logo').addClass('active');
$('.logo').removeClass('active');
$('.logo-small').addClass('active');
{% endif %}
$(".nano").nanoScroller({ scrollTop: 93 });
}
}
Expand All @@ -276,9 +295,29 @@
});
});
</script>
<script type="text/javascript">
var downloadNote = $(".sphx-glr-download-link-note.admonition.note");
if (downloadNote.length >= 1) {
var tutorialUrlArray = $("#tutorial-type").text().split('/');
tutorialUrlArray[0] = "examples"

var githubLink = "https://github.com/" + "{{ theme_github_repo }}" + "/blob/master/" + tutorialUrlArray.join("/") + ".py",
pythonLink = $(".reference.download")[0].href,
notebookLink = $(".reference.download")[1].href,
notebookDownloadPath = notebookLink.split('_downloads')[1].split('/').pop();

$("#download-python-link").wrap("<a href=" + pythonLink + " data-behavior='call-to-action-event' data-response='Download Python script' download target='_blank'/>");
$("#download-notebook-link").wrap("<a href=" + notebookLink + " data-behavior='call-to-action-event' data-response='Download Notebook' download target='_blank'/>");
$("#github-view-link").wrap("<a href=" + githubLink + " data-behavior='call-to-action-event' data-response='View on Github' target='_blank'/>");
} else {
$(".xanadu-call-to-action-links").hide();
}
</script>
{%- block footer_wrapper %}
<div class="footer">
{{ copyright }} Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
{{ copyright }}
<br>
Documentation created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
{%- endblock %}
{%- endblock %}
4 changes: 2 additions & 2 deletions doc/xanadu_theme/logo-text.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a href="http://xanadu.ai" class="text-logo">
<img src="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" class="logo active" width=80%></img>
<img src="{{ pathto('_static/logo_new_small.png', 1) }}" class="logo-small" width=80%></img>
<img src="{{ pathto(theme_touch_icon, 1) }}" class="logo active" width=80%></img>
<img src="{{ pathto(theme_touch_icon_small, 1) }}" class="logo-small" width=80%></img>
<!-- <span id="project-name">{{ theme_project_nav_name or shorttitle }}</span> -->
</a>
Loading

0 comments on commit b7ebd31

Please sign in to comment.