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

Extend the basis gates of BasicSimulator #12186

Merged
merged 19 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 49 additions & 13 deletions qiskit/providers/basic_provider/basic_provider_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,30 @@
from qiskit.exceptions import QiskitError

# Single qubit gates supported by ``single_gate_params``.
SINGLE_QUBIT_GATES = ("U", "u", "h", "p", "u1", "u2", "u3", "rz", "sx", "x")
SINGLE_QUBIT_GATES = (
"U",
"u",
"u1",
"u2",
"u3",
"h",
"p",
"s",
"sdg",
"sx",
"sxdg",
"t",
"tdg",
"x",
"y",
"z",
"id",
"i",
"r",
"rx",
"ry",
"rz",
)


def single_gate_matrix(gate: str, params: list[float] | None = None) -> np.ndarray:
Expand All @@ -40,29 +63,42 @@ def single_gate_matrix(gate: str, params: list[float] | None = None) -> np.ndarr
"""
if params is None:
params = []

if gate == "U":
if gate in ("U", "u"):
gc = gates.UGate
elif gate == "u3":
gc = gates.U3Gate
elif gate == "h":
gc = gates.HGate
elif gate == "u":
gc = gates.UGate
elif gate == "p":
gc = gates.PhaseGate
elif gate == "u2":
gc = gates.U2Gate
elif gate == "u1":
gc = gates.U1Gate
elif gate == "rz":
gc = gates.RZGate
elif gate == "id":
gc = gates.IGate
elif gate == "s":
gc = gates.SGate
elif gate == "sdg":
gc = gates.SdgGate
elif gate == "sx":
gc = gates.SXGate
elif gate == "sxdg":
gc = gates.SXdgGate
elif gate == "t":
gc = gates.TGate
elif gate == "tdg":
gc = gates.TdgGate
elif gate == "x":
gc = gates.XGate
elif gate == "y":
gc = gates.YGate
elif gate == "z":
gc = gates.ZGate
elif gate in ("id", "i"):
gc = gates.IGate
elif gate == "r":
gc = gates.RGate
elif gate == "rx":
gc = gates.RXGate
elif gate == "ry":
gc = gates.RYGate
elif gate == "rz":
gc = gates.RZGate
else:
raise QiskitError("Gate is not a valid basis gate for this simulator: %s" % gate)

Expand Down
67 changes: 58 additions & 9 deletions qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,70 @@ def _build_basic_target(self) -> Target:
num_qubits=None,
)
basis_gates = [
"c3sx",
"ccx",
"ccz",
"ch",
"cp",
"crx",
"cry",
"crz",
"cs",
"csdg",
"cswap",
"csx",
"cu",
"cu1",
"cu3",
"cx",
"cy",
"cz",
"dcx",
"delay",
"ecr",
"global_phase",
"h",
"u",
"id",
"iswap",
"mc1",
"mcp",
"mcrx",
"mcry",
"mcrz",
"mcx",
"mcx_gray",
"mcx_recursive",
"mcx_vchain",
"measure",
"p",
"r",
"rcccx",
"rccx",
"reset",
"rx",
"rxx",
"ry",
"ryy",
"rz",
"rzx",
"rzz",
"s",
"sdg",
"swap",
"sx",
"sxdg",
"t",
"tdg",
"u",
"u1",
"u2",
"u3",
"rz",
"sx",
"x",
"cx",
"id",
"unitary",
"measure",
"delay",
"reset",
"x",
"xx_minus_yy",
"xx_plus_yy",
"y",
"z",
]
inst_mapping = get_standard_gate_name_mapping()
for name in basis_gates:
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/fixes_10852-e197344c5f44b4f1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
upgrade_providers:
- |
The :class:`.BasicSimulator` python-based simulator included in :mod:`qiskit.providers.basic_provider`
now includes all the standard gates (:mod:`qiskit.circuit.library .standard_gates`). The new basis support includes:
``s`` (:class:`.SGate`), ``sdg`` (:class:`.SdgGate`), ``sx`` (:class:`.SXGate`), ``sdgx`` (:class:`.SdgXGate`),
``t`` (:class:`.TGate`), ``tdg`` (:class:`.TdgGate`), ``y`` (:class:`.YGate`), ``z`` (:class:`.ZGate`),
``id`` (and the alias ``i``, :class:`.IGate`), ``r`` (:class:`.RGate`), ``rx`` (:class:`.RXGate`), and ``ry`` (:class:`.RYGate`).
Loading