Skip to content

Commit

Permalink
test.python.circuit.library.test_mcmt
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 committed Dec 19, 2024
1 parent 74aa286 commit d9c91c5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/python/circuit/library/test_mcmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def test_mcmt_as_normal_control(self):
def test_missing_qubits(self):
"""Test that an error is raised if qubits are missing."""
with self.subTest(msg="no control qubits"):
with self.assertRaises(AttributeError):
with self.assertRaises(ValueError):
_ = MCMTGate(XGate(), num_ctrl_qubits=0, num_target_qubits=1)

with self.subTest(msg="no target qubits"):
with self.assertRaises(AttributeError):
with self.assertRaises(ValueError):
_ = MCMTGate(ZGate(), num_ctrl_qubits=4, num_target_qubits=0)

def test_different_gate_types(self):
Expand Down Expand Up @@ -107,12 +107,12 @@ def test_mcmt_v_chain_ancilla_test(self):
[HGate(), 5, 1],
)
@unpack
def test_mcmt_v_chain_simulation(self, cgate, num_controls, num_targets):
def test_mcmt_v_chain_simulation(self, gate, num_controls, num_targets):
"""Test the MCMT V-chain implementation test on a simulation."""
controls = QuantumRegister(num_controls)
targets = QuantumRegister(num_targets)

subsets = [tuple(range(i)) for i in range(num_controls + 1)]
subsets = [tuple(range(i)) for i in range(num_controls)]
for subset in subsets:
qc = QuantumCircuit(targets, controls)
# Initialize all targets to 1, just to be sure that
Expand All @@ -132,7 +132,7 @@ def test_mcmt_v_chain_simulation(self, cgate, num_controls, num_targets):
for i in subset:
qc.x(controls[i])

mcmt = MCMTGate(cgate, num_controls, num_targets)
mcmt = MCMTGate(gate, num_controls, num_targets)
qc.compose(mcmt, qubits, inplace=True)

for i in subset:
Expand All @@ -143,11 +143,11 @@ def test_mcmt_v_chain_simulation(self, cgate, num_controls, num_targets):
# target register is initially |11...1>, with length equal to 2**(n_targets)
vec_exp = np.array([0] * (2 ** (num_targets) - 1) + [1])

if isinstance(cgate, ZGate):
if isinstance(gate, ZGate):
# Z gate flips the last qubit only if it's applied an odd number of times
if len(subset) == num_controls and (num_controls % 2) == 1:
vec_exp[-1] = -1
elif isinstance(cgate, HGate):
elif isinstance(gate, HGate):
# if all the control qubits have been activated,
# we repeatedly apply the kronecker product of the Hadamard
# with itself and then multiply the results for the original
Expand All @@ -159,7 +159,7 @@ def test_mcmt_v_chain_simulation(self, cgate, num_controls, num_targets):
h_tot = np.kron(h_tot, h_i)
vec_exp = np.dot(h_tot, vec_exp)
else:
raise ValueError(f"Test not implement for gate: {cgate}")
raise ValueError(f"Test not implement for gate: {gate}")

# append the remaining part of the state
vec_exp = np.concatenate(
Expand Down

0 comments on commit d9c91c5

Please sign in to comment.