Skip to content

Commit f8f741c

Browse files
add pennylane in bp
1 parent a410e90 commit f8f741c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ We also have [Docker support](/docker).
109109

110110
- Efficiency
111111

112-
- Time: 10 to 10^6 times acceleration compared to tfq or qiskit
112+
- Time: 10 to 10^6+ times acceleration compared to TensorFlow Quantum, Pennylane or Qiskit
113113

114114
- Space: 600+ qubits 1D VQE workflow (converged energy inaccuracy: < 1%)
115115

README_cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pip install tensorcircuit-nightly
105105

106106
- 效率
107107

108-
- 时间:与 TFQ 或 Qiskit 相比,加速 10 到 10^6 倍
108+
- 时间:与 TFQ, Pennylane, 或 Qiskit 相比,加速 10 到 10^6+
109109

110110
- 空间:600+ qubits 1D VQE 工作流(收敛能量误差:< 1%)
111111

examples/bp_benchmark.py

+37
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import cirq
1010
import sympy
1111
import numpy as np
12+
import pennylane as qml
1213
import tensorflow_quantum as tfq
1314
import tensorcircuit as tc
1415

@@ -123,6 +124,42 @@ def op_expectation(params, seed, n_qubits, depth):
123124
)
124125

125126

127+
def pennylane_approach(n_qubits=10, depth=10, n_circuits=100):
128+
129+
dev = qml.device("lightning.qubit", wires=n_qubits)
130+
gate_set = [qml.RX, qml.RY, qml.RZ]
131+
132+
@qml.qnode(dev)
133+
def rand_circuit(params, status):
134+
for i in range(n_qubits):
135+
qml.RY(np.pi / 4, wires=i)
136+
137+
for j in range(depth):
138+
for i in range(n_qubits):
139+
gate_set[status[i, j]](params[j, i], wires=i)
140+
141+
for i in range(n_qubits - 1):
142+
qml.CZ(wires=[i, i + 1])
143+
144+
return qml.expval(qml.Hamiltonian([1.0], [qml.PauliZ(0) @ qml.PauliZ(1)], True))
145+
146+
gf = qml.grad(rand_circuit, argnum=0)
147+
params = np.random.uniform(0, 2 * np.pi, size=[n_circuits, depth, n_qubits])
148+
status = np.random.choice(3, size=[n_circuits, depth, n_qubits])
149+
150+
g_results = []
151+
152+
for i in range(n_circuits):
153+
g_results.append(gf(params[i], status[i]))
154+
155+
g_results = np.stack(g_results)
156+
157+
return np.std(g_results[:, 0, 0])
158+
159+
160+
benchmark(pennylane_approach)
161+
162+
126163
def tc_approach(n_qubits=10, depth=10, n_circuits=100):
127164

128165
seed = tc.array_to_tensor(

0 commit comments

Comments
 (0)