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

Fix name map of aerbackend #1984

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 8 additions & 1 deletion qiskit_aer/backends/aerbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def __init__(
self._options_properties = {}
self._target = None
self._mapping = NAME_MAPPING
self._add_delay = False
self._filter_faulty = False

# Set options from backend_options dictionary
if backend_options is not None:
Expand Down Expand Up @@ -352,7 +354,12 @@ def max_circuits(self):
@property
def target(self):
self._target = convert_to_target(
self.configuration(), self.properties(), self.defaults(), self._mapping
self.configuration(),
self.properties(),
self.defaults(),
self._mapping,
add_delay=self._add_delay,
filter_faulty=self._filter_faulty,
)
return self._target

Expand Down
221 changes: 11 additions & 210 deletions qiskit_aer/backends/name_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@
"""
Qiskit Aer simulator name mapping for Target object
"""
from qiskit.circuit import ControlledGate, Parameter
from qiskit.circuit.reset import Reset
from qiskit.circuit import Parameter


from qiskit.circuit.library import (
SXGate,
MCPhaseGate,
MCXGate,
RZGate,
RXGate,
MCU1Gate,
U2Gate,
U1Gate,
U3Gate,
YGate,
ZGate,
PauliGate,
SwapGate,
RGate,
MCXGrayCode,
RYGate,
UnitaryGate,
UCGate,
Initialize,
DiagonalGate,
)
from qiskit.circuit.controlflow import (
IfElseOp,
Expand All @@ -41,8 +37,8 @@
BreakLoopOp,
SwitchCaseOp,
)
from qiskit.extensions import Initialize, UnitaryGate
from qiskit.extensions.quantum_initializer import DiagonalGate, UCGate

from qiskit.extensions import UnitaryGate
from qiskit.quantum_info.operators.channel.kraus import Kraus
from qiskit.quantum_info.operators.channel import SuperOp
from qiskit.quantum_info.operators.channel.quantum_channel import QuantumChannel
Expand Down Expand Up @@ -73,209 +69,23 @@
from ..noise.errors import ReadoutError
from ..noise.noise_model import QuantumErrorLocation


class MCSXGate(ControlledGate):
"""mcsx gate"""

def __init__(self, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcsx",
1 + num_ctrl_qubits,
[],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=SXGate(),
)


class MCYGate(ControlledGate):
"""mcy gate"""

def __init__(self, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcy",
1 + num_ctrl_qubits,
[],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=YGate(),
)


class MCZGate(ControlledGate):
"""mcz gate"""

def __init__(self, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcz",
1 + num_ctrl_qubits,
[],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=ZGate(),
)


class MCRXGate(ControlledGate):
"""mcrx gate"""

def __init__(self, theta, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcrx",
1 + num_ctrl_qubits,
[theta],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=RXGate(theta),
)


class MCRYGate(ControlledGate):
"""mcry gate"""

def __init__(self, theta, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcry",
1 + num_ctrl_qubits,
[theta],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=RYGate(theta),
)


class MCRZGate(ControlledGate):
"""mcrz gate"""

def __init__(self, theta, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcrz",
1 + num_ctrl_qubits,
[theta],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=RZGate(theta),
)


class MCRGate(ControlledGate):
"""mcr gate"""

def __init__(self, theta, phi, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcr",
1 + num_ctrl_qubits,
[theta, phi],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=RGate(theta, phi),
)


class MCU1Gate(ControlledGate):
"""mcu1 gate"""

def __init__(self, theta, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcu1",
1 + num_ctrl_qubits,
[theta],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=U1Gate(theta),
)


class MCU2Gate(ControlledGate):
"""mcu2 gate"""

def __init__(self, theta, lam, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcu2",
1 + num_ctrl_qubits,
[theta, lam],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=U2Gate(theta, lam),
)


class MCU3Gate(ControlledGate):
"""mcu3 gate"""

def __init__(self, theta, lam, phi, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcu3",
1 + num_ctrl_qubits,
[theta, phi, lam],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=U3Gate(theta, phi, lam),
)


class MCUGate(ControlledGate):
"""mcu gate"""

def __init__(self, theta, lam, phi, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcu",
1 + num_ctrl_qubits,
[theta, phi, lam],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=U3Gate(theta, phi, lam),
)


class MCSwapGate(ControlledGate):
"""mcswap gate"""

def __init__(self, num_ctrl_qubits, ctrl_state=None):
super().__init__(
"mcswap",
2 + num_ctrl_qubits,
[],
None,
num_ctrl_qubits,
ctrl_state=ctrl_state,
base_gate=SwapGate(),
)


PHI = Parameter("phi")
LAM = Parameter("lam")
NAME_MAPPING = {
"mcsx": MCSXGate,
"mcp": MCPhaseGate,
"mcphase": MCPhaseGate,
"initialize": Initialize,
"quantum_channel": QuantumChannel,
"initialize": Initialize,
"save_expval": SaveExpectationValue,
"diagonal": DiagonalGate,
"save_amplitudes": SaveAmplitudes,
"roerror": ReadoutError,
"mcrx": MCRXGate,
"kraus": Kraus,
"save_statevector_dict": SaveStatevectorDict,
"mcx": MCXGate,
"mcu1": MCU1Gate,
"mcu2": MCU2Gate,
"mcu3": MCU3Gate,
"save_superop": SaveSuperOp,
"multiplexer": UCGate,
"mcy": MCYGate,
"superop": SuperOp,
"save_clifford": SaveClifford,
"save_matrix_product_state": SaveMatrixProductState,
Expand All @@ -288,30 +98,21 @@ def __init__(self, num_ctrl_qubits, ctrl_state=None):
"break_loop": BreakLoopOp,
"continue_loop": ContinueLoopOp,
"save_statevector": SaveStatevector,
"mcu": MCUGate,
"set_density_matrix": SetDensityMatrix,
"qerror_loc": QuantumErrorLocation,
"unitary": UnitaryGate,
"mcz": MCZGate,
"pauli": PauliGate,
"set_unitary": SetUnitary,
"save_state": SaveState,
"mcswap": MCSwapGate,
"set_matrix_product_state": SetMatrixProductState,
"save_unitary": SaveUnitary,
"mcr": MCRGate,
"mcx_gray": MCXGrayCode,
"mcrz": MCRZGate,
"set_superop": SetSuperOp,
"save_expval_var": SaveExpectationValueVariance,
"save_stabilizer": SaveStabilizer,
"set_statevector": SetStatevector,
"mcry": MCRYGate,
"set_stabilizer": SetStabilizer,
"save_amplitudes_sq": SaveAmplitudesSquared,
"save_probabilities_dict": SaveProbabilitiesDict,
"save_probs_ket": SaveProbabilitiesDict,
"save_probs": SaveProbabilities,
"cu2": U2Gate(PHI, LAM).control(),
"reset": Reset(),
}
6 changes: 6 additions & 0 deletions releasenotes/notes/fix_name_mapping-1cf7af45bafcb203.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
`num_ctrl_qubits` should be integer but in Qiskit's test case
`test.python.circuit.test_controlled_gate` float type is passed
so add cast to integer
Loading