Skip to content

Commit 7fb754f

Browse files
committed
UPDATE:
1. basic usage of `qubit` class
1 parent 64eece5 commit 7fb754f

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

qubitverse/simulator/simulator/simulator.cc

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,40 @@
33
* @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.
44
* @author Tushar Chaurasia (Dark-CodeX)
55
*/
6+
67
#include "../gates/gates.hh"
78
#include <iostream>
89

9-
int main() {
10+
int main()
11+
{
1012
using namespace simulator;
11-
12-
// Instantiate a 3-qubit system
13-
qubit<100> q;
14-
13+
qubit<3> q;
1514
std::cout << "Initial state (3-qubit system):\n";
1615
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+
{
1818
std::cout << "State[" << i << "] = " << init_state[i] << "\n";
1919
}
2020

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";
2334

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";
2740
}
2841

2942
return 0;

0 commit comments

Comments
 (0)