Skip to content

Commit

Permalink
fix test_gate.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Glacialte committed Jan 11, 2024
1 parent 23045ec commit b87306d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/gate/gate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ void run_random_gate_apply_two_qubit(UINT n_qubits) {
Random random;

Eigen::VectorXcd test_state = Eigen::VectorXcd::Zero(dim);
QuantumGate* gate;
std::function<Eigen::MatrixXcd(UINT, UINT, UINT)> func_eig;
for (int repeat = 0; repeat < 10; repeat++) {
auto state = StateVector::Haar_random_state(n_qubits);
for (int g = 0; g < 2; g++) {
QuantumGate* gate;
auto state_cp = state.amplitudes();
for (int i = 0; i < dim; i++) {
test_state[i] = state[i];
Expand All @@ -150,12 +150,13 @@ void run_random_gate_apply_two_qubit(UINT n_qubits) {
for (int i = 0; i < dim; i++) {
ASSERT_NEAR(std::abs((CComplex)state_cp[i] - test_state[i]), 0, eps);
}
delete gate;
}
delete gate;
}

func_eig = get_eigen_matrix_full_qubit_SWAP;
for (int repeat = 0; repeat < 10; repeat++) {
QuantumGate* gate;
auto state = StateVector::Haar_random_state(n_qubits);
auto state_cp = state.amplitudes();
for (int i = 0; i < dim; i++) {
Expand All @@ -175,27 +176,28 @@ void run_random_gate_apply_two_qubit(UINT n_qubits) {
for (int i = 0; i < dim; i++) {
ASSERT_NEAR(std::abs((CComplex)state_cp[i] - test_state[i]), 0, eps);
}
delete gate;
}
delete gate;
}

void run_random_gate_apply_fused(UINT n_qubits, UINT target0, UINT target1, UINT block_size) {
const UINT dim = 1ULL << n_qubits;
StateVector state_ref = StateVector::Haar_random_state(n_qubits);
StateVector state = state_ref;
QuantumGate* swap_gate;

// update "state_ref" using SWAP gate
for (UINT i = 0; i < block_size; i++) {
QuantumGate* swap_gate;
swap_gate = new SWAP(target0 + i, target1 + i);
swap_gate->update_quantum_state(state_ref);
delete swap_gate;
}
auto state_ref_cp = state_ref.amplitudes();

swap_gate = new FusedSWAP(target0, target1, block_size);
swap_gate->update_quantum_state(state);
delete swap_gate;
QuantumGate* fused_swap_gate;
fused_swap_gate = new FusedSWAP(target0, target1, block_size);
fused_swap_gate->update_quantum_state(state);
delete fused_swap_gate;
auto state_cp = state.amplitudes();

for (UINT i = 0; i < dim; i++) {
Expand Down

0 comments on commit b87306d

Please sign in to comment.