Skip to content

Commit

Permalink
refer review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
doichanj committed Nov 22, 2023
1 parent 28e2f06 commit 8afde0b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 92 deletions.
8 changes: 0 additions & 8 deletions qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ class AerSimulator(AerBackend):
"continue_loop",
"reset",
"switch_case",
"barrier",
]
),
"density_matrix": sorted(
Expand All @@ -543,7 +542,6 @@ class AerSimulator(AerBackend):
"continue_loop",
"reset",
"switch_case",
"barrier",
]
),
"matrix_product_state": sorted(
Expand All @@ -570,7 +568,6 @@ class AerSimulator(AerBackend):
"continue_loop",
"reset",
"switch_case",
"barrier",
]
),
"stabilizer": sorted(
Expand All @@ -594,7 +591,6 @@ class AerSimulator(AerBackend):
"continue_loop",
"reset",
"switch_case",
"barrier",
]
),
"extended_stabilizer": sorted(
Expand All @@ -604,7 +600,6 @@ class AerSimulator(AerBackend):
"roerror",
"save_statevector",
"reset",
"barrier",
]
),
"unitary": sorted(
Expand All @@ -613,7 +608,6 @@ class AerSimulator(AerBackend):
"save_unitary",
"set_unitary",
"reset",
"barrier",
]
),
"superop": sorted(
Expand All @@ -626,7 +620,6 @@ class AerSimulator(AerBackend):
"save_superop",
"set_superop",
"reset",
"barrier",
]
),
"tensor_network": sorted(
Expand All @@ -650,7 +643,6 @@ class AerSimulator(AerBackend):
"set_density_matrix",
"reset",
"switch_case",
"barrier",
]
),
}
Expand Down
65 changes: 0 additions & 65 deletions qiskit_aer/backends/name_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,14 @@
from qiskit.circuit import ControlledGate, Parameter
from qiskit.circuit.reset import Reset
from qiskit.circuit.library import (
U1Gate,
U2Gate,
U3Gate,
UGate,
PhaseGate,
RGate,
RXGate,
RXXGate,
RYGate,
RYYGate,
RZGate,
RZZGate,
RZXGate,
IGate,
HGate,
XGate,
YGate,
ZGate,
SGate,
SdgGate,
SXGate,
SXdgGate,
TGate,
TdgGate,
SwapGate,
CXGate,
CYGate,
CZGate,
CCXGate,
CSXGate,
CUGate,
CU1Gate,
CU3Gate,
CSwapGate,
ECRGate,
PauliGate,
DiagonalGate,
UnitaryGate,
Expand All @@ -63,7 +36,6 @@
CRZGate,
MCU1Gate,
MCXGrayCode,
Barrier,
)
from qiskit.circuit.controlflow import (
IfElseOp,
Expand Down Expand Up @@ -274,43 +246,7 @@ def __init__(self, num_ctrl_qubits, ctrl_state=None):
PHI = Parameter("phi")
LAM = Parameter("lam")
NAME_MAPPING = {
"u1": U1Gate,
"u2": U2Gate,
"u3": U3Gate,
"u": UGate,
"p": PhaseGate,
"r": RGate,
"rx": RXGate,
"rxx": RXXGate,
"ry": RYGate,
"ryy": RYYGate,
"rz": RZGate,
"rzz": RZZGate,
"rzx": RZXGate,
"id": IGate,
"h": HGate,
"x": XGate,
"y": YGate,
"z": ZGate,
"s": SGate,
"sdg": SdgGate,
"sx": SXGate,
"sxdg": SXdgGate,
"t": TGate,
"tdg": TdgGate,
"swap": SwapGate,
"cx": CXGate,
"cy": CYGate,
"cz": CZGate,
"ccx": CCXGate,
"csx": CSXGate,
"cp": CPhaseGate,
"cu": CUGate,
"cu1": CU1Gate,
"cu2": U2Gate(PHI, LAM).control(),
"cu3": CU3Gate,
"cswap": CSwapGate,
"ecr": ECRGate,
"pauli": PauliGate,
"diagonal": DiagonalGate,
"unitary": UnitaryGate,
Expand Down Expand Up @@ -367,5 +303,4 @@ def __init__(self, num_ctrl_qubits, ctrl_state=None):
"save_probs_ket": SaveProbabilitiesDict,
"save_probs": SaveProbabilities,
"reset": Reset(),
"barrier": Barrier,
}
36 changes: 22 additions & 14 deletions qiskit_aer/backends/plugin/aer_backend_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from qiskit.transpiler.passes import UnitarySynthesis
from qiskit.transpiler.passes import HighLevelSynthesis
from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as sel
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping
from qiskit.circuit.measure import Measure
from qiskit.circuit.library import Barrier
from qiskit.circuit import ControlFlowOp
from qiskit.converters import circuit_to_dag
from qiskit_aer.backends.name_mapping import NAME_MAPPING
Expand All @@ -34,8 +36,10 @@ def __init__(self, config, opt_lvl):
self.optimization_level = 1
else:
self.optimization_level = opt_lvl
self.qiskit_inst_name_map = get_standard_gate_name_mapping()
self.qiskit_inst_name_map["barrier"] = Barrier

def _add_ops(self, dag, ops):
def _add_ops(self, dag, ops: set):
num_unsupported_ops = 0
opnodes = dag.op_nodes()
if opnodes is None:
Expand All @@ -44,12 +48,11 @@ def _add_ops(self, dag, ops):
for node in opnodes:
if isinstance(node.op, ControlFlowOp):
for block in node.op.blocks:
num_unsupported_ops += self._add_ops(
circuit_to_dag(block), ops
)
if node.name in self.config.target:
if node.name not in ops:
ops.append(node.name)
num_unsupported_ops += self._add_ops(circuit_to_dag(block), ops)
if node.name in self.qiskit_inst_name_map:
ops.add(node.name)
elif node.name in self.config.target:
ops.add(node.name)
else:
num_unsupported_ops = num_unsupported_ops + 1
return num_unsupported_ops
Expand All @@ -62,7 +65,7 @@ def run(self, dag):
return dag

# search ops in supported name mapping
ops = []
ops = set()
num_unsupported_ops = self._add_ops(dag, ops)

# if there are some unsupported node (i.e. RealAmplitudes) do nothing
Expand All @@ -77,16 +80,21 @@ def run(self, dag):

# rebuild gate sets from circuit
for name in ops:
if name not in self.config.target:
if name != "measure":
self.config.target.add_instruction(NAME_MAPPING[name], name=name)
self.config.target.add_instruction(Measure())
self.config.basis_gates.clear()
self.config.basis_gates.extend(self.config.target.operations)
if name in self.qiskit_inst_name_map:
self.config.target.add_instruction(self.qiskit_inst_name_map[name], name=name)
else:
self.config.target.add_instruction(NAME_MAPPING[name], name=name)
if "measure" not in ops:
self.config.target.add_instruction(Measure())
self.config.basis_gates = list(self.config.target.operation_names)

return dag


# This plugin should not be used outside of simulator
# TODO : this plugin should be moved to optimization stage plugin
# if Qiskit will have custom optimizaiton stage plugin interface
# in that case just return pass without Optimize1qGatesDecomposition
class AerBackendPlugin(PassManagerStagePlugin):
"""custom passmanager to avoid unnecessary gate changes"""

Expand Down
1 change: 0 additions & 1 deletion qiskit_aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ class QasmSimulator(AerBackend):
"set_density_matrix",
"set_stabilizer",
"reset",
"barrier",
]
)

Expand Down
1 change: 0 additions & 1 deletion qiskit_aer/backends/statevector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ class StatevectorSimulator(AerBackend):
"save_state",
"set_statevector",
"reset",
"barrier",
]
),
"gates": [],
Expand Down
4 changes: 1 addition & 3 deletions qiskit_aer/backends/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ class UnitarySimulator(AerBackend):
"pauli",
]
),
"custom_instructions": sorted(
["save_unitary", "save_state", "set_unitary", "reset", "barrier"]
),
"custom_instructions": sorted(["save_unitary", "save_state", "set_unitary", "reset"]),
"gates": [],
}

Expand Down

0 comments on commit 8afde0b

Please sign in to comment.