diff options
| author | hachem <im@hachem.wtf> | 2026-09-18 12:25:32 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-18 12:25:32 +0200 |
| commit | 17598056a69a14e0390a07251d383f413ded9eea (patch) | |
| tree | 79cf23ea99072f065407da3e0b92ee03f8972695 /tester/kernels.c | |
| parent | ee14ad272e68d9363202d7f668e0b20302827209 (diff) | |
feat: add matrix, vector, and circuit display + fmt
Diffstat (limited to 'tester/kernels.c')
| -rw-r--r-- | tester/kernels.c | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/tester/kernels.c b/tester/kernels.c index 91a5cba..f3e4e46 100644 --- a/tester/kernels.c +++ b/tester/kernels.c @@ -4,50 +4,50 @@ static const double R2 = 0.7071067811865476; static void build_fusion(struct PsiQuantumCircuit* c) { - psi_apply_h(c, 0); - psi_apply_z(c, 0); - psi_apply_h(c, 0); - psi_apply_x(c, 1); - psi_apply_x(c, 1); + psi_apply_h(c, 0); + psi_apply_z(c, 0); + psi_apply_h(c, 0); + psi_apply_x(c, 1); + psi_apply_x(c, 1); } void run_kernel_tests(void) { - psi_test_section("Kernel batching and fusion"); + psi_test_section("Kernel batching and fusion"); - struct PsiQuantumCircuit hh = psi_new_quantum_circuit(1); - psi_apply_h(&hh, 0); - psi_apply_h(&hh, 0); - struct PsiComplex hh_exp[] = { psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0) }; - psi_check_circuit("H then H = identity", &hh, hh_exp, 2); - psi_free_quantum_circuit(&hh); + struct PsiQuantumCircuit hh = psi_new_quantum_circuit(1); + psi_apply_h(&hh, 0); + psi_apply_h(&hh, 0); + struct PsiComplex hh_exp[] = { psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0) }; + psi_check_circuit("H then H = identity", &hh, hh_exp, 2); + psi_free_quantum_circuit(&hh); - struct PsiKernel a = - psi_new_kernel("H", - psi_matrix(2, 2, psi_new_complex(R2, 0.0), psi_new_complex(R2, 0.0), - psi_new_complex(R2, 0.0), psi_new_complex(-R2, 0.0)), - (size_t[]){ 0 }, 1); - struct PsiKernel b = psi_clone_kernel(a); - psi_test_check(psi_kernels_can_fuse(a, b), "adjacent single-qubit kernels fuse"); - psi_free_kernel(&a); - psi_free_kernel(&b); + struct PsiKernel a = + psi_new_kernel("H", + psi_matrix(2, 2, psi_new_complex(R2, 0.0), psi_new_complex(R2, 0.0), + psi_new_complex(R2, 0.0), psi_new_complex(-R2, 0.0)), + (size_t[]){ 0 }, 1); + struct PsiKernel b = psi_clone_kernel(a); + psi_test_check(psi_kernels_can_fuse(a, b), "adjacent single-qubit kernels fuse"); + psi_free_kernel(&a); + psi_free_kernel(&b); - struct PsiKernelBatch batch = psi_new_kernel_batch(1); - psi_add_kernel( - &batch, - psi_new_kernel("H", - psi_matrix(2, 2, psi_new_complex(R2, 0.0), psi_new_complex(R2, 0.0), - psi_new_complex(R2, 0.0), psi_new_complex(-R2, 0.0)), - (size_t[]){ 0 }, 1)); - psi_add_kernel( - &batch, - psi_new_kernel("H", - psi_matrix(2, 2, psi_new_complex(R2, 0.0), psi_new_complex(R2, 0.0), - psi_new_complex(R2, 0.0), psi_new_complex(-R2, 0.0)), - (size_t[]){ 0 }, 1)); - psi_optimize_kernel_batch(&batch); - psi_test_check(batch.count == 1, "batch fuses two H kernels into one"); - psi_free_kernel_batch(&batch); + struct PsiKernelBatch batch = psi_new_kernel_batch(1); + psi_add_kernel( + &batch, + psi_new_kernel("H", + psi_matrix(2, 2, psi_new_complex(R2, 0.0), psi_new_complex(R2, 0.0), + psi_new_complex(R2, 0.0), psi_new_complex(-R2, 0.0)), + (size_t[]){ 0 }, 1)); + psi_add_kernel( + &batch, + psi_new_kernel("H", + psi_matrix(2, 2, psi_new_complex(R2, 0.0), psi_new_complex(R2, 0.0), + psi_new_complex(R2, 0.0), psi_new_complex(-R2, 0.0)), + (size_t[]){ 0 }, 1)); + psi_optimize_kernel_batch(&batch); + psi_test_check(batch.count == 1, "batch fuses two H kernels into one"); + psi_free_kernel_batch(&batch); - psi_check_runtimes_agree("Runtimes agree on fusion circuit", 2, build_fusion); + psi_check_runtimes_agree("Runtimes agree on fusion circuit", 2, build_fusion); } |
