Skip to content

Commit

Permalink
Replacement of legacy devices with default.qubit (#1176)
Browse files Browse the repository at this point in the history
**Summary:**
The legacy qubit devices `default.qubit.{tf,torch,jax,autograd,legacy}`
are now deprecated and need to be replaced with `default.qubit`.

[[sc-70260](https://app.shortcut.com/xanaduai/story/70260)]
  • Loading branch information
Shiro-Raven authored Aug 6, 2024
1 parent efe55a7 commit 951ac78
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 178 deletions.
42 changes: 23 additions & 19 deletions demonstrations/ahs_aquila.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,68 @@
}
],
"dateOfPublication": "2023-05-16T00:00:00+00:00",
"dateOfLastModification": "2024-07-10T00:00:00+00:00",
"categories": ["Quantum Hardware", "Devices and Performance", "Quantum Computing"],
"dateOfLastModification": "2024-07-31T00:00:00+00:00",
"categories": [
"Quantum Hardware",
"Devices and Performance",
"Quantum Computing"
],
"tags": [],
"previewImages": [
{
"type": "thumbnail",
"uri": "/_static/demonstration_assets/ahs_aquila/thumbnail_tutorial_pulse_on_hardware.png"
}
],
{
"type": "thumbnail",
"uri": "/_static/demonstration_assets/ahs_aquila/thumbnail_tutorial_pulse_on_hardware.png"
}
],
"seoDescription": "Perform measurements on neutral atom hardware through PennyLane",
"doi": "",
"canonicalURL": "/qml/demos/ahs_aquila",
"references": [
{
{
"id": "Semeghini",
"type": "article",
"title": "Probing topological spin liquids on a programmable quantum simulator",
"authors": "G. Semeghini, H. Levine, A. Keesling, S. Ebadi, T.T. Wang, D. Bluvstein, R. Verresen, H. Pichler, M. Kalinowski, R. Samajdar, A. Omran, S. Sachdev, A. Vishwanath, M. Greiner, V. Vuletic, M.D. Lukin",
"year": "2021",
"journal": "",
"url": "https://arxiv.org/abs/2104.04119"
},
{
},
{
"id": "Lienhard",
"type": "article",
"title": "Observing the Space- and Time-Dependent Growth of Correlations in Dynamically Tuned Synthetic Ising Models with Antiferromagnetic Interactions",
"authors": "V. Lienhard, S. de Léséleuc, D. Barredo, T. Lahaye, A. Browaeys, M. Schuler, L.-P. Henry, A.M. Läuchli",
"year": "2018",
"journal": "",
"url": "https://arxiv.org/abs/1711.01185"
},
{
},
{
"id": "BraketDevGuide",
"type": "webpage",
"title": "Hello AHS: Run your first Analog Hamiltonian Simulation",
"authors": "Amazon Web Services: Amazon Braket",
"journal": "",
"url": "https://docs.aws.amazon.com/braket/latest/developerguide/braket-get-started-hello-ahs.html"
},
{
},
{
"id": "Asthana2022",
"type": "article",
"title": "AWS Quantum Technologies Blog: Realizing quantum spin liquid phase on an analog Hamiltonian Rydberg simulator",
"authors": "Alexander Keesling, Eric Kessler, and Peter Komar",
"year": "2021",
"journal": "",
"url": "https://aws.amazon.com/blogs/quantum-computing/realizing-quantum-spin-liquid-phase-on-an-analog-hamiltonian-rydberg-simulator/"
}
],
}
],
"basedOnPapers": [],
"referencedByPapers": [],
"relatedContent": [
{
{
"type": "demonstration",
"id": "tutorial_pasqal",
"weight": 1.0
},
{
{
"type": "demonstration",
"id": "tutorial_pulse_programming101",
"weight": 1.0
Expand All @@ -76,4 +80,4 @@
"logo": "/_static/hardware_logos/aws.png"
}
]
}
}
2 changes: 1 addition & 1 deletion demonstrations/ahs_aquila.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def gaussian_fn(p, t):
params = [amplitude_params]
ts = [0.0, 1.75]

default_qubit = qml.device("default.qubit.jax", wires=3, shots=1000)
default_qubit = qml.device("default.qubit", wires=3, shots=1000)


@qml.qnode(default_qubit, interface="jax")
Expand Down
8 changes: 5 additions & 3 deletions demonstrations/learning2learn.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2021-03-02T00:00:00+00:00",
"dateOfLastModification": "2024-07-03T00:00:00+00:00",
"dateOfLastModification": "2024-07-31T00:00:00+00:00",
"categories": [
"Quantum Machine Learning"
],
Expand All @@ -21,7 +21,9 @@
"doi": "",
"canonicalURL": "/qml/demos/learning2learn",
"references": [],
"basedOnPapers": ["10.48550/arXiv.1907.05415"],
"basedOnPapers": [
"10.48550/arXiv.1907.05415"
],
"referencedByPapers": [],
"relatedContent": [
{
Expand All @@ -35,4 +37,4 @@
"weight": 1.0
}
]
}
}
11 changes: 3 additions & 8 deletions demonstrations/learning2learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def circuit(params, **kwargs):
def hamiltonian(params, **kwargs):
"""Evaluate the cost Hamiltonian, given the angles and the graph."""

# We set the default.qubit.tf device for seamless integration with TensorFlow
dev = qml.device("default.qubit.tf", wires=len(graph.nodes))
dev = qml.device("default.qubit", wires=len(graph.nodes))

# This qnode evaluates the expectation value of the cost hamiltonian operator
cost = qml.QNode(circuit, dev, diff_method="backprop", interface="tf")
Expand Down Expand Up @@ -373,9 +372,7 @@ def recurrent_loop(graph_cost, n_layers=1, intermediate_steps=False):
# We perform five consecutive calls to 'rnn_iteration', thus creating the
# recurrent loop. More iterations lead to better results, at the cost of
# more computationally intensive simulations.
out0 = rnn_iteration(
[initial_cost, initial_params, initial_h, initial_c], graph_cost
)
out0 = rnn_iteration([initial_cost, initial_params, initial_h, initial_c], graph_cost)
out1 = rnn_iteration(out0, graph_cost)
out2 = rnn_iteration(out1, graph_cost)
out3 = rnn_iteration(out2, graph_cost)
Expand Down Expand Up @@ -1030,9 +1027,7 @@ def call(self, inputs):
_params = tf.reshape(new_params, shape=(2, self.qaoa_p))

# Cost evaluation, and reshaping to be consistent with other Keras tensors
new_cost = tf.reshape(
tf.cast(self.expectation(_params), dtype=tf.float32), shape=(1, 1)
)
new_cost = tf.reshape(tf.cast(self.expectation(_params), dtype=tf.float32), shape=(1, 1))

return [new_cost, new_params, new_h, new_c]

Expand Down
20 changes: 11 additions & 9 deletions demonstrations/tutorial_eqnn_force_field.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"authors": [
{
"id": "oriel_kiss"
},
{
},
{
"id": "isabel_nha_minh_le"
}
],
"dateOfPublication": "2024-03-12T00:00:00+00:00",
"dateOfLastModification": "2024-03-13T00:00:00+00:00",
"dateOfLastModification": "2024-07-31T00:00:00+00:00",
"categories": [
"Quantum Machine Learning", "Quantum Chemistry"
"Quantum Machine Learning",
"Quantum Chemistry"
],
"tags": [],
"previewImages": [
Expand Down Expand Up @@ -57,7 +58,7 @@
"publisher": "APS",
"journal": "Phys. Rev. A",
"url": "https://journals.aps.org/pra/abstract/10.1103/PhysRevA.103.032430"
} ,
},
{
"id": "wierichs",
"type": "article",
Expand All @@ -67,7 +68,7 @@
"publisher": "",
"journal": "",
"url": "https://arxiv.org/abs/2312.06752"
} ,
},
{
"id": "meyer",
"type": "article",
Expand All @@ -79,10 +80,11 @@
"url": "https://journals.aps.org/prxquantum/abstract/10.1103/PRXQuantum.4.010328"
}
],
"basedOnPapers": ["https://arxiv.org/abs/2311.11362"],
"basedOnPapers": [
"https://arxiv.org/abs/2311.11362"
],
"referencedByPapers": [],
"relatedContent": [

{
"type": "demonstration",
"id": "tutorial_geometric_qml",
Expand All @@ -104,4 +106,4 @@
"weight": 1.0
}
]
}
}
29 changes: 16 additions & 13 deletions demonstrations/tutorial_eqnn_force_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@
import numpy as np

import jax
jax.config.update('jax_platform_name', 'cpu')

jax.config.update("jax_platform_name", "cpu")
from jax import numpy as jnp

import scipy
import matplotlib.pyplot as plt
import sklearn

######################################################################
# Let us construct Pauli matrices, which are used to build the Hamiltonian.
X = np.array([[0, 1], [1, 0]])
Expand All @@ -148,7 +150,11 @@
sigmas = jnp.array(np.array([X, Y, Z])) # Vector of Pauli matrices
sigmas_sigmas = jnp.array(
np.array(
[np.kron(X, X), np.kron(Y, Y), np.kron(Z, Z)] # Vector of tensor products of Pauli matrices
[
np.kron(X, X),
np.kron(Y, Y),
np.kron(Z, Z),
] # Vector of tensor products of Pauli matrices
)
)

Expand All @@ -169,7 +175,6 @@ def singlet(wires):
qml.CNOT(wires=wires)



######################################################################
# Next, we need a rotationally equivariant data embedding. We choose to encode a three-dimensional
# data point :math:`\vec{x}\in \mathbb{R}^3` via
Expand Down Expand Up @@ -201,7 +206,6 @@ def equivariant_encoding(alpha, data, wires):
qml.QubitUnitary(U, wires=wires, id="E")



######################################################################
# Finally, we require an equivariant trainable map and an invariant observable. We take the Heisenberg
# Hamiltonian, which is rotationally invariant, as an inspiration. We define a single summand of it,
Expand Down Expand Up @@ -290,12 +294,12 @@ def noise_layer(epsilon, wires):
rep = 2 # Number of repeated vertical encoding

active_atoms = 2 # Number of active atoms
# Here we only have two active atoms since we fixed the oxygen (which becomes non-active) at the origin
# Here we only have two active atoms since we fixed the oxygen (which becomes non-active) at the origin
num_qubits = active_atoms * rep
#################################


dev = qml.device("default.qubit.jax", wires=num_qubits)
dev = qml.device("default.qubit", wires=num_qubits)


@qml.qnode(dev, interface="jax")
Expand All @@ -311,9 +315,7 @@ def vqlm(data, params):

# Initial encoding
for i in range(num_qubits):
equivariant_encoding(
alphas[i, 0], jnp.asarray(data)[i % active_atoms, ...], wires=[i]
)
equivariant_encoding(alphas[i, 0], jnp.asarray(data)[i % active_atoms, ...], wires=[i])

# Reuploading model
for d in range(D):
Expand Down Expand Up @@ -437,6 +439,7 @@ def inference(loss_data, opt_state):

return E_pred, l


#################################
# **Parameter initialization:**
#
Expand Down Expand Up @@ -466,8 +469,8 @@ def inference(loss_data, opt_state):
# We train our VQLM using stochastic gradient descent.


num_batches = 5000 # number of optimization steps
batch_size = 256 # number of training data per batch
num_batches = 5000 # number of optimization steps
batch_size = 256 # number of training data per batch


for ibatch in range(num_batches):
Expand All @@ -492,7 +495,7 @@ def inference(loss_data, opt_state):
history_loss = np.array(running_loss)

fontsize = 12
plt.figure(figsize=(4,4))
plt.figure(figsize=(4, 4))
plt.plot(history_loss[:, 0], "r-", label="training error")
plt.plot(history_loss[:, 1], "b-", label="testing error")

Expand All @@ -512,7 +515,7 @@ def inference(loss_data, opt_state):
# could be improved, e.g. by using a deeper model as in the original paper.
#

plt.figure(figsize=(4,4))
plt.figure(figsize=(4, 4))
plt.title("Energy predictions", fontsize=fontsize)
plt.plot(energy[indices_test], E_pred, "ro", label="Test predictions")
plt.plot(energy[indices_test], energy[indices_test], "k.-", lw=1, label="Exact")
Expand Down
4 changes: 2 additions & 2 deletions demonstrations/tutorial_geometric_qml.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2022-10-18T00:00:00+00:00",
"dateOfLastModification": "2024-01-01T00:00:00+00:00",
"dateOfLastModification": "2024-07-31T00:00:00+00:00",
"categories": [
"Quantum Machine Learning"
],
Expand Down Expand Up @@ -58,4 +58,4 @@
"weight": 1.0
}
]
}
}
Loading

0 comments on commit 951ac78

Please sign in to comment.