1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "tests.h"
static const double R2 = 0.7071067811865476;
void run_custom_tests(void)
{
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 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);
}
|