The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
decoherence.cpp
1/** @file
2 * API definitions for effecting decohering channels upon Quregs
3 * which are instantiated as density matrices.
4 *
5 * @author Tyson Jones
6 * @author Balint Koczor (prototyped v3 mixKrausMap)
7 * @author Nicolas Vogt (prototyped v3 mixDamping)
8 */
9
10#include "quest/include/types.h"
11#include "quest/include/qureg.h"
12#include "quest/include/channels.h"
13
14#include "quest/src/core/validation.hpp"
15#include "quest/src/core/localiser.hpp"
16#include "quest/src/core/utilities.hpp"
17
18#include <vector>
19using std::vector;
20
21
22
23/*
24 * C AND C++ AGNOSTIC FUNCTIONS
25 */
26
27// enable invocation by both C and C++ binaries
28extern "C" {
29
30
31void mixDephasing(Qureg qureg, int qubit, qreal prob) {
32 validate_quregFields(qureg, __func__);
33 validate_target(qureg, qubit, __func__);
34 validate_oneQubitDepashingProb(prob, __func__);
35
36 // permit but do not change non-decohering statevecs
37 if (prob == 0)
38 return;
39
40 validate_quregIsDensityMatrix(qureg, __func__);
41
42 localiser_densmatr_oneQubitDephasing(qureg, qubit, prob);
43}
44
45
46void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob) {
47 validate_quregFields(qureg, __func__);
48 validate_twoTargets(qureg, qubit1, qubit2, __func__);
49 validate_twoQubitDepashingProb(prob, __func__);
50
51 // permit but do not change non-decohering statevecs
52 if (prob == 0)
53 return;
54
55 validate_quregIsDensityMatrix(qureg, __func__);
56
57 localiser_densmatr_twoQubitDephasing(qureg, qubit1, qubit2, prob);
58}
59
60
61void mixDepolarising(Qureg qureg, int qubit, qreal prob) {
62 validate_quregFields(qureg, __func__);
63 validate_target(qureg, qubit, __func__);
64 validate_oneQubitDepolarisingProb(prob, __func__);
65
66 // permit but do not change non-decohering statevecs
67 if (prob == 0)
68 return;
69
70 validate_quregIsDensityMatrix(qureg, __func__);
71
72 localiser_densmatr_oneQubitDepolarising(qureg, qubit, prob);
73}
74
75
76void mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal prob) {
77 validate_quregFields(qureg, __func__);
78 validate_twoTargets(qureg, qubit1, qubit2, __func__);
79 validate_twoQubitDepolarisingProb(prob, __func__);
80
81 // permit but do not change non-decohering statevecs
82 if (prob == 0)
83 return;
84
85 validate_quregIsDensityMatrix(qureg, __func__);
86
87 localiser_densmatr_twoQubitDepolarising(qureg, qubit1, qubit2, prob);
88}
89
90
91void mixDamping(Qureg qureg, int qubit, qreal prob) {
92 validate_quregFields(qureg, __func__);
93 validate_target(qureg, qubit, __func__);
94 validate_oneQubitDampingProb(prob, __func__);
95
96 // permit but do not change non-decohering statevecs
97 if (prob == 0)
98 return;
99
100 validate_quregIsDensityMatrix(qureg, __func__);
101
102 localiser_densmatr_oneQubitDamping(qureg, qubit, prob);
103}
104
105
106void mixPaulis(Qureg qureg, int qubit, qreal probX, qreal probY, qreal probZ) {
107 validate_quregFields(qureg, __func__);
108 validate_target(qureg, qubit, __func__);
109 validate_oneQubitPauliChannelProbs(probX, probY, probZ, __func__);
110
111 // permit but do not change non-decohering statevecs
112 if (probX == 0 && probY == 0 && probZ == 0)
113 return;
114
115 validate_quregIsDensityMatrix(qureg, __func__);
116
117 localiser_densmatr_oneQubitPauliChannel(qureg, qubit, probX, probY, probZ);
118}
119
120
121void mixKrausMap(Qureg qureg, int* qubits, int numQubits, KrausMap map) {
122 validate_quregFields(qureg, __func__);
123 validate_quregIsDensityMatrix(qureg, __func__);
124 validate_targets(qureg, qubits, numQubits, __func__);
125 validate_mixedAmpsFitInNode(qureg, 2*numQubits, __func__); // superop acts on 2x
126 validate_krausMapIsCPTP(map, __func__); // also checks fields and is-sync
127 validate_krausMapMatchesTargets(map, numQubits, __func__);
128
129 localiser_densmatr_krausMap(qureg, map, util_getVector(qubits, numQubits));
130}
131
132
133void mixQureg(Qureg outQureg, Qureg inQureg, qreal inProb) {
134 validate_quregFields(outQureg, __func__);
135 validate_quregFields(inQureg, __func__);
136 validate_probability(inProb, __func__);
137 validate_quregsCanBeMixed(outQureg, inQureg, __func__); // checks outQureg is densmatr
138
139 qreal outProb = 1 - inProb;
140 localiser_densmatr_mixQureg(outProb, outQureg, inProb, inQureg);
141}
142
143
144void mixSuperOp(Qureg qureg, int* targets, int numTargets, SuperOp superop) {
145 validate_quregFields(qureg, __func__);
146 validate_targets(qureg, targets, numTargets, __func__);
147 validate_superOpFields(superop, __func__);
148 validate_superOpIsSynced(superop, __func__);
149 validate_superOpDimMatchesTargs(superop, numTargets, __func__);
150 validate_mixedAmpsFitInNode(qureg, 2*numTargets, __func__); // superop acts on 2x
151
152 localiser_densmatr_superoperator(qureg, superop, util_getVector(targets, numTargets));
153}
154
155
156
157} // end de-mangler
158
159
160
161/*
162 * C++ OVERLOADS
163 *
164 * which are only accessible to C++ binaries, and accept
165 * arguments more natural to C++ (e.g. std::vector). We
166 * manually add these to their respective Doxygen doc groups.
167 */
168
169#ifdef __cplusplus
170
171void mixKrausMap(Qureg qureg, vector<int> targets, KrausMap map) {
172 mixKrausMap(qureg, targets.data(), targets.size(), map);
173}
174
175void mixSuperOp(Qureg qureg, vector<int> targets, SuperOp superop) {
176 mixSuperOp(qureg, targets.data(), targets.size(), superop);
177}
178
179#endif // __cplusplus
void mixDepolarising(Qureg qureg, int qubit, qreal prob)
void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob)
void mixQureg(Qureg outQureg, Qureg inQureg, qreal inProb)
void mixDamping(Qureg qureg, int qubit, qreal prob)
void mixPaulis(Qureg qureg, int qubit, qreal probX, qreal probY, qreal probZ)
void mixKrausMap(Qureg qureg, int *qubits, int numQubits, KrausMap map)
void mixSuperOp(Qureg qureg, int *targets, int numTargets, SuperOp superop)
void mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal prob)
void mixDephasing(Qureg qureg, int qubit, qreal prob)
Definition qureg.h:49