aboutsummaryrefslogtreecommitdiff
path: root/tester/main.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-06 19:12:05 +0200
committerhachem <im@hachem.wtf>2026-09-06 19:12:05 +0200
commitb2a5d3d5a2faac05b1b722d96d11d9b191c7cffc (patch)
treeac7712ead7cea6e9b90de62b2520d04d98ce6c42 /tester/main.c
parentab08fa6065b5b08627b51203eb92ef65ed7b5ea2 (diff)
add: quantum bit and register with gate application
Diffstat (limited to 'tester/main.c')
-rw-r--r--tester/main.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/tester/main.c b/tester/main.c
index cba5d28..8885afa 100644
--- a/tester/main.c
+++ b/tester/main.c
@@ -77,5 +77,33 @@ int main(void)
psi_free_vector(&hs0);
psi_free_quantum_gate(&gate);
+ const char *names[] = { "q0", "q1" };
+ struct PsiQuantumRegister reg = psi_new_quantum_register("bell", names, 2);
+
+ struct PsiMatrix h2 = psi_matrix(2, 2,
+ psi_new_complex(inv_sqrt2, 0.0), psi_new_complex(inv_sqrt2, 0.0),
+ psi_new_complex(inv_sqrt2, 0.0), psi_new_complex(-inv_sqrt2, 0.0));
+ struct PsiQuantumGate hadamard = psi_new_quantum_gate_from_matrix("H", h2);
+
+ struct PsiMatrix cnot_m = psi_matrix(4, 4,
+ psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0), psi_new_complex(0.0, 0.0), psi_new_complex(0.0, 0.0),
+ psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0), psi_new_complex(0.0, 0.0),
+ psi_new_complex(0.0, 0.0), psi_new_complex(0.0, 0.0), psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0),
+ psi_new_complex(0.0, 0.0), psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0));
+ struct PsiQuantumGate cnot = psi_new_quantum_gate_from_matrix("CNOT", cnot_m);
+
+ size_t t0[] = { 0 };
+ size_t t01[] = { 0, 1 };
+ psi_apply_gate(&reg, hadamard, t0, 1);
+ psi_apply_gate(&reg, cnot, t01, 2);
+
+ printf("bell = [%g, %g, %g, %g]\n",
+ reg.state_vector.data[0].real, reg.state_vector.data[1].real,
+ reg.state_vector.data[2].real, reg.state_vector.data[3].real);
+
+ psi_free_quantum_gate(&hadamard);
+ psi_free_quantum_gate(&cnot);
+ psi_free_quantum_register(&reg);
+
return 0;
}