aboutsummaryrefslogtreecommitdiff
path: root/tester/src
diff options
context:
space:
mode:
Diffstat (limited to 'tester/src')
-rw-r--r--tester/src/main.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/tester/src/main.rs b/tester/src/main.rs
index ab4c78c..7981e8d 100644
--- a/tester/src/main.rs
+++ b/tester/src/main.rs
@@ -91,4 +91,71 @@ fn main() {
complex.compute();
println!("{}", complex);
+
+ print!("------\n\n");
+
+ println!("Custom Gate: Bell Pair Creator\n");
+
+ let bell_gate = CustomGateBuilder::new("BELL", 2).h(0).cnot(0, 1).build();
+
+ let mut custom_circuit = QuantumCircuit::new(4);
+ custom_circuit
+ .apply_custom(bell_gate.clone(), &[0, 1])
+ .apply_custom(bell_gate.clone(), &[2, 3]);
+
+ println!("Horizontal:");
+ println!("{}", HorizontalRenderer::new(&custom_circuit));
+ println!("Vertical:");
+ println!("{}", VerticalRenderer::new(&custom_circuit));
+
+ custom_circuit.compute();
+ println!("{}", custom_circuit);
+
+ print!("------\n\n");
+
+ println!("Custom Gate: Swap via CNOTs\n");
+
+ let swap_gate = CustomGateBuilder::new("MYSWAP", 2)
+ .cnot(0, 1)
+ .cnot(1, 0)
+ .cnot(0, 1)
+ .build();
+
+ let mut swap_test = QuantumCircuit::new(2);
+ swap_test.x(0).apply_custom(swap_gate, &[0, 1]);
+
+ println!("Horizontal:");
+ println!("{}", HorizontalRenderer::new(&swap_test));
+ println!("Vertical:");
+ println!("{}", VerticalRenderer::new(&swap_test));
+
+ swap_test.compute();
+ println!("{}", swap_test);
+
+ print!("------\n\n");
+
+ println!("Custom Gate: Matrix-defined √X gate\n");
+
+ // √X gate (square root of NOT)
+ // When applied twice, it equals X gate
+ let sqrt_x_matrix = matrix!(
+ [complex!(0.5, 0.5), complex!(0.5, -0.5)];
+ [complex!(0.5, -0.5), complex!(0.5, 0.5)]
+ );
+
+ let sqrt_x = CustomGate::from_matrix("√X", sqrt_x_matrix);
+
+ let mut matrix_test = QuantumCircuit::new(1);
+ matrix_test
+ .apply_custom(sqrt_x.clone(), &[0])
+ .apply_custom(sqrt_x, &[0]); // Two √X = X
+
+ println!("Horizontal:");
+ println!("{}", HorizontalRenderer::new(&matrix_test));
+ println!("Vertical:");
+ println!("{}", VerticalRenderer::new(&matrix_test));
+
+ matrix_test.compute();
+ println!("{}", matrix_test);
+ println!("(Two √X gates should equal X, so |0⟩ becomes |1⟩)");
}