aboutsummaryrefslogtreecommitdiff
path: root/tester/main.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-06 19:42:59 +0200
committerhachem <im@hachem.wtf>2026-09-06 19:42:59 +0200
commit081fc18575be18ddedf603638793152d5ddc83b6 (patch)
tree42090cd446ed9dc2a0da311f513515d5cf2643b2 /tester/main.c
parent597c959053fe8861538513663d3ca04ff8f5356b (diff)
add: custom gates from matrices and composites
Diffstat (limited to 'tester/main.c')
-rw-r--r--tester/main.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tester/main.c b/tester/main.c
index cc32de1..e401288 100644
--- a/tester/main.c
+++ b/tester/main.c
@@ -1,5 +1,6 @@
#include <stdio.h>
+#include "core/custom_gate.h"
#include "core/gates.h"
#include "core/quantum_components.h"
#include "maths/complex.h"
@@ -97,5 +98,24 @@ int main(void)
psi_free_quantum_gate(&cnot);
psi_free_quantum_register(&reg);
+ 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 PsiQuantumGate bell_gate = psi_to_quantum_gate(bell);
+
+ struct PsiQuantumRegister reg2 = psi_new_quantum_register("bell2", names, 2);
+ size_t t01b[] = { 0, 1 };
+ psi_apply_gate(&reg2, bell_gate, t01b, 2);
+
+ printf("custom = %s -> [%g, %g, %g, %g]\n", bell_gate.name,
+ reg2.state_vector.data[0].real, reg2.state_vector.data[1].real,
+ reg2.state_vector.data[2].real, reg2.state_vector.data[3].real);
+
+ psi_free_custom_gate(&bell);
+ psi_free_quantum_gate(&bell_gate);
+ psi_free_quantum_register(&reg2);
+
return 0;
}