Skip to content

Commit

Permalink
Dev to master (#1044)
Browse files Browse the repository at this point in the history
A copy of dev to merge to master following the PL 0.35 release

---------

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: 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: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>
Co-authored-by: Guillermo Alonso-Linaje <[email protected]>
Co-authored-by: CatalinaAlbornoz <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: ixfoduap <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Utkarsh <[email protected]>
Co-authored-by: Stepan Fomichev <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Alvaro Ballon <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Lee J. O'Riordan <[email protected]>
Co-authored-by: Korbinian Kottmann <[email protected]>
Co-authored-by: DanielNino27 <[email protected]>
  • Loading branch information
1 parent ed5d5d3 commit d42cf7e
Show file tree
Hide file tree
Showing 20 changed files with 661 additions and 81 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
from jinja2 import FileSystemLoader, Environment
import yaml
from pennylane import PennyLaneDeprecationWarning

sys.path.insert(0, os.path.abspath("."))

Expand Down Expand Up @@ -104,6 +105,9 @@
message=r"Creating an ndarray from ragged"
)

# Raise PennyLane deprecation warnings as errors
warnings.filterwarnings("error", category=PennyLaneDeprecationWarning)

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
5 changes: 3 additions & 2 deletions demonstrations/braket-parallel-gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,16 +475,17 @@ def qaoa_training(n_iterations, n_layers=2):
braket_tasks_cost = Tracker().start() # track Braket quantum tasks costs

# declare PennyLane device
dev = qml.device("lightning.qubit", wires=wires)
dev = qml.device("lightning.qubit", wires=n_wires)

@qml.qnode(dev)
def cost_function(params, **kwargs):
for i in range(wires): # Prepare an equal superposition over all qubits
for i in range(n_wires): # Prepare an equal superposition over all qubits
qml.Hadamard(wires=i)
qml.layer(qaoa_layer, n_layers, params[0], params[1])
return qml.expval(cost_h)

params = 0.01 * np.random.uniform(size=[2, n_layers])
optimizer = qml.AdagradOptimizer(stepsize=0.01)

# run the classical-quantum iterations
for i in range(n_iterations):
Expand Down
24 changes: 12 additions & 12 deletions demonstrations/ensemble_multi_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
# /interfaces.html>`_, which can be installed from `here
# <https://pytorch.org/get-started/locally/>`__.
#
# .. warning::
# Rigetti's QVM and Quil Compiler services must be running for this tutorial to execute. They
# can be installed by consulting the `Rigetti documentation
# <http://docs.rigetti.com/qcs/>`__ or, for users with Docker, by running:
#
# .. code-block:: bash
#
# docker run -d -p 5555:5555 rigetti/quilc -R -p 5555
# docker run -d -p 5000:5000 rigetti/qvm -S -p 5000
#
# Load data
# ---------
#
Expand Down Expand Up @@ -186,15 +196,6 @@ def plot_points(x_train, y_train, x_test, y_test):
# swap ``qiskit.aer`` for ``qiskit.ibmq`` and specify their chosen backend (see `here
# <https://docs.pennylane.ai/projects/qiskit/en/latest/devices/ibmq.html>`__).
#
# .. warning::
# Rigetti's QVM and Quil Compiler services must be running for this tutorial to execute. They
# can be installed by consulting the `Rigetti documentation
# <http://docs.rigetti.com/qcs/>`__ or, for users with Docker, by running:
#
# .. code-block:: bash
#
# docker run -d -p 5555:5555 rigetti/quilc -R -p 5555
# docker run -d -p 5000:5000 rigetti/qvm -S -p 5000
#
# The circuits for both QPUs are shown in the figure below:
#
Expand Down Expand Up @@ -259,9 +260,8 @@ def decision(softmax):

def predict_point(params, x_point=None, parallel=True):
if parallel:
results = tuple(dask.delayed(q)(params, x=x_point) for q in qnodes)
results = dask.compute(*results, scheduler="threads")
results = torch.tensor(torch.vstack(results))
results = tuple(dask.delayed(q)(params, x=torch.from_numpy(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)
Expand Down
4 changes: 2 additions & 2 deletions demonstrations/function_fitting_qsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def QSP_circ(phi, W):

for i in range(5):
phi = torch.rand(d + 1, generator=gen) * 2 * torch.tensor([math.pi], requires_grad=False)
matrix_func = qml.matrix(QSP_circ)
matrix_func = qml.matrix(QSP_circ, wire_order=[0])
y_vals = [matrix_func(phi, w)[0, 0].real for w in w_mats]

plt.plot(a_vals, y_vals, label=f"poly #{i}")
Expand Down Expand Up @@ -307,7 +307,7 @@ def __init__(self, degree, num_vals, random_seed=None):
def forward(self, omega_mats):
"""PennyLane forward implementation"""
y_pred = []
generate_qsp_mat = qml.matrix(QSP_circ)
generate_qsp_mat = qml.matrix(QSP_circ, wire_order=[0])

for w in omega_mats:
u_qsp = generate_qsp_mat(self.phi, w)
Expand Down
23 changes: 21 additions & 2 deletions demonstrations/getting_started_with_hybrid_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,34 @@ def qubit_rotation(num_steps=10, stepsize=0.5):
# you may provide the device argument as string of the form: ``"local:<provider>/<simulator_name>"`` or simply ``None``.
# For example, you may set ``"local:pennylane/lightning.qubit"`` for the `PennyLane lightning simulator <https://pennylane.ai/performance>`__.
#
# In the following code, we annotate the ``qubit_rotation`` function from above.
# In the following code, we annotate the ``qubit_rotation`` function from above. It is redefined inside the
# `hybrid_job` context as the job only has access to local variables and functions.
#

from braket.jobs import hybrid_job


@hybrid_job(device="local:pennylane/lightning.qubit")
def qubit_rotation_hybrid_job(num_steps=1, stepsize=0.5):
return qubit_rotation(num_steps=num_steps, stepsize=stepsize)
device = qml.device("lightning.qubit", wires=1)

@qml.qnode(device)
def circuit(params):
qml.RX(params[0], wires=0)
qml.RY(params[1], wires=0)
return qml.expval(qml.PauliZ(0))

opt = qml.GradientDescentOptimizer(stepsize=stepsize)
params = np.array([0.5, 0.75])

for i in range(num_steps):
# update the circuit parameters
params = opt.step(circuit, params)
expval = circuit(params)

log_metric(metric_name="expval", iteration_number=i, value=expval)

return params


######################################################################
Expand Down
13 changes: 10 additions & 3 deletions demonstrations/pytorch_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
To follow along with this tutorial on your own computer, you will require the
following dependencies:
* The `Rigetti SDK <https://qcs.rigetti.com/sdk-downloads>`_, which contains the quantum virtual
* Rigetti's QVM and Quil Compiler services. One option for setting this up is the
`Rigetti SDK <https://qcs.rigetti.com/sdk-downloads>`_, which contains the quantum virtual
machine (QVM) and quilc quantum compiler. Once installed, the QVM and quilc can be
started by running the commands ``quilc -S`` and ``qvm -S`` in separate terminal windows.
Alternatively, for users with Docker, the QVM and Quil Compiler services can be run with commands:
.. code-block:: bash
docker run -d -p 5555:5555 rigetti/quilc -R -p 5555
docker run -d -p 5000:5000 rigetti/qvm -S -p 5000
* `PennyLane-Rigetti plugin <https://docs.pennylane.ai/projects/rigetti/en/latest/>`_, in order
to access the QVM as a PennyLane device. This can be installed via pip:
Expand Down Expand Up @@ -198,7 +205,7 @@ def cost(phi, theta, step):
my_prefix = "Your-Folder-Name" # the name of the folder in the bucket
s3_folder = (my_bucket, my_prefix)

device_arn = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2"
device_arn = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3"

qpu = qml.device(
"braket.aws.qubit",
Expand All @@ -208,7 +215,7 @@ def cost(phi, theta, step):
)

# Note: swap dev to qpu here to use the QPU
# Warning: check the pricing of Aspen-M-2 on Braket to make
# Warning: check the pricing of Aspen-M-3 on Braket to make
# sure you are aware of the costs associated with running the
# optimization below.
@qml.qnode(dev, interface="torch")
Expand Down
6 changes: 3 additions & 3 deletions demonstrations/tutorial_apply_qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def my_circuit(phase_angles):

qsvt_y_vals = []
for x in x_vals:
poly_x = qml.matrix(qml.qsvt)(
poly_x = qml.matrix(qml.qsvt, wire_order=[0])(
x, phi_pyqsp, wires=[0], convention="Wx" # specify angles using convention=`Wx`
)
qsvt_y_vals.append(np.real(poly_x[0, 0]))
Expand Down Expand Up @@ -219,7 +219,7 @@ def target_func(x):
def loss_func(phi):
sum_square_error = 0
for x in samples_x:
qsvt_matrix = qml.matrix(sum_even_odd_circ)(x, phi, ancilla_wire="ancilla", wires=[0])
qsvt_matrix = qml.matrix(sum_even_odd_circ, wire_order=["ancilla", 0])(x, phi, ancilla_wire="ancilla", wires=[0])
qsvt_val = qsvt_matrix[0, 0]
sum_square_error += (np.real(qsvt_val) - target_func(x)) ** 2

Expand Down Expand Up @@ -256,7 +256,7 @@ def loss_func(phi):

samples_x = np.linspace(0, 1, 100)
qsvt_y_vals = [
np.real(qml.matrix(sum_even_odd_circ)(x, phi, "ancilla", wires=[0])[0, 0])
np.real(qml.matrix(sum_even_odd_circ, wire_order=["ancilla", 0])(x, phi, "ancilla", wires=[0])[0, 0])
for x in samples_x
]

Expand Down
5 changes: 3 additions & 2 deletions demonstrations/tutorial_classically_boosted_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,15 @@ def circuit_product_state(state):
qml.BasisState(state, range(qubits))


Uq = qml.matrix(circuit_VQE)(theta_opt, range(qubits))
wire_order = list(range(qubits))
Uq = qml.matrix(circuit_VQE, wire_order=wire_order)(theta_opt, wire_order)

H12 = 0
relevant_basis_states = np.array(
[[1, 1, 0, 0], [0, 1, 1, 0], [1, 0, 0, 1], [0, 0, 1, 1]], requires_grad=True
)
for j, basis_state in enumerate(relevant_basis_states):
Ucl = qml.matrix(circuit_product_state)(basis_state)
Ucl = qml.matrix(circuit_product_state, wire_order=wire_order)(basis_state)
probs = hadamard_test(Uq, Ucl)
# The projection Re(<phi_q|i>) corresponds to 2p-1
y = 2 * probs[0] - 1
Expand Down
3 changes: 2 additions & 1 deletion demonstrations/tutorial_intro_qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def qsvt_output(a):

eigvals = np.linspace(-1, 1, 16)
A = np.diag(eigvals) # 16-dim matrix
U_A = qml.matrix(qml.qsvt)(A, angles, wires=range(5)) # block-encoded in 5-qubit system
wire_order = list(range(5))
U_A = qml.matrix(qml.qsvt, wire_order=wire_order)(A, angles, wires=wire_order) # block-encoded in 5-qubit system

qsvt_A = np.real(np.diagonal(U_A))[:16] # retrieve transformed eigenvalues

Expand Down
2 changes: 1 addition & 1 deletion demonstrations/tutorial_lcu_blockencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def lcu_circuit(): # block_encode
return qml.state()


output_matrix = qml.matrix(lcu_circuit)()
output_matrix = qml.matrix(lcu_circuit, wire_order=[0, "ancilla"])()
print("Block-encoded projector:\n")
print(np.real(np.round(output_matrix,2)))

Expand Down
117 changes: 117 additions & 0 deletions demonstrations/tutorial_liealgebra.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"title": "Introducing (Dynamical) Lie Algebras for quantum practitioners",
"authors": [
{
"id": "korbinian_kottmann"
}
],
"dateOfPublication": "2024-02-27T00:00:00+00:00",
"dateOfLastModification": "2024-02-27T00:00:00+00:00",
"categories": [
"Quantum Computing",
"Getting Started"
],
"tags": [],
"previewImages": [
{
"type": "thumbnail",
"uri": "/_static/demonstration_assets/liealgebra/thumbnail_liealgebra.png"
},
{
"type": "large_thumbnail",
"uri": "/_static/large_demo_thumbnails/thumbnail_large_liealgebra.png"
}
],
"seoDescription": "A gentle introduction to Lie theory covering the basics of Lie algebras and Lie groups in the context of quantum computing.",
"doi": "",
"canonicalURL": "/qml/demos/tutorial_liealgebra",
"references": [
{
"id": "Wiersema",
"type": "preprint",
"title": "Classification of dynamical Lie algebras for translation-invariant 2-local spin systems in one dimension",
"authors": "Roeland Wiersema, Efekan Kökcü, Alexander F. Kemper, Bojko N. Bakalov",
"year": "2023",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.2309.05690",
"url": "https://arxiv.org/abs/2309.05690"
},
{
"id": "Meyer",
"type": "article",
"title": "Exploiting symmetry in variational quantum machine learning",
"authors": "Johannes Jakob Meyer, Marian Mularski, Elies Gil-Fuster, Antonio Anna Mele, Francesco Arzani, Alissa Wilms, Jens Eisert",
"year": "2022",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.2205.06217",
"url": "https://arxiv.org/abs/2205.06217"
},
{
"id": "Nguyen",
"type": "preprint",
"title": "Theory for Equivariant Quantum Neural Networks",
"authors": "Quynh T. Nguyen, Louis Schatzki, Paolo Braccia, Michael Ragone, Patrick J. Coles, Frederic Sauvage, Martin Larocca, M. Cerezo",
"year": "2022",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.2210.08566",
"url": "https://arxiv.org/abs/2210.08566"
},
{
"id": "Fontana",
"type": "article",
"title": "The Adjoint Is All You Need: Characterizing Barren Plateaus in Quantum Ansätze",
"authors": "Enrico Fontana, Dylan Herman, Shouvanik Chakrabarti, Niraj Kumar, Romina Yalovetzky, Jamie Heredge, Shree Hari Sureshbabu, Marco Pistoia",
"year": "2023",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.2309.07902",
"url": "https://arxiv.org/abs/2309.07902"
},
{
"id": "Ragone",
"type": "preprint",
"title": "A Unified Theory of Barren Plateaus for Deep Parametrized Quantum Circuits",
"authors": "Michael Ragone, Bojko N. Bakalov, Frédéric Sauvage, Alexander F. Kemper, Carlos Ortiz Marrero, Martin Larocca, M. Cerezo",
"year": "2023",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.2309.09342",
"url": "https://arxiv.org/abs/2309.09342"
},
{
"id": "Goh",
"type": "preprint",
"title": "Lie-algebraic classical simulations for variational quantum computing",
"authors": "Matthew L. Goh, Martin Larocca, Lukasz Cincio, M. Cerezo, Frédéric Sauvage",
"year": "2023",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.2308.01432",
"url": "https://arxiv.org/abs/2308.01432"
},
{
"id": "Somma",
"type": "preprint",
"title": "Quantum Computation, Complexity, and Many-Body Physics",
"authors": "Rolando D. Somma",
"year": "2005",
"publisher": "",
"journal": "",
"doi": "10.48550/arXiv.quant-ph/0512209",
"url": "https://arxiv.org/abs/quant-ph/0512209"
}
],
"basedOnPapers": [],
"referencedByPapers": [],
"relatedContent": [
{
"type": "demonstration",
"id": "tutorial_geometric_qml",
"weight": 1.0
}
]
}

Loading

0 comments on commit d42cf7e

Please sign in to comment.