From 081fc18575be18ddedf603638793152d5ddc83b6 Mon Sep 17 00:00:00 2001 From: hachem Date: Sun, 6 Sep 2026 19:42:59 +0200 Subject: add: custom gates from matrices and composites --- include/core/custom_gate.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 include/core/custom_gate.h (limited to 'include/core') diff --git a/include/core/custom_gate.h b/include/core/custom_gate.h new file mode 100644 index 0000000..bc22956 --- /dev/null +++ b/include/core/custom_gate.h @@ -0,0 +1,56 @@ +#pragma once + +#include + +#include "core/quantum_components.h" +#include "maths/matrix.h" + +enum PsiCompositeOp +{ + PSI_OP_H, + PSI_OP_X, + PSI_OP_Y, + PSI_OP_Z, + PSI_OP_S, + PSI_OP_T, + PSI_OP_CNOT, + PSI_OP_CZ, + PSI_OP_SWAP, + PSI_OP_CCNOT, + PSI_OP_CSWAP, +}; + +struct PsiCompositeGateOp +{ + enum PsiCompositeOp op; + size_t targets[3]; + size_t target_count; +}; + +enum PsiCustomGateKind +{ + PSI_CUSTOM_GATE_MATRIX, + PSI_CUSTOM_GATE_COMPOSITE, +}; + +struct PsiCustomGate +{ + const char *name; + size_t num_qubits; + enum PsiCustomGateKind kind; + union + { + struct PsiMatrix matrix; + struct + { + struct PsiCompositeGateOp *ops; + size_t count; + } composite; + } definition; +}; + +struct PsiCustomGate psi_new_custom_gate_from_matrix(const char *name, struct PsiMatrix matrix); +struct PsiCustomGate psi_new_custom_gate_from_composite(const char *name, size_t num_qubits, const struct PsiCompositeGateOp *ops, size_t op_count); +void psi_free_custom_gate(struct PsiCustomGate *gate); + +struct PsiQuantumGate psi_to_quantum_gate(struct PsiCustomGate gate); -- cgit v1.3