Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fixes and Full Standard Gates #181

Merged
merged 6 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"setuptools>=52.0.0",
"torch>=1.8.0",
"torchpack>=0.3.0",
"qiskit==0.38.0",
"qiskit>=0.38.0",
"matplotlib>=3.3.2",
"pathos>=0.2.7",
"pylatexenc>=2.10",
Expand Down
17 changes: 13 additions & 4 deletions test/operator/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import qiskit.circuit.library.standard_gates as qiskit_gate
import qiskit.circuit.library as qiskit_library
from qiskit.quantum_info import Operator


RND_TIMES = 100
Expand Down Expand Up @@ -71,13 +72,14 @@
{"qiskit": qiskit_gate.U1Gate, "tq": tq.U1},
{"qiskit": qiskit_gate.U2Gate, "tq": tq.U2},
{"qiskit": qiskit_gate.U3Gate, "tq": tq.U3},
{"qiskit": qiskit_gate.CUGate, "tq": tq.CU},
{"qiskit": qiskit_gate.CU1Gate, "tq": tq.CU1},
# {'qiskit': qiskit_gate.?, 'tq': tq.CU2},
{"qiskit": qiskit_gate.CU3Gate, "tq": tq.CU3},
{"qiskit": qiskit_gate.ECRGate, "tq": tq.ECR},
{"qiskit": qiskit_library.QFT, "tq": tq.QFT},
# {"qiskit": qiskit_library.QFT, "tq": tq.QFT},
{"qiskit": qiskit_gate.SdgGate, "tq": tq.SDG},
{"qiskit": qiskit_gate.TDgGate, "tq": tq.TDG},
{"qiskit": qiskit_gate.TdgGate, "tq": tq.TDG},
{"qiskit": qiskit_gate.SXdgGate, "tq": tq.SXDG},
{"qiskit": qiskit_gate.CHGate, "tq": tq.CH},
{"qiskit": qiskit_gate.CCZGate, "tq": tq.CCZ},
Expand All @@ -86,10 +88,15 @@
{"qiskit": qiskit_gate.CSdgGate, "tq": tq.CSDG},
{"qiskit": qiskit_gate.CSXGate, "tq": tq.CSX},
{"qiskit": qiskit_gate.DCXGate, "tq": tq.DCX},
{'qiskit': qiskit_gate.XXMinusYYGate, 'tq': tq.XXMINYY},
{'qiskit': qiskit_gate.XXPlusYYGate, 'tq': tq.XXPLUSYY},
{"qiskit": qiskit_gate.XXMinusYYGate, "tq": tq.XXMINYY},
{"qiskit": qiskit_gate.XXPlusYYGate, "tq": tq.XXPLUSYY},
{"qiskit": qiskit_gate.C3XGate, "tq": tq.C3X},
{"qiskit": qiskit_gate.RGate, "tq": tq.R},
{"qiskit": qiskit_gate.C4XGate, "tq": tq.C4X},
{"qiskit": qiskit_gate.RCCXGate, "tq": tq.RCCX},
{"qiskit": qiskit_gate.RC3XGate, "tq": tq.RC3X},
{"qiskit": qiskit_gate.GlobalPhaseGate, "tq": tq.GlobalPhase},
{"qiskit": qiskit_gate.C3SXGate, "tq": tq.C3SX},
]

import os
Expand Down Expand Up @@ -120,6 +127,8 @@ def test_op():
if pair["tq"]().name == "SHadamard":
"""Square root of Hadamard is RY(pi/4)"""
qiskit_matrix = qiskit_gate.RYGate(theta=np.pi / 4).to_matrix()
elif pair["tq"]().name == "C3SX":
qiskit_matrix = Operator(pair["qiskit"]())
else:
qiskit_matrix = pair["qiskit"]().to_matrix()
tq_matrix = pair["tq"].matrix.numpy()
Expand Down
2 changes: 1 addition & 1 deletion torchquantum/algorithm/vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import torchquantum as tq

from torchpack.utils.logging import logger
from torchquantum.measurement import expval_obs_mat, expval_joint_analytical
from torchquantum.measurement import expval_joint_analytical


__all__ = ["VQE"]
Expand Down
2 changes: 1 addition & 1 deletion torchquantum/density/density_mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def sswap(
inverse: bool = False,
comp_method: str = "bmm",
):
"""Apply a symmetric swap gate on the specified wires.
"""Apply a symmetric swap gate on the specified wires.

This method applies a symmetric swap gate on the specified wires of the quantum device.
The gate is applied to all the wires if the inverse flag is set to False.
Expand Down
Loading