Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into master 0.30 #768

Merged
merged 90 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
5743fa5
Development branch
josh146 Nov 15, 2022
39ca8c1
Merge branch 'master' into dev
actions-user Nov 18, 2022
17fdcb4
Merge branch 'master' into dev
actions-user Nov 21, 2022
47e83e1
Merge branch 'master' into dev
actions-user Nov 21, 2022
12ef0b8
Merge branch 'master' into dev
actions-user Nov 22, 2022
ecad024
Merge branch 'master' into dev
actions-user Nov 23, 2022
b0fb42b
Merge branch 'master' into dev
actions-user Nov 25, 2022
f39ee3f
Merge branch 'master' into dev
actions-user Nov 28, 2022
00becee
Merge branch 'master' into dev
actions-user Nov 28, 2022
3685225
Merge branch 'master' into dev
actions-user Nov 29, 2022
ce0d527
Merge branch 'master' into dev
actions-user Dec 1, 2022
8a86295
Merge branch 'master' into dev
actions-user Dec 2, 2022
7a323e1
Merge branch 'master' into dev
actions-user Dec 5, 2022
289baab
Merge branch 'master' into dev
actions-user Dec 7, 2022
b91874b
Merge branch 'master' into dev
actions-user Dec 9, 2022
9c92f0e
Merge branch 'master' into dev
actions-user Dec 10, 2022
1d32d2b
Merge branch 'master' into dev
actions-user Dec 12, 2022
8c25d7d
Merge branch 'master' into dev
actions-user Dec 12, 2022
222e6a6
Merge branch 'master' into dev
actions-user Dec 16, 2022
a8284e3
Bumped requirement package versions (#667)
rashidnhm Dec 19, 2022
ccfcf45
Merge dev in master following v0.28.0 release of PennyLane (#671) (#672)
rashidnhm Dec 21, 2022
808b1d8
Merge branch 'master' into dev
rashidnhm Dec 21, 2022
00a7c8c
Merge branch 'master' into dev
actions-user Jan 3, 2023
bf00d71
Merge branch 'master' into dev
actions-user Jan 4, 2023
cc47e89
Merge branch 'master' into dev
actions-user Jan 5, 2023
b3f7f3e
Merge branch 'master' into dev
actions-user Jan 5, 2023
9316a8f
Merge branch 'master' into dev
actions-user Jan 18, 2023
eb7a990
Merge branch 'master' into dev
actions-user Jan 20, 2023
595b898
Merge branch 'master' into dev
actions-user Jan 23, 2023
03ee056
Merge branch 'master' into dev
actions-user Jan 23, 2023
76d7343
Merge branch 'master' into dev
actions-user Jan 30, 2023
5281bd8
Merge branch 'master' into dev
actions-user Feb 3, 2023
dadd39c
Merge branch 'master' into dev
actions-user Feb 3, 2023
a8ab874
Merge branch 'master' into dev
actions-user Feb 6, 2023
b39a0e7
Merge branch 'master' into dev
actions-user Feb 6, 2023
4f65f43
Merge branch 'master' into dev
actions-user Feb 10, 2023
673e059
Merge branch 'master' into dev
actions-user Feb 14, 2023
34b6c43
Merge branch 'master' into dev
actions-user Feb 21, 2023
3b40e58
Merge branch 'master' into dev
actions-user Feb 21, 2023
8356cca
Update chemical reactions demo to use pyscf for openshell H3 (#704)
soranjh Feb 21, 2023
10d6d86
Change ibm device in Quantum volume (#703)
rmoyard Feb 22, 2023
ab34e2a
Update demos to remove warnings (#705)
mudit2812 Feb 22, 2023
e8811cd
Update classical shadows (#708)
rmoyard Feb 23, 2023
942cbb5
Update SPSA demo to count circuit executions manually. (#706)
dwierichs Feb 24, 2023
c2bcccb
Merge branch 'master' into dev
actions-user Feb 24, 2023
62295af
Merge branch 'master' into dev
actions-user Feb 28, 2023
f98c1ec
Merge branch 'master' into dev
trbromley Mar 1, 2023
fd6fb94
Merge branch 'master' into dev
actions-user Mar 3, 2023
cf7ddcf
Merge branch 'master' into dev
actions-user Mar 3, 2023
3e34def
Merge branch 'master' into dev
rashidnhm Mar 15, 2023
f487736
Merge branch 'master' into dev
actions-user Mar 16, 2023
a2c4aac
Merge branch 'master' into dev
actions-user Mar 17, 2023
580ea7b
Merge branch 'master' into dev
actions-user Mar 20, 2023
36bd9a7
Merge branch 'master' into dev
actions-user Mar 22, 2023
125fe67
Merge branch 'master' into dev
actions-user Mar 22, 2023
a8cb199
Merge branch 'master' into dev
actions-user Mar 24, 2023
649de42
Merge branch 'master' into dev
actions-user Apr 3, 2023
3471f48
Merge branch 'master' into dev
actions-user Apr 4, 2023
59d2d60
Merge branch 'master' into dev
actions-user Apr 4, 2023
ff563c6
Merge branch 'master' into dev
actions-user Apr 4, 2023
e68fa30
Merge branch 'master' into dev
actions-user Apr 10, 2023
432b6e9
Merge branch 'master' into dev
actions-user Apr 10, 2023
dbccd02
Merge branch 'master' into dev
actions-user Apr 10, 2023
ce4d5bb
Updated adaptive circuits demo for new return type (#735)
mudit2812 Apr 14, 2023
ef4184f
Merge branch 'master' into dev
actions-user Apr 17, 2023
a5ad1d6
Merge branch 'master' into dev
actions-user Apr 18, 2023
d6b47ac
Merge branch 'master' into dev
actions-user Apr 18, 2023
d770e5b
Merge branch 'master' into dev
actions-user Apr 19, 2023
16b4dd2
Merge branch 'master' into dev
actions-user Apr 19, 2023
1e61f33
Merge branch 'master' into dev
actions-user Apr 21, 2023
3cdc59a
Merge branch 'master' into dev
actions-user Apr 22, 2023
a84c9a9
Merge branch 'master' into dev
actions-user Apr 24, 2023
7e4dfe9
Update automatically run demos to be able to execute with v0.30 (#741)
albi3ro Apr 24, 2023
be299d6
remove nlopt from list of requirements (#755)
albi3ro Apr 24, 2023
ba04866
Merge branch 'master' into dev
actions-user Apr 24, 2023
11991f5
use dev version of lightning for demo checker (#759)
albi3ro Apr 25, 2023
d494b50
Improve formatting of output in toric code demo (#762)
albi3ro Apr 26, 2023
c219606
Merge branch 'master' into dev
actions-user Apr 26, 2023
30a6039
use lightning in quantumvolume; fix qnspsa for new return; use H.spar…
timmysilv Apr 27, 2023
63a7104
Merge branch 'master' into dev
actions-user Apr 27, 2023
8c7e4cd
Merge branch 'master' into dev
actions-user Apr 28, 2023
ba89a43
Merge branch 'master' into dev
actions-user Apr 28, 2023
680d318
Merge branch 'master' into dev
actions-user Apr 28, 2023
1ce2d79
Update manually run demos (#766)
mudit2812 Apr 28, 2023
ad2e71d
Add warnings to pennylane-sf plugins and expected output (#761)
albi3ro Apr 28, 2023
cd610b2
revert workflow changes
albi3ro May 1, 2023
bfa4cbc
add small gbs fixes
albi3ro May 2, 2023
1d4192d
trigger ci
albi3ro May 2, 2023
bd9093d
image link wrong
albi3ro May 2, 2023
e509410
trigger ci
albi3ro May 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
103 changes: 101 additions & 2 deletions demonstrations/tutorial_gbs.py → demonstrations/gbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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,6 +215,15 @@ 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
Expand All @@ -214,6 +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 +332,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,20 +360,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**
#
Expand All @@ -333,6 +413,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**
#
Expand All @@ -343,7 +433,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
Be sure to read through the introductory :ref:`qubit rotation <qubit_rotation>` and
:ref:`Gaussian transformation <gaussian_transformation>` tutorials before attempting this tutorial.

.. warning::
This demo is only compatible with PennyLane version ``0.29`` or below.

.. note::

To follow along with this tutorial on your own computer, you will require the
Expand Down Expand Up @@ -195,6 +198,16 @@ def cost(params):
init_params = np.array([0.01, 0.01], requires_grad=True)
print(cost(init_params))

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# -9.999666671111081e-05
#

##############################################################################
# Here, we choose the values of :math:`\theta` and :math:`\phi` to be very close to zero;
# this results in :math:`B(\theta,\phi)\approx I`, and the output of the quantum
Expand All @@ -212,6 +225,16 @@ def cost(params):
dphoton_redirection = qml.grad(photon_redirection, argnum=0)
print(dphoton_redirection([0.0, 0.0]))

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# [array(0.), array(0.)]
#

##############################################################################
# Now, let's use the :class:`~.pennylane.GradientDescentOptimizer`, and update the circuit
# parameters over 100 optimization steps.
Expand All @@ -233,6 +256,36 @@ def cost(params):

print("Optimized rotation angles: {}".format(params))

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# Cost after step 5: -0.0349558
# Cost after step 10: -0.9969017
# Cost after step 15: -1.0000000
# Cost after step 20: -1.0000000
# Cost after step 25: -1.0000000
# Cost after step 30: -1.0000000
# Cost after step 35: -1.0000000
# Cost after step 40: -1.0000000
# Cost after step 45: -1.0000000
# Cost after step 50: -1.0000000
# Cost after step 55: -1.0000000
# Cost after step 60: -1.0000000
# Cost after step 65: -1.0000000
# Cost after step 70: -1.0000000
# Cost after step 75: -1.0000000
# Cost after step 80: -1.0000000
# Cost after step 85: -1.0000000
# Cost after step 90: -1.0000000
# Cost after step 95: -1.0000000
# Cost after step 100: -1.0000000
# Optimized rotation angles: [1.57079633 0.01 ]
#
#

##############################################################################
# Comparing this to the :ref:`exact calculation <photon_redirection_calc>` above,
Expand Down Expand Up @@ -342,6 +395,37 @@ def cost(params, phi1=0.5, phi2=0.1):

print("Optimized rotation angles: {}".format(params))


##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# Cost after step 5: 0.2154539
# Cost after step 10: 0.0000982
# Cost after step 15: 0.0000011
# Cost after step 20: 0.0000000
# Cost after step 25: 0.0000000
# Cost after step 30: 0.0000000
# Cost after step 35: 0.0000000
# Cost after step 40: 0.0000000
# Cost after step 45: 0.0000000
# Cost after step 50: 0.0000000
# Cost after step 55: 0.0000000
# Cost after step 60: 0.0000000
# Cost after step 65: 0.0000000
# Cost after step 70: 0.0000000
# Cost after step 75: 0.0000000
# Cost after step 80: 0.0000000
# Cost after step 85: 0.0000000
# Cost after step 90: 0.0000000
# Cost after step 95: 0.0000000
# Cost after step 100: 0.0000000
# Optimized rotation angles: [1.20671364 0.01 ]
#
#
##############################################################################
# Substituting this into the photon redirection QNode shows that it now produces
# the same output as the qubit rotation QNode:
Expand All @@ -350,6 +434,16 @@ def cost(params, phi1=0.5, phi2=0.1):
print(photon_redirection(result))
print(qubit_rotation(0.5, 0.1))

##############################################################################
# .. rst-class:: sphx-glr-script-out
#
# Out:
#
# .. code-block:: none
#
# 0.8731983021146449
# 0.8731983044562817
#
##############################################################################
# This is just a simple example of the kind of hybrid computation that can be carried
# out in PennyLane. Quantum nodes (bound to different devices) and classical
Expand Down
Loading