Qit/
lib.rs

1/*!
2Simple quantum computer simulator library without matrix operations.
3
4
5# Example
6All gates can make changes to the qubit using the apply method.
7## Usage basic gates
8```
9use Qit::core::{Applicable, Operator, Qubits};
10use Qit::gates::{CX, H, U, X, Z, OperatorVec, PushOps};
11
12// 1-Bit Gate
13let h_0 = H::new(0);
14// create |0⟩ Qubit
15let q_in = Qubits::zeros(1);
16let q_out = h_0.apply(q_in);
17q_out.print_cmps();
18// |0⟩ : +0.707 +0.000i
19// |1⟩ : +0.707 +0.000i
20
21// 2-Bit Gate
22let cx01 = CX::new(0, 1);
23// q_in = |01⟩ Qubit
24let q_in = Qubits::from_num(2, 1);
25let q_out = cx01.apply(q_in);
26q_out.print_cmps();
27// |00⟩ : +0.000 +0.000i
28// |01⟩ : +0.000 +0.000i
29// |10⟩ : +0.000 +0.000i
30// |11⟩ : +1.000 +0.000i
31
32// Combine gates into one unitary gate
33let x = X::new(0);
34let cx01 = CX::new(0, 1);
35let z = Z::new(1);
36let mut circ = OperatorVec::new();
37circ.push_ops(x);
38circ.push_ops(cx01);
39circ.push_ops(z);
40let u = U::new(circ, String::from("example_circ"));
41
42let q_in = Qubits::from_num(2, 0);
43let q_out = u.apply(q_in);
44q_out.print_cmps();
45// |00⟩ : +0.000 +0.000i
46// |01⟩ : +0.000 +0.000i
47// |10⟩ : -0.000 -0.000i
48// |11⟩ : -1.000 -0.000i
49```
50
51## Usage prepared circuits
52The circuits module implements a function that gives a circuit created using the structure of the gates module.
53
54```
55use Qit::circuits::wrapping_qsub_const;
56use Qit::core::{Applicable, Qubits};
57use Qit::gates::U;
58
59let b = vec![0, 1, 2];
60let sub_2 = wrapping_qsub_const(&b, 2);
61let sub_3 = wrapping_qsub_const(&b, 3);
62
63// combine sub_2 and sub_3
64let sub_5 = U::new(
65    vec![Box::new(sub_2), Box::new(sub_3)],
66    String::from("sub_5"),
67);
68// q_in = |111⟩
69let q_in = Qubits::from_num(3, 7);
70let q_out = sub_5.apply(q_in);
71
72q_out.print_cmps();
73// |000⟩ : +0.000 +0.000i
74// |001⟩ : +0.000 +0.000i
75// |010⟩ : +1.000 +0.000i
76// |011⟩ : +0.000 +0.000i
77// |100⟩ : +0.000 +0.000i
78// |101⟩ : +0.000 +0.000i
79// |110⟩ : +0.000 +0.000i
80// |111⟩ : +0.000 +0.000i
81```
82*/
83
84pub mod circuits;
85pub mod core;
86pub mod gates;
87#[cfg(test)]
88mod tests;