1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
use crate::common::{benchmark_circuit, print_circuit, print_section, BenchmarkResult};
use libpsi_core::QuantumCircuit;
pub fn run_all(results: &mut Vec<BenchmarkResult>) {
println!("═══════════════════════════════════════════════════════════════");
println!(" CLIFFORD GATES TESTS");
println!("═══════════════════════════════════════════════════════════════\n");
test_bell_state(results);
test_ghz_state(results);
test_swap_via_cnots(results);
test_toffoli(results);
test_hadamard_measure(results);
test_complex_circuit(results);
}
pub fn test_bell_state(results: &mut Vec<BenchmarkResult>) {
print_section("Bell State with Measurement");
let builder = || {
let mut circuit = QuantumCircuit::with_classical(2, 2);
circuit.h(0).cnot(0, 1).measure(0, 0).measure(1, 1);
circuit
};
print_circuit(&builder());
results.push(benchmark_circuit("Bell State (2 qubits)", builder));
let mut display = builder();
display.compute();
println!("{}\n", display);
}
pub fn test_ghz_state(results: &mut Vec<BenchmarkResult>) {
print_section("GHZ State");
let builder = || {
let mut circuit = QuantumCircuit::new(3);
circuit.h(0).cnot(0, 1).cnot(0, 2);
circuit
};
print_circuit(&builder());
results.push(benchmark_circuit("GHZ State (3 qubits)", builder));
let mut display = builder();
display.compute();
println!("{}\n", display);
}
pub fn test_swap_via_cnots(results: &mut Vec<BenchmarkResult>) {
print_section("SWAP via 3 CNOTs");
let builder = || {
let mut circuit = QuantumCircuit::new(2);
circuit.x(0).cnot(0, 1).cnot(1, 0).cnot(0, 1);
circuit
};
print_circuit(&builder());
results.push(benchmark_circuit("SWAP via CNOTs (2 qubits)", builder));
let mut display = builder();
display.compute();
println!("{}\n", display);
}
pub fn test_toffoli(results: &mut Vec<BenchmarkResult>) {
print_section("Toffoli Gate");
let builder = || {
let mut circuit = QuantumCircuit::new(3);
circuit.x(0).x(1).toffoli(0, 1, 2);
circuit
};
print_circuit(&builder());
results.push(benchmark_circuit("Toffoli (3 qubits)", builder));
let mut display = builder();
display.compute();
println!("{}\n", display);
}
pub fn test_hadamard_measure(results: &mut Vec<BenchmarkResult>) {
print_section("Full Circuit with Measurements");
let builder = || {
let mut circuit = QuantumCircuit::with_classical(3, 3);
circuit.h(0).h(1).h(2).measure_all();
circuit
};
print_circuit(&builder());
results.push(benchmark_circuit("3-qubit Hadamard + Measure", builder));
let mut display = builder();
display.compute();
println!("{}\n", display);
}
pub fn test_complex_circuit(results: &mut Vec<BenchmarkResult>) {
print_section("Complex Circuit");
let builder = || {
let mut circuit = QuantumCircuit::with_classical(4, 2);
circuit
.h(0)
.h(1)
.cnot(0, 2)
.cnot(1, 3)
.cz(2, 3)
.swap(0, 1)
.measure(0, 0)
.measure(1, 1);
circuit
};
print_circuit(&builder());
results.push(benchmark_circuit("Complex (4 qubits)", builder));
let mut display = builder();
display.compute();
println!("{}\n", display);
}
|