| |
| |
| |
| |
| |
| |
|
|
| program test_phase1_depth |
| use bob_circuit |
| use bob_kinds |
| implicit none |
|
|
| type(bob_circuit_t) :: c |
| integer(i4) :: depth, gate_cnt, st |
| integer :: passed, failed, test_num |
|
|
| passed = 0 |
| failed = 0 |
| test_num = 0 |
|
|
| print *, "========================================================" |
| print *, "PHASE 1 CIRCUIT DEPTH TESTS" |
| print *, "========================================================" |
| print *, "" |
|
|
| |
| |
| |
| test_num = 1 |
| print *, "TEST ", test_num, ": Single Hadamard gate" |
| c = circuit_new(1, 0) |
| call c%add_gate(GATE_HADAMARD, 0, status=st) |
|
|
| depth = c%logical_depth() |
| gate_cnt = c%gate_count() |
|
|
| print *, " Gates: ", gate_cnt, " (expected: 1)" |
| print *, " Logical depth: ", depth, " (expected: 1)" |
|
|
| if (gate_cnt == 1 .and. depth == 1) then |
| print *, " β PASSED" |
| passed = passed + 1 |
| else |
| print *, " β FAILED" |
| failed = failed + 1 |
| end if |
| print *, "" |
|
|
| |
| |
| |
| test_num = 2 |
| print *, "TEST ", test_num, ": Two parallel Hadamards (different qubits)" |
| c = circuit_new(2, 0) |
| call c%add_gate(GATE_HADAMARD, 0, status=st) |
| call c%add_gate(GATE_HADAMARD, 1, status=st) |
|
|
| depth = c%logical_depth() |
| gate_cnt = c%gate_count() |
|
|
| print *, " Gates: ", gate_cnt, " (expected: 2)" |
| print *, " Logical depth: ", depth, " (expected: 1) [parallel gates]" |
|
|
| if (gate_cnt == 2 .and. depth == 1) then |
| print *, " β PASSED" |
| passed = passed + 1 |
| else |
| print *, " β FAILED (parallel gates should have depth 1)" |
| failed = failed + 1 |
| end if |
| print *, "" |
|
|
| |
| |
| |
| test_num = 3 |
| print *, "TEST ", test_num, ": Three serial gates on same qubit" |
| c = circuit_new(1, 0) |
| call c%add_gate(GATE_HADAMARD, 0, status=st) |
| call c%add_gate(GATE_PAULI_X, 0, status=st) |
| call c%add_gate(GATE_PAULI_Z, 0, status=st) |
|
|
| depth = c%logical_depth() |
| gate_cnt = c%gate_count() |
|
|
| print *, " Gates: ", gate_cnt, " (expected: 3)" |
| print *, " Logical depth: ", depth, " (expected: 3) [serial gates]" |
|
|
| if (gate_cnt == 3 .and. depth == 3) then |
| print *, " β PASSED" |
| passed = passed + 1 |
| else |
| print *, " β FAILED" |
| failed = failed + 1 |
| end if |
| print *, "" |
|
|
| |
| |
| |
| test_num = 4 |
| print *, "TEST ", test_num, ": CNOT with dependency" |
| c = circuit_new(2, 0) |
| call c%add_gate(GATE_HADAMARD, 0, status=st) |
| call c%add_gate(GATE_HADAMARD, 1, status=st) |
| call c%add_gate(GATE_CNOT, 1, control=0, status=st) |
|
|
| depth = c%logical_depth() |
| gate_cnt = c%gate_count() |
|
|
| print *, " Gates: ", gate_cnt, " (expected: 3)" |
| print *, " Logical depth: ", depth, " (expected: 2) [H layer + CNOT layer]" |
|
|
| if (gate_cnt == 3 .and. depth == 2) then |
| print *, " β PASSED" |
| passed = passed + 1 |
| else |
| print *, " β FAILED" |
| failed = failed + 1 |
| end if |
| print *, "" |
|
|
| |
| |
| |
| test_num = 5 |
| print *, "TEST ", test_num, ": Empty circuit" |
| c = circuit_new(2, 0) |
|
|
| depth = c%logical_depth() |
| gate_cnt = c%gate_count() |
|
|
| print *, " Gates: ", gate_cnt, " (expected: 0)" |
| print *, " Logical depth: ", depth, " (expected: 0)" |
|
|
| if (gate_cnt == 0 .and. depth == 0) then |
| print *, " β PASSED" |
| passed = passed + 1 |
| else |
| print *, " β FAILED" |
| failed = failed + 1 |
| end if |
| print *, "" |
|
|
| |
| |
| |
| test_num = 6 |
| print *, "TEST ", test_num, ": Bell pair (H + CNOT)" |
| c = circuit_bell_pair() |
|
|
| depth = c%logical_depth() |
| gate_cnt = c%gate_count() |
|
|
| print *, " Gates: ", gate_cnt |
| print *, " Logical depth: ", depth, " (expected: 2) [H then CNOT]" |
|
|
| |
| |
| |
| if (gate_cnt >= 2 .and. depth >= 2) then |
| print *, " β PASSED (depth >= 2)" |
| passed = passed + 1 |
| else |
| print *, " β FAILED" |
| failed = failed + 1 |
| end if |
| print *, "" |
|
|
| |
| |
| |
| print *, "========================================================" |
| print *, "SUMMARY" |
| print *, " Passed: ", passed, "/", test_num |
| print *, " Failed: ", failed, "/", test_num |
| print *, "========================================================" |
|
|
| if (failed == 0) then |
| print *, "ALL TESTS PASSED β" |
| stop 0 |
| else |
| print *, "SOME TESTS FAILED β" |
| stop 1 |
| end if |
|
|
| end program test_phase1_depth |
|
|