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/custom_gates.c | |
| parent | ee14ad272e68d9363202d7f668e0b20302827209 (diff) | |
feat: add matrix, vector, and circuit display + fmt
Diffstat (limited to 'tester/custom_gates.c')
| -rw-r--r-- | tester/custom_gates.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/tester/custom_gates.c b/tester/custom_gates.c index df2d9ae..8831e8c 100644 --- a/tester/custom_gates.c +++ b/tester/custom_gates.c @@ -4,33 +4,33 @@ static const double R2 = 0.7071067811865476; void run_custom_tests(void) { - psi_test_section("Custom gates"); + psi_test_section("Custom gates"); - struct PsiCompositeGateOp bell_ops[] = { - { PSI_OP_H, { 0 }, 1 }, - { PSI_OP_CNOT, { 0, 1 }, 2 }, - }; - struct PsiCustomGate bell = psi_new_custom_gate_from_composite("BELL", 2, bell_ops, 2); - struct PsiQuantumCircuit c = psi_new_quantum_circuit(2); - size_t bell_targets[] = { 0, 1 }; - psi_apply_custom(&c, bell, bell_targets, 2); - struct PsiComplex bell_exp[] = { - psi_new_complex(R2, 0.0), - psi_new_complex(0.0, 0.0), - psi_new_complex(0.0, 0.0), - psi_new_complex(R2, 0.0), - }; - psi_check_circuit("composite BELL gate -> Bell state", &c, bell_exp, 4); - psi_free_quantum_circuit(&c); + struct PsiCompositeGateOp bell_ops[] = { + { PSI_OP_H, { 0 }, 1 }, + { PSI_OP_CNOT, { 0, 1 }, 2 }, + }; + struct PsiCustomGate bell = psi_new_custom_gate_from_composite("BELL", 2, bell_ops, 2); + struct PsiQuantumCircuit c = psi_new_quantum_circuit(2); + size_t bell_targets[] = { 0, 1 }; + psi_apply_custom(&c, bell, bell_targets, 2); + struct PsiComplex bell_exp[] = { + psi_new_complex(R2, 0.0), + psi_new_complex(0.0, 0.0), + psi_new_complex(0.0, 0.0), + psi_new_complex(R2, 0.0), + }; + psi_check_circuit("composite BELL gate -> Bell state", &c, bell_exp, 4); + psi_free_quantum_circuit(&c); - struct PsiCustomGate custom_x = psi_new_custom_gate_from_matrix( - "MYX", - psi_matrix(2, 2, psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0), - psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0))); - struct PsiQuantumCircuit c2 = psi_new_quantum_circuit(1); - size_t x_targets[] = { 0 }; - psi_apply_custom(&c2, custom_x, x_targets, 1); - struct PsiComplex x_exp[] = { psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0) }; - psi_check_circuit("from_matrix X custom gate: |0> -> |1>", &c2, x_exp, 2); - psi_free_quantum_circuit(&c2); + struct PsiCustomGate custom_x = psi_new_custom_gate_from_matrix( + "MYX", + psi_matrix(2, 2, psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0), + psi_new_complex(1.0, 0.0), psi_new_complex(0.0, 0.0))); + struct PsiQuantumCircuit c2 = psi_new_quantum_circuit(1); + size_t x_targets[] = { 0 }; + psi_apply_custom(&c2, custom_x, x_targets, 1); + struct PsiComplex x_exp[] = { psi_new_complex(0.0, 0.0), psi_new_complex(1.0, 0.0) }; + psi_check_circuit("from_matrix X custom gate: |0> -> |1>", &c2, x_exp, 2); + psi_free_quantum_circuit(&c2); } |
