Skip to content

Commit

Permalink
Upd. Qiskit tests to include cases for MCSU2Gate
Browse files Browse the repository at this point in the history
  • Loading branch information
israelferrazaraujo committed Mar 5, 2023
1 parent 7d3ea14 commit 7c75611
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,18 @@ def test_open_controlled_to_matrix(self, gate_class, ctrl_state):
free_params[1] = 3
elif gate_class in [MCXGate]:
free_params[0] = 3
elif gate_class in [MCSU2Gate]:
alpha = np.random.rand() + 1.j * np.random.rand()
beta = np.random.rand() + 1.j * np.random.rand()

length = np.linalg.norm([alpha, beta])
su2 = np.array([
[alpha, -np.conj(beta)],
[beta, np.conj(alpha)]
]) / length
free_params[0] = su2
free_params[1] = 7

cgate = gate_class(*free_params)
cgate.ctrl_state = ctrl_state

Expand Down Expand Up @@ -1471,6 +1483,18 @@ def test_controlled_standard_gates(self, num_ctrl_qubits, gate_class):
args[1] = 2
elif issubclass(gate_class, MCXGate):
args = [5]
elif gate_class in [MCSU2Gate]:
alpha = np.random.rand() + 1.j * np.random.rand()
beta = np.random.rand() + 1.j * np.random.rand()

length = np.linalg.norm([alpha, beta])
su2 = np.array([
[alpha, -np.conj(beta)],
[beta, np.conj(alpha)]
]) / length
args[0] = su2
args[1] = 7

gate = gate_class(*args)

for ctrl_state in (ctrl_state_ones, ctrl_state_zeros, ctrl_state_mixed):
Expand Down

0 comments on commit 7c75611

Please sign in to comment.