38 CNOT::CNOT(
int qbit_num_in,
int target_qbit_in,
int control_qbit_in) {
50 printf(
"The index of the target qubit is larger than the number of qubits");
51 throw "The index of the target qubit is larger than the number of qubits";
54 target_qbit = target_qbit_in;
58 printf(
"The index of the control qubit is larger than the number of qubits");
59 throw "The index of the control qubit is larger than the number of qubits";
62 control_qbit = control_qbit_in;
80 return composite_cnot();
98 int target_qbit_power =
Power_of_2(target_qbit);
99 int control_qbit_power =
Power_of_2(control_qbit);
112 int target_qubit_state_row = int(row_idx / target_qbit_power) % 2;
113 int control_qubit_state_row = int(row_idx / control_qbit_power) % 2;
114 int state_row_remaining = row_idx;
115 if (target_qubit_state_row == 1) {
116 state_row_remaining = state_row_remaining - target_qbit_power;
118 if (control_qubit_state_row == 1) {
119 state_row_remaining = state_row_remaining - control_qbit_power;
124 int target_qubit_state_col = int(col_idx / target_qbit_power) % 2;
125 int control_qubit_state_col = int(col_idx / control_qbit_power) % 2;
126 int state_col_remaining = col_idx;
127 if (target_qubit_state_col == 1) {
128 state_col_remaining = state_col_remaining - target_qbit_power;
130 if (control_qubit_state_col == 1) {
131 state_col_remaining = state_col_remaining - control_qbit_power;
136 if (control_qubit_state_row == 0 && control_qubit_state_col == 0 && target_qubit_state_row == target_qubit_state_col && state_row_remaining == state_col_remaining) {
137 CNOT_mtx[idx].real = 1;
148 else if (control_qubit_state_row == 1 && control_qubit_state_col == 1 && target_qubit_state_row != target_qubit_state_col && state_row_remaining == state_col_remaining) {
149 CNOT_mtx[idx].real = 1;
CNOT(int qbit_num_in, int target_qbit_in, int control_qbit_in)
Constructor of the class.
scalar * get_data()
Call to get the pointer to the stored data.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
Header file for a class representing a CNOT operation.
Matrix composite_cnot()
Calculate the matrix of a CNOT gate operation acting on the space of qbit_num qubits.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
CNOT * clone()
Call to create a clone of the present class.
Structure type representing complex numbers in the QGD package.
A class representing a CNOT operation.
void set_qbit_num(int qbit_num)
Call to set the number of qubits spanning the matrix of the operation.
int Power_of_2(int n)
Calculates the n-th power of 2.
Class to store data of complex arrays and its properties.
~CNOT()
Destructor of the class.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
Matrix get_matrix()
Call to retrieve the operation matrix.