diff --git a/qiskit_aer/backends/aerbackend.py b/qiskit_aer/backends/aerbackend.py index 22f620ba77..a25ca2d7cd 100644 --- a/qiskit_aer/backends/aerbackend.py +++ b/qiskit_aer/backends/aerbackend.py @@ -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: @@ -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 diff --git a/qiskit_aer/backends/name_mapping.py b/qiskit_aer/backends/name_mapping.py index 0caadc1999..03a6350b2f 100644 --- a/qiskit_aer/backends/name_mapping.py +++ b/qiskit_aer/backends/name_mapping.py @@ -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, @@ -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 @@ -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, @@ -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(), } diff --git a/releasenotes/notes/fix_name_mapping-1cf7af45bafcb203.yaml b/releasenotes/notes/fix_name_mapping-1cf7af45bafcb203.yaml new file mode 100644 index 0000000000..2055ab350c --- /dev/null +++ b/releasenotes/notes/fix_name_mapping-1cf7af45bafcb203.yaml @@ -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