-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
This optimization is basically for the control gates which have three or more control quits.
Right now it is pure brute force solutions.
"""
Generate and return the tensor of the control gate for any system
of different number of qubits with the consideration of the given
control and target qubits.
Args:
control: The index of the control qubit
target: The index of the target qubit
gate: a type of gate to be generated (X, Y, etc.)
Returns:
A tensor of the contol gate
"""
control_gate = np.eye(2**self.num_qubits, dtype=np.complex128)
tuples = []
# Searches for all the numbers up to 2**self.num_qubits such that in
# binary representation they have '1' in control-place and '0' in
# target place.
for i in range(2**self.num_qubits):
if not (i & (1 << target)) and all(i & (1 << control_qubit) for control_qubit in control):
swap = i + 2**target
# Embeds the transformation into the matrix.
control_gate[i][i] = self.gates[gate][0][0]
control_gate[i][swap] = self.gates[gate][0][1]
control_gate[swap][i] = self.gates[gate][1][0]
control_gate[swap][swap] = self.gates[gate][1][1]
# If control gate applies Hadamard gate, puts the whole system into
# superposition.
if gate == 'H':
control_gate = control_gate * (1. + 1.j) / np.sqrt(2)
return control_gate```
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request