|
3 | 3 | * @license This file is licensed under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. You may obtain a copy of this license at https://www.gnu.org/licenses/gpl-3.0.en.html. |
4 | 4 | * @author Tushar Chaurasia (Dark-CodeX) |
5 | 5 | */ |
| 6 | + |
6 | 7 | #include "../gates/gates.hh" |
7 | 8 | #include <iostream> |
8 | 9 |
|
9 | | -int main() { |
| 10 | +int main() |
| 11 | +{ |
10 | 12 | using namespace simulator; |
11 | | - |
12 | | - // Instantiate a 3-qubit system |
13 | | - qubit<100> q; |
14 | | - |
| 13 | + qubit<3> q; |
15 | 14 | std::cout << "Initial state (3-qubit system):\n"; |
16 | 15 | const auto &init_state = q.get_qubits(); |
17 | | - for (std::size_t i = 0; i < q.get_size(); ++i) { |
| 16 | + for (std::size_t i = 0; i < q.get_size(); ++i) |
| 17 | + { |
18 | 18 | std::cout << "State[" << i << "] = " << init_state[i] << "\n"; |
19 | 19 | } |
20 | 20 |
|
21 | | - q.apply_pauli_x(1); |
22 | | - std::cout << "\n\nAFTER\n"; |
| 21 | + q.apply_hadamard(0); |
| 22 | + q.apply_pauli_y(1); |
| 23 | + |
| 24 | + std::cout << "\nState after applying Hadamard on qubit 0 and Pauli-Y on qubit 1:\n"; |
| 25 | + const auto &state_after_gates = q.get_qubits(); |
| 26 | + for (std::size_t i = 0; i < q.get_size(); ++i) |
| 27 | + { |
| 28 | + std::cout << "State[" << i << "] = " << state_after_gates[i] << "\n"; |
| 29 | + } |
| 30 | + |
| 31 | + std::cout << "\nMeasuring the entire system...\n"; |
| 32 | + std::size_t outcome = q.measure(); |
| 33 | + std::cout << "Measurement outcome: " << outcome << "\n"; |
23 | 34 |
|
24 | | - const auto &final_state = q.get_qubits(); |
25 | | - for (std::size_t i = 0; i < q.get_size(); ++i) { |
26 | | - std::cout << "State[" << i << "] = " << final_state[i] << "\n"; |
| 35 | + std::cout << "\nState after measurement (collapsed state):\n"; |
| 36 | + const auto &state_after_measure = q.get_qubits(); |
| 37 | + for (std::size_t i = 0; i < q.get_size(); ++i) |
| 38 | + { |
| 39 | + std::cout << "State[" << i << "] = " << state_after_measure[i] << "\n"; |
27 | 40 | } |
28 | 41 |
|
29 | 42 | return 0; |
|
0 commit comments