-
Notifications
You must be signed in to change notification settings - Fork 208
Demo TN with LightningTensor #1288
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
Linking to shortcut: |
Hey @LuisAlfredoNu , could you please help to double check if the scripts shown in this demo work? Thank you. |
demonstrations/tutorial_How_to_simulate_quantum_circuits_with_lightning_tensor.py
Show resolved
Hide resolved
import pennylane as qml | ||
import numpy as np | ||
import time | ||
|
||
# Parameters of the quantum circuit | ||
theta = 0.5 | ||
phi = 0.1 | ||
depth = 10 | ||
n = 1011 | ||
num_qubits = 100 | ||
|
||
# Instantiate the device with the TN method and the specified kwargs | ||
dev = qml.device("lightning.tensor", wires=num_qubits, method="tn") | ||
|
||
|
||
@qml.qnode(dev) | ||
def circuit(theta, depth, n, num_qubits): | ||
for i in range(num_qubits): | ||
qml.X(wires=i) | ||
for _ in range(1, depth - 1): | ||
for i in range(0, num_qubits, 2): | ||
qml.CNOT(wires=[i, i + 1]) | ||
for i in range(num_qubits % 5): | ||
qml.RZ(theta, wires=i) | ||
for i in range(1, num_qubits - 1, 2): | ||
qml.CZ(wires=[i, i + 1]) | ||
for i in range(num_qubits - 1): | ||
qml.CNOT(wires=[i, (i + 1)]) | ||
return qml.expval(qml.X(num_qubits - 1)) | ||
|
||
|
||
# Simulate the circuit for different numbers of qubits | ||
print(f"Number of qubits: {num_qubits}") | ||
start_time = time.time() | ||
result = circuit(theta, depth, n, num_qubits) | ||
end_time = time.time() | ||
print(f"Result: {result}") | ||
print(f"Execution time: {end_time - start_time:.4f} seconds") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output of this code is the following:
Number of qubits: 100
Result: 0.0
Execution time: 22.2965 seconds
demonstrations/tutorial_How_to_simulate_quantum_circuits_with_lightning_tensor.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_How_to_simulate_quantum_circuits_with_lightning_tensor.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_How_to_simulate_quantum_circuits_with_lightning_tensor.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_How_to_simulate_quantum_circuits_with_lightning_tensor.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_How_to_simulate_quantum_circuits_with_lightning_tensor.py
Outdated
Show resolved
Hide resolved
"tags": [ | ||
"how to" | ||
], | ||
"previewImages": [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before submitting
Please complete the following checklist when submitting a PR:
Ensure that your tutorial executes correctly, and conforms to the
guidelines specified in the README.
Remember to do a grammar check of the content you include.
All tutorials conform to
PEP8 standards.
To auto format files, simply
pip install black
, and thenrun
black -l 100 path/to/file.py
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Title:
Summary:
Relevant references:
Possible Drawbacks:
Related GitHub Issues:
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
KEYWORDS — What words should be included in the marketing post?
Which of the following types of documentation is most similar to your file?
(more details here)