Skip to content

Commit

Permalink
Merge dev into master 0.30 (#768)
Browse files Browse the repository at this point in the history
* Development branch

* Bumped requirement package versions (#667)

* Bumped jax versions

* Updated neural-tangents

* Merge dev in master following v0.28.0 release of PennyLane (#671) (#672)

* Development branch

* Bumped requirement package versions (#667)

* Bumped jax versions

* Updated neural-tangents

* Apply suggestions from code review

Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: GitHub Nightly Merge Action <[email protected]>
Co-authored-by: Rashid N H M <[email protected]>

Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: GitHub Nightly Merge Action <[email protected]>

* Update chemical reactions demo to use pyscf for openshell H3 (#704)

* use pyscf for openshell H3

* change date and fix interface warning

* Change ibm device in Quantum volume (#703)

* Ibm oslo

* Update to new hardware

* Change to Lima

* Typo

* Replace

* One below

* Update demos to remove warnings (#705)

* Added interface, removed deprecated functionality

* Addressing PR comments

---------

Co-authored-by: Romain Moyard <[email protected]>

* Update classical shadows (#708)

* More

* typo

* Trigger CI

* lightning req no depth

* Trigger CI

* Update SPSA demo to count circuit executions manually. (#706)

* new version of SPSA demo

* Update demonstrations/spsa.py

Co-authored-by: Josh Izaac <[email protected]>

* simplify code, update outputs and figures

* Apply suggestions from code review

Co-authored-by: Romain Moyard <[email protected]>

* review and tweaking

* make spsa an executing tutorial

* move file

* fix links

* fix some more links

* author bio

* line breaks, undo link change, fixing them actually

* links...

* links again... bio

* update to count executions manually

* reword device executions -> circuit executions. avoid recreating device and qnode

* print executions

---------

Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: Romain Moyard <[email protected]>

* Updated adaptive circuits demo for new return type (#735)

* Update automatically run demos to be able to execute with v0.30 (#741)

* fix toric code and classical kernels demos (#740)

* FIx photonics and noisy demos (#742)

* FIx two demos

* small change

* wrap relevant results in np.array (#743)

* Updated demos to work with return types (#744)

* Update demos for new return types (#754)

* remove pennylane-sf from dependencies

* try to use developement lightning

* force upgrade of lightnign

* make tutorial_gbs non-executable

---------

Co-authored-by: Romain Moyard <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: lillian542 <[email protected]>

* remove nlopt from list of requirements (#755)

* use dev version of lightning for demo checker (#759)

* Improve formatting of output in toric code demo (#762)

* round outputs on toric code

* Update demonstrations/tutorial_toric_code.py

Co-authored-by: Mudit Pandey <[email protected]>

---------

Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>

* use lightning in quantumvolume; fix qnspsa for new return; use H.sparse_matrix (#757)

* use lightning in quantumvolume; fix qnspsa for new return

* stop using sparse_hamiltonian

* Update manually run demos (#766)

* Added changes to manual demos

* Updated output as found in rerun

* Trigger CI

* Add warnings to pennylane-sf plugins and expected output (#761)

* add warnings to pennylane-sf plugins, add output

* Apply suggestions from code review

Co-authored-by: Tom Bromley <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>

* add warning to quantum neural net

---------

Co-authored-by: Tom Bromley <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>

* revert workflow changes

* add small gbs fixes

* trigger ci

* image link wrong

* trigger ci

---------

Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: GitHub Nightly Merge Action <[email protected]>
Co-authored-by: Rashid N H M <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Romain Moyard <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: trbromley <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>
  • Loading branch information
13 people authored May 2, 2023
1 parent 41b915a commit 34f81c1
Show file tree
Hide file tree
Showing 42 changed files with 289 additions and 81 deletions.
Binary file modified demonstrations/adjoint_diff/scaling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 14 additions & 9 deletions demonstrations/ensemble_multi_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from collections import Counter

import dask
import matplotlib.pyplot as plt
import numpy as np
import pennylane as qml
Expand Down Expand Up @@ -229,14 +230,14 @@ def circuit1(params, x=None):


##############################################################################
# We finally combine the two devices into a :class:`~.pennylane.QNodeCollection` that uses the
# We finally combine the two devices into a :class:`~.pennylane.QNode` list that uses the
# PyTorch interface:


qnodes = qml.QNodeCollection(
[qml.QNode(circuit0, dev0, interface="torch"),
qml.QNode(circuit1, dev1, interface="torch")]
)
qnodes = [
qml.QNode(circuit0, dev0, interface="torch"),
qml.QNode(circuit1, dev1, interface="torch"),
]

##############################################################################
# Postprocessing into a prediction
Expand All @@ -245,19 +246,23 @@ def circuit1(params, x=None):
# The ``predict_point`` function below allows us to find the ensemble prediction, as well as keeping
# track of the individual predictions from each QPU.
#
# We include a ``parallel`` keyword argument for evaluating the :class:`~.pennylane.QNodeCollection`
# We include a ``parallel`` keyword argument for evaluating the :class:`~.pennylane.QNode` list
# in a parallel asynchronous manner. This feature requires the ``dask`` library, which can be
# installed using ``pip install "dask[delayed]"``. When ``parallel=True``, we are able to make
# predictions faster because we do not need to wait for one QPU to output before running on the
# other.


def decision(softmax):
return int(torch.argmax(softmax))


def predict_point(params, x_point=None, parallel=True):
results = qnodes(params, x=x_point, parallel=parallel)
if parallel:
results = tuple(dask.delayed(q)(params, x=x_point) for q in qnodes)
results = torch.tensor(dask.compute(*results, scheduler="threads"))
else:
results = tuple(q(params, x=x_point) for q in qnodes)
results = torch.tensor(results)
softmax = torch.nn.functional.softmax(results, dim=1)
choice = torch.where(softmax == torch.max(softmax))[0][0]
chosen_softmax = softmax[choice]
Expand Down Expand Up @@ -364,7 +369,7 @@ def accuracy(predictions, actuals):
#
# Training accuracy (ensemble): 0.824
# Training accuracy (QPU0): 0.648
# Training accuracy (QPU1): 0.28
# Training accuracy (QPU1): 0.296

##############################################################################

Expand Down
Binary file modified demonstrations/ensemble_multi_qpu/ensemble_multi_qpu_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demonstrations/ensemble_multi_qpu/ensemble_multi_qpu_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demonstrations/ensemble_multi_qpu/ensemble_multi_qpu_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demonstrations/ensemble_multi_qpu/ensemble_multi_qpu_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
116 changes: 106 additions & 10 deletions demonstrations/tutorial_gbs.py → demonstrations/gbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.. meta::
:property="og:description": Using light to perform tasks beyond the reach of classical computers.
:property="og:image": https://pennylane.ai/qml/_images/tutorial_gbs_expt2.png
:property="og:image": https://pennylane.ai/qml/_images/gbs_expt2.png
.. related::
Expand All @@ -19,6 +19,9 @@
*Authors: Josh Izaac and Nathan Killoran — Posted: 04 December 2020. Last updated: 04 December 2020.*
.. warning::
This demo is only compatible with PennyLane version ``0.29`` or below.
On the journey to large-scale fault-tolerant quantum computers, one of the first major
milestones is to demonstrate a quantum device carrying out tasks that are beyond the reach of
any classical algorithm. The launch of Xanadu's Borealis device marked an important milestone
Expand All @@ -45,12 +48,12 @@
|
.. image:: /demonstrations/tutorial_gbs_expt2.png
.. image:: /demonstrations/gbs_expt2.png
:align: center
:width: 80%
:target: javascript:void(0);
.. figure:: /demonstrations/tutorial_gbs_expt1.png
.. figure:: /demonstrations/gbs_expt1.png
:align: center
:width: 80%
:target: javascript:void(0);
Expand Down Expand Up @@ -116,7 +119,7 @@
matrix :math:`U`. When decomposed into a quantum optical circuit, the interferometer will
be made up of beamsplitters and phase shifters.
.. image:: /demonstrations/tutorial_gbs_circuit2.png
.. image:: /demonstrations/gbs_circuit2.png
:align: center
:width: 90%
:target: javascript:void(0);
Expand Down Expand Up @@ -147,7 +150,22 @@
U = unitary_group.rvs(4)
print(U)

######################################################################
##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# [[ 0.23648826-0.48221431j 0.06829648+0.04447898j 0.51150074-0.09529866j
# 0.55205719-0.35974699j]
# [-0.11148167+0.69780321j -0.24943828+0.08410701j 0.46705929-0.43192981j
# 0.16220654-0.01817602j]
# [-0.22351926-0.25918352j 0.24364996-0.05375623j -0.09259829-0.53810588j
# 0.27267708+0.66941977j]
# [ 0.11519953-0.28596729j -0.90164923-0.22099186j -0.09627758-0.13105595j
# -0.0200152 +0.12766128j]]
#
# We can now use this to construct the circuit, choosing a compatible
# device. For the simulation, we can use the Strawberry Fields
# Gaussian backend. This backend is perfectly suited for simulation of GBS,
Expand Down Expand Up @@ -197,7 +215,16 @@ def gbs_circuit():
probs = gbs_circuit().reshape([cutoff] * n_wires)
print(probs.shape)

######################################################################
##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# (10, 10, 10, 10)
#
#
# For example, element ``[1,2,0,1]`` represents the probability of
# detecting 1 photon on wire
# ``0`` and wire ``3``, and 2 photons at wire ``1``, i.e., the value
Expand All @@ -214,7 +241,19 @@ def gbs_circuit():
for i in measure_states:
print(f"|{''.join(str(j) for j in i)}>: {probs[i]}")

######################################################################
##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# |0000>: 0.17637844761413496
# |1100>: 0.03473293649420282
# |0101>: 0.011870900427255589
# |1111>: 0.005957399165336106
# |2000>: 0.02957384308320549
#
# The GBS Distribution
# --------------------
#
Expand Down Expand Up @@ -292,6 +331,16 @@ def gbs_circuit():

print(A[:, [0, 1]][[0, 1]])

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# [[ 0.19343159-0.54582922j 0.43418269-0.09169615j]
# [ 0.43418269-0.09169615j -0.27554025-0.46222197j]]
#
######################################################################
# i.e., we consider only the rows and columns where a photon was detected, which gives us
# the submatrix corresponding to indices :math:`0` and :math:`1`.
Expand All @@ -310,21 +359,50 @@ def gbs_circuit():
print(1 / np.cosh(1) ** 4)
print(probs[0, 0, 0, 0])

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# 0.1763784476141347
# 0.17637844761413496
#
######################################################################
# **Measuring** :math:`|1,1,0,0\rangle` **at the output**

A = (np.dot(U, U.T) * np.tanh(1))[:, [0, 1]][[0, 1]]
print(np.abs(haf(A)) ** 2 / np.cosh(1) ** 4)
print(probs[1, 1, 0, 0])

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# 0.03473293649420271
# 0.03473293649420282
#
######################################################################
# **Measuring** :math:`|0,1,0,1\rangle` **at the output**

A = (np.dot(U, U.T) * np.tanh(1))[:, [1, 3]][[1, 3]]
print(np.abs(haf(A)) ** 2 / np.cosh(1) ** 4)
print(probs[0, 1, 0, 1])

######################################################################
##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# 0.011870900427255558
# 0.011870900427255589
#
# **Measuring** :math:`|1,1,1,1\rangle` **at the output**
#
# This corresponds to the hafnian of the full matrix :math:`A=UU^T\mathrm{tanh}(r)`:
Expand All @@ -333,7 +411,16 @@ def gbs_circuit():
print(np.abs(haf(A)) ** 2 / np.cosh(1) ** 4)
print(probs[1, 1, 1, 1])

######################################################################
##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# 0.005957399165336081
# 0.005957399165336106
#
# **Measuring** :math:`|2,0,0,0\rangle` **at the output**
#
# Since we have two photons in mode ``q[0]``, we take two copies of the
Expand All @@ -343,7 +430,16 @@ def gbs_circuit():
print(np.abs(haf(A)) ** 2 / (2 * np.cosh(1) ** 4))
print(probs[2, 0, 0, 0])

######################################################################
##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# 0.029573843083205383
# 0.02957384308320549
#
# The PennyLane simulation results agree (with almost negligible numerical error) to the
# expected result from the Gaussian boson sampling equation!
#
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"seoDescription": "This tutorial introduces the notion of hybrid computation by combining several PennyLane device backends to train an algorithm containing both photonic and qubit devices.",
"doi": "",
"canonicalURL": "https://pennylane.ai/qml/demos/tutorial_plugins_hybrid.html",
"canonicalURL": "https://pennylane.ai/qml/demos/plugins_hybrid.html",
"references": [],
"basedOnPapers": [],
"referencedByPapers": [],
Expand Down
Loading

0 comments on commit 34f81c1

Please sign in to comment.