10#include "quest/include/qureg.h"
11#include "quest/include/calculations.h"
12#include "quest/include/initialisations.h"
14#include "quest/src/core/validation.hpp"
15#include "quest/src/core/localiser.hpp"
16#include "quest/src/core/utilities.hpp"
17#include "quest/src/core/bitwise.hpp"
18#include "quest/src/gpu/gpu_config.hpp"
35 validate_quregFields(qureg, __func__);
39 localiser_statevec_initUniformState(qureg, amp);
44 validate_quregFields(qureg, __func__);
48 localiser_statevec_initClassicalState(qureg, ind);
53 validate_quregFields(qureg, __func__);
57 qcomp amp = 1.0 / std::sqrt(qureg.numAmps);
58 localiser_statevec_initUniformState(qureg, amp);
63 validate_quregFields(qureg, __func__);
64 validate_quregFields(pure, __func__);
65 validate_quregCanBeInitialisedToPureState(qureg, pure, __func__);
70 (qureg.isDensityMatrix)?
71 localiser_densmatr_initPureState(qureg, pure):
72 localiser_statevec_setQuregToSuperposition(0, qureg, 1, pure, 0, pure);
77 validate_quregFields(qureg, __func__);
78 validate_basisStateIndex(qureg, ind, __func__);
81 if (qureg.isDensityMatrix)
82 ind = util_getGlobalFlatIndex(qureg, ind, ind);
84 localiser_statevec_initClassicalState(qureg, ind);
89 validate_quregFields(qureg, __func__);
91 localiser_statevec_initDebugState(qureg);
96 validate_quregFields(qureg, __func__);
99 (qureg.isDensityMatrix)?
100 localiser_densmatr_initArbitraryPureState(qureg, amps):
101 localiser_statevec_initArbitraryPureState(qureg, amps);
105void initArbitraryMixedState(
Qureg qureg, qcomp** amps) {
106 validate_quregFields(qureg, __func__);
107 validate_quregIsDensityMatrix(qureg, __func__);
109 localiser_densmatr_initArbitraryMixedState(qureg, amps);
114 validate_quregFields(qureg, __func__);
119 if (qureg.isDensityMatrix)
120 localiser_densmatr_initUniformlyRandomPureStateAmps(qureg);
122 localiser_statevec_initUnnormalisedUniformlyRandomPureStateAmps(qureg);
129 validate_quregFields(qureg, __func__);
130 validate_quregIsDensityMatrix(qureg, __func__);
131 validate_numInitRandomPureStates(numPureStates, __func__);
133 localiser_densmatr_initMixtureOfUniformlyRandomPureStates(qureg, numPureStates);
144 validate_quregFields(qureg, __func__);
145 validate_quregIsStateVector(qureg, __func__);
146 validate_basisStateIndices(qureg, startInd, numAmps, __func__);
148 localiser_statevec_setAmps(amps, qureg, startInd, numAmps);
153 validate_quregFields(qureg, __func__);
154 validate_quregIsDensityMatrix(qureg, __func__);
155 validate_basisStateRowCols(qureg, startRow, startCol, numRows, numCols, __func__);
157 localiser_densmatr_setAmps(amps, qureg, startRow, startCol, numRows, numCols);
162 validate_quregFields(qureg, __func__);
163 validate_quregIsDensityMatrix(qureg, __func__);
164 validate_basisStateIndices(qureg, startInd, numAmps, __func__);
166 localiser_statevec_setAmps(amps, qureg, startInd, numAmps);
171 validate_quregFields(targetQureg, __func__);
172 validate_quregFields(copyQureg, __func__);
173 validate_quregsCanBeCloned(targetQureg, copyQureg, __func__);
178 (targetQureg.isDensityMatrix)?
179 localiser_densmatr_mixQureg(0, targetQureg, 1, copyQureg):
180 localiser_statevec_setQuregToSuperposition(0, targetQureg, 1, copyQureg, 0, copyQureg);
185 validate_quregFields(out, __func__);
186 validate_quregFields(qureg1, __func__);
187 validate_quregFields(qureg2, __func__);
188 validate_quregsCanBeSuperposed(out, qureg1, qureg2, __func__);
190 localiser_statevec_setQuregToSuperposition(facOut, out, fac1, qureg1, fac2, qureg2);
195 validate_quregFields(qureg, __func__);
198 validate_quregRenormProbIsNotZero(prob, __func__);
200 qreal norm = (qureg.isDensityMatrix)? prob : std::sqrt(prob);
201 qreal fac = 1 / norm;
202 localiser_statevec_setQuregToSuperposition(fac, qureg, 0, qureg, 0, qureg);
209 validate_quregFields(qureg, __func__);
210 validate_quregIsDensityMatrix(qureg, __func__);
211 validate_pauliStrSumFields(sum, __func__);
212 validate_pauliStrSumTargets(sum, qureg, __func__);
217 localiser_densmatr_setAmpsToPauliStrSum(qureg, sum);
222 validate_quregFields(in, __func__);
223 validate_quregFields(out, __func__);
224 validate_quregIsDensityMatrix(in, __func__);
225 validate_quregIsDensityMatrix(out, __func__);
226 validate_targets(in, traceOutQubits, numTraceQubits, __func__);
227 validate_quregCanBeSetToReducedDensMatr(out, in, numTraceQubits, __func__);
229 auto targets = util_getVector(traceOutQubits, numTraceQubits);
230 localiser_densmatr_partialTrace(in, out, targets);
235 validate_quregFields(in, __func__);
236 validate_quregFields(out, __func__);
237 validate_quregIsDensityMatrix(in, __func__);
238 validate_quregIsDensityMatrix(out, __func__);
239 validate_targets(in, retainQubits, numRetainQubits, __func__);
240 validate_quregCanBeSetToReducedDensMatr(out, in, in.numQubits - numRetainQubits, __func__);
242 auto traceQubits = util_getNonTargetedQubits(retainQubits, numRetainQubits, in.numQubits);
243 localiser_densmatr_partialTrace(in, out, traceQubits);
qreal calcTotalProb(Qureg qureg)
void setDensityQuregFlatAmps(Qureg qureg, qindex startInd, qcomp *amps, qindex numAmps)
void setQuregToReducedDensityMatrix(Qureg out, Qureg in, int *retainQubits, int numRetainQubits)
void setQuregToPauliStrSum(Qureg qureg, PauliStrSum sum)
void setQuregAmps(Qureg qureg, qindex startInd, qcomp *amps, qindex numAmps)
void setQuregToPartialTrace(Qureg out, Qureg in, int *traceOutQubits, int numTraceQubits)
qreal setQuregToRenormalized(Qureg qureg)
void setQuregToClone(Qureg targetQureg, Qureg copyQureg)
void setDensityQuregAmps(Qureg qureg, qindex startRow, qindex startCol, qcomp **amps, qindex numRows, qindex numCols)
void setQuregToSuperposition(qcomp facOut, Qureg out, qcomp fac1, Qureg qureg1, qcomp fac2, Qureg qureg2)
void initArbitraryPureState(Qureg qureg, qcomp *amps)
void initRandomPureState(Qureg qureg)
void initPlusState(Qureg qureg)
void initZeroState(Qureg qureg)
void initPureState(Qureg qureg, Qureg pure)
void initDebugState(Qureg qureg)
void initRandomMixedState(Qureg qureg, qindex numPureStates)
void initClassicalState(Qureg qureg, qindex ind)
void initBlankState(Qureg qureg)