Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi committed Jun 21, 2024
1 parent d1f7c41 commit 5bd449c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions qiskit/circuit/library/standard_gates/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""X, CX, CCX and multi-controlled X gates."""
from __future__ import annotations
from typing import Optional, Union, Type
from typing import Optional, Union
from math import ceil, pi
import numpy
from qiskit.circuit.controlledgate import ControlledGate
Expand Down Expand Up @@ -1101,9 +1101,8 @@ def __new__(
Depending on the number of controls and which mode of the MCX, this creates an
explicit CX, CCX, C3X or C4X instance or a generic MCX gate.
"""
# The CXGate and CCXGate will be implemented for all modes of the MCX, and
# the C3XGate and C4XGate are handled in the gate definition.
explicit: dict[int, Type[ControlledGate]] = {1: CXGate, 2: CCXGate}
# The CXGate, CCXGate, C3XGate, and C4XGate will be implemented for all modes of the MCX.
explicit = {1: CXGate, 2: CCXGate, 3: C3XGate, 4: C4XGate}
gate_class = explicit.get(num_ctrl_qubits, None)
if gate_class is not None:
gate = gate_class.__new__(
Expand Down
4 changes: 2 additions & 2 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,9 @@ def test_small_mcx_gates_yield_cx_count(self, num_ctrl_qubits):

@data(1, 2, 3, 4)
def test_mcxgraycode_gates_yield_explicit_gates(self, num_ctrl_qubits):
"""Test creating an mcx gate calls MCXGrayCode and yeilds explicit definition."""
"""Test an MCXGrayCode yields explicit definition."""
qc = QuantumCircuit(num_ctrl_qubits + 1)
qc.mcx(list(range(num_ctrl_qubits)), [num_ctrl_qubits])
qc.append(MCXGrayCode(num_ctrl_qubits), list(range(qc.num_qubits)), [])
explicit = {1: CXGate, 2: CCXGate, 3: C3XGate, 4: C4XGate}
self.assertEqual(type(qc[0].operation), explicit[num_ctrl_qubits])

Expand Down

0 comments on commit 5bd449c

Please sign in to comment.