Skip to content

Commit

Permalink
[minor] style update
Browse files Browse the repository at this point in the history
  • Loading branch information
01110011011101010110010001101111 committed Nov 25, 2023
1 parent e5cdd52 commit 33bfb85
Show file tree
Hide file tree
Showing 4 changed files with 424 additions and 385 deletions.
19 changes: 14 additions & 5 deletions test/layers/test_nlocal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import torchquantum as tq
from qiskit.circuit.library import TwoLocal, EfficientSU2, ExcitationPreserving, PauliTwoDesign, RealAmplitudes
from qiskit.circuit.library import (
TwoLocal,
EfficientSU2,
ExcitationPreserving,
PauliTwoDesign,
RealAmplitudes,
)

def compare_tq_to_qiskit(tq_circuit, qiskit_circuit, instance_info = ""):

def compare_tq_to_qiskit(tq_circuit, qiskit_circuit, instance_info=""):
"""
helper function to compare if tq and qiskit have the same gates configuration
"""

qiskit_ops = []
for bit in qiskit_circuit.decompose():
wires = []
Expand Down Expand Up @@ -41,8 +48,10 @@ def compare_tq_to_qiskit(tq_circuit, qiskit_circuit, instance_info = ""):
tq_ops_tuple == qiskit_ops_tuple
), f"operations do not match for {instance_info}"


## TEST TWOLOCAL


def test_twolocal():
# iterate through different parameters to test
for entanglement_type in ("linear", "circular", "full"):
Expand All @@ -68,14 +77,15 @@ def test_twolocal():
reps=reps,
insert_barriers=False,
)

# compare the circuits
test_info = f"{entanglement_type} with {n_wires} wires and {reps} reps"
compare_tq_to_qiskit(qdev, qiskit_two)


## TEST OTHER CIRCUITS


def test_twolocal_variants():
tq_to_qiskit = {
"EfficientSU2": (tq.layer.EfficientSU2, EfficientSU2),
Expand All @@ -93,4 +103,3 @@ def test_twolocal_variants():
qdev = tq.QuantumDevice(n_wires, record_op=True)
tq_circuit(qdev)
compare_tq_to_qiskit(qdev, circuit, f"{circuit_name} with {n_wires} wires")

Loading

0 comments on commit 33bfb85

Please sign in to comment.