The Quantum Exact Simulation Toolkit v4.3.0
Loading...
Searching...
No Matches
deprecated.h
1/** @file
2 * Backwards-compatible definitions of deprecated v3 functions which
3 * work as expected, but issue a user-toggleable warning during
4 * compilation. The deprecated functions are necessarily instantiated
5 * here as macros so that they are only resolved (and the compiler
6 * warnings therein triggered) when a user actually calls them. Note
7 * that uses should NOT dely upon these, but instead use them to ease
8 * the process of refactoring v3-compatible QuEST code to v4. Further,
9 * they do not enable every v3 function signatures to compile - some
10 * manual modification of the v3 QuEST program will be required, as
11 * attemptedly reported by this header during compilation.
12 *
13 * @author Tyson Jones
14 *
15 * (excluded from doxygen doc)
16 */
17
18#ifndef DEPRECATED_H
19#define DEPRECATED_H
20
21#include "quest.h"
22
23#include "stdlib.h"
24#include <stdbool.h>
25
26
27
28/*
29 * INITIAL WARNING
30 */
31
32#if !defined(QUEST_DISABLE_DEPRECATION_WARNINGS) || QUEST_DISABLE_DEPRECATION_WARNINGS == 0
33
34 // #warning command is always recognised (deprecated API is not MSVC-compatible)
35 #warning "\
36Deprecated functions have been included in compilation. The QuEST v3 API will be attemptedly \
37automatically substituted for the v4 API, although some uses of the old API will still fail to \
38compile. For example, access to v3 struct fields (e.g. 'ComplexMatrixN.real[0][0]') must be \
39manually replaced with v4 struct fields (e.g. 'CompMatr.cpuElems[0][0]'), though new v4 functions \
40make struct field access mostly redundant (e.g. via 'setCompMatr()'). Even when successfully \
41compiling, use of the deprecated v3 functions is dangerous; these are not unit-tested, and the \
42auto-porting to v4 may introduce new bugs. As such, you should only use this facility to help \
43refactor your code to v4, and should absolutely not continue to use the old v3 API for simulation."
44
45#endif
46
47
48
49/*
50 * TOGGLEABLE WARNING MESSAGES
51 *
52 * users can define precompiler constant QUEST_DISABLE_DEPRECATION_WARNINGS=1
53 * in order to disable compile-time deprecation warnings. This will
54 * make most of the QuEST v3 API silently work by casting to the
55 * v4 API at compile-time. Note that _Pragma() are resolved at
56 * compile-time, AFTER pre-processing; some compilers (like gcc) will
57 * ergo treat them like statements which can fill an 'if() (token)', so
58 * that (e.g.) 'if(..) oldFunc()' will issue a warning but execute
59 * 'oldFunc()' outside of the conditional. That won't compile if the
60 * function depends on control-flow params like a for-loop index. Yuck!
61 */
62
63#define _EFFECT_PRAGMA(cmd) _Pragma(#cmd)
64
65#if QUEST_DISABLE_DEPRECATION_WARNINGS
66
67 #define _WARN_TYPE_RENAMED(oldname, newname)
68
69 #define _WARN_FUNC_RENAMED(oldname, newname)
70
71 #define _WARN_FUNC_NOW_HAS_FEWER_ARGS(oldsig, newsig)
72
73 #define _WARN_GENERAL_MSG(msg)
74
75#else
76
77 #define _WARN_TYPE_RENAMED(oldname, newname) \
78 _EFFECT_PRAGMA(message( \
79 "The QuEST type '" oldname "' is deprecated. " \
80 "Please instead use '" newname "' which has been automatically invoked."))
81
82 #define _WARN_FUNC_RENAMED(oldname, newname) \
83 _EFFECT_PRAGMA(message( \
84 "The QuEST function '" oldname "' is deprecated. " \
85 "Please instead use '" newname "' which has been automatically invoked."))
86
87 #define _WARN_FUNC_NOW_HAS_FEWER_ARGS(oldsig, newsig) \
88 _EFFECT_PRAGMA(message( \
89 "The QuEST function '" oldsig "' now accepts fewer arguments, and has " \
90 "new signature '" newsig "' which has been automatically invoked."))
91
92 #define _WARN_GENERAL_MSG(msg) \
93 _EFFECT_PRAGMA(message(msg))
94
95#endif
96
97
98
99/*
100 * NON-TOGGLEABLE WARNING
101 *
102 * which cannot be suppressed because it sometimes precedes an error
103 * which is obfuscated without prior warning
104 */
105
106#define _WARN_UNSUPPRESSABLE_MSG(msg) \
107 _EFFECT_PRAGMA(message(msg))
108
109
110
111/*
112 * NON-TOGGLEABLE ERRORS
113 *
114 * which cannot be disabled, and after which compilation cannot continue.
115 */
116
117
118/// @todo:
119/// we use placeholder message(...) below which only issues a warning,
120/// and does not kill compilation; there alas seems to be no cross-platform
121/// method of aborting compilation with a _Pragma (and aborting during
122/// preprocessing via #error is too soon). We currently work around this by
123/// referring to an undefined symbol. Ew!
124
125
126#define _FORCE_COMPILATION_TO_FAIL() \
127 _FORCING_UNKNOWN_SYMBOL_ERROR_TO_STOP_COMPILATION
128
129
130#define _ERROR_GENERAL_MSG(msg) \
131 _EFFECT_PRAGMA(message(msg)) \
132 _FORCE_COMPILATION_TO_FAIL()
133
134
135#define _ERROR_FUNC_RENAMED(oldname, newfunc) \
136 _ERROR_GENERAL_MSG( \
137 "The QuEST function '" oldname "' is deprecated. " \
138 "Please instead use '" newfunc "' which could not here be automatically invoked.") \
139 _FORCE_COMPILATION_TO_FAIL()
140
141
142#define _ERROR_FUNC_REMOVED(oldname) \
143 _ERROR_GENERAL_MSG( \
144 "The QuEST function '" oldname "' is deprecated, and has no replacement.") \
145 _FORCE_COMPILATION_TO_FAIL()
146
147
148#define _ERROR_PREPROCESSOR_RENAMED(oldname, newname) \
149 _ERROR_GENERAL_MSG( \
150 "The QuEST preprocessor '" oldname "' is deprecated. " \
151 "Please instead use '" newname "' which could not here be automatically invoked.") \
152 _FORCE_COMPILATION_TO_FAIL()
153
154
155#define _ERROR_PREPROCESSOR_REMOVED(oldname) \
156 _ERROR_GENERAL_MSG( \
157 "The QuEST preprocessor '" oldname "' is deprecated, and has no replacement.") \
158 _FORCE_COMPILATION_TO_FAIL()
159
160
161#define _ERROR_PHASE_FUNC_REMOVED(oldname) \
162 _ERROR_GENERAL_MSG( \
163 "The QuEST function '" oldname "' is deprecated. Please instead create a 'DiagMatr' or 'FullStateDiagMatr', initialise it " \
164 "via functions like 'setDiagMatrFromMultiVarFunc()' or 'setDiagMatrFromMultiDimLists()', and apply it via 'applyDiagMatr() or " \
165 "'applyFullStateDiagMatr()'. This procedure cannot be automatically performed here." ) \
166 _FORCE_COMPILATION_TO_FAIL()
167
168
169
170/*
171 * PREPROCESSOR CONSTANTS
172 *
173 * We cannot simply replace format specifiers like 'REAL_STRING_FORMAT' because our
174 * warning code interrupts the string joining done by the preprocessor. For example,
175 * '"x = " REAL_STRING_FORMAT' would not compile due to the warning inside REAL_*.
176 */
177
178#define REAL_STRING_FORMAT \
179 _ERROR_PREPROCESSOR_RENAMED("REAL_STRING_FORMAT", "QREAL_FORMAT_SPECIFIER")
180
181#define REAL_QASM_FORMAT \
182 _ERROR_PREPROCESSOR_REMOVED("REAL_QASM_FORMAT")
183
184#define MPI_QuEST_REAL \
185 _ERROR_PREPROCESSOR_REMOVED("MPI_QuEST_REAL")
186
187#define MPI_MAX_AMPS_IN_MSG \
188 _ERROR_PREPROCESSOR_REMOVED("MPI_MAX_AMPS_IN_MSG")
189
190#define REAL_EPS \
191 _ERROR_PREPROCESSOR_REMOVED("REAL_EPS")
192
193#define REAL_SPECIFIER \
194 _ERROR_PREPROCESSOR_REMOVED("REAL_SPECIFIER")
195
196#define absReal(...) \
197 _ERROR_PREPROCESSOR_REMOVED("absReal()")
198
199
200
201/*
202 * STACK-MEMORY STRUCT TYPES
203 *
204 * which involves us defining entirely the old v3 structs, and
205 * warning users to migrate to the new v4 versions. We avoided
206 * just replacing the v3 structs with the v4 equivalents
207 * because then direct access of v3 fields (.real[0][0]) would
208 * cause a compiler error with no error messages. We accept
209 * that only for heap-memory structs which always have a
210 * proceeding create() function which will dispatch the warning.
211 */
212
213
214typedef struct ComplexMatrix2
215{
216 qreal real[2][2];
217 qreal imag[2][2];
219
220typedef struct ComplexMatrix4
221{
222 qreal real[4][4];
223 qreal imag[4][4];
225
226
227// enable referencess to ComplexMatrix2/ 4 inside this header without
228// causing a warning unrelated to the user's code (must define these
229// before below macro which would then seek to replace the values)
230
233
234
235// warn about use of ComplexMatrix1/2, but allow it
236
237#define ComplexMatrix2 \
238 _WARN_GENERAL_MSG( \
239 "The QuEST type 'ComplexMatrix2' is deprecated in favour of 'CompMatr1' which has a different memory layout. We will attempt to " \
240 "automatically replace your 'ComplexMatrix2' with a 'CompMatr1' instance in subsequently invoked functions.") \
241 ComplexMatrix2
242
243#define ComplexMatrix4 \
244 _WARN_GENERAL_MSG( \
245 "The QuEST type 'ComplexMatrix4' is deprecated in favour of 'CompMatr2' which has a different memory layout. We will attempt to " \
246 "automatically replace your 'ComplexMatrix4' with a 'CompMatr2' instance in subsequently invoked functions.") \
247 ComplexMatrix4
248
249
250// automatically convert ComplexMatrix2/4 to CompMatr1/2 when
251// passed to a v3 function which has a v4 port
252
253#define _GET_COMP_MATR_1_FROM_COMPLEX_MATRIX_2(m) \
254 (CompMatr1) { \
255 .numQubits = 1, \
256 .numRows = 2, \
257 .elems = { \
258 {getQcomp(m.real[0][0], m.imag[0][0]), getQcomp(m.real[0][1], m.imag[0][1])}, \
259 {getQcomp(m.real[1][0], m.imag[1][0]), getQcomp(m.real[1][1], m.imag[1][1])}}}
260
261#define _GET_COMP_MATR_2_FROM_COMPLEX_MATRIX_4(m) \
262 (CompMatr2) { \
263 .numQubits = 2, \
264 .numRows = 4, \
265 .elems = { \
266 {getQcomp(m.real[0][0], m.imag[0][0]), getQcomp(m.real[0][1], m.imag[0][1]), getQcomp(m.real[0][2], m.imag[0][2]), getQcomp(m.real[0][3], m.imag[0][3])}, \
267 {getQcomp(m.real[1][0], m.imag[1][0]), getQcomp(m.real[1][1], m.imag[1][1]), getQcomp(m.real[1][2], m.imag[1][2]), getQcomp(m.real[1][3], m.imag[1][3])}, \
268 {getQcomp(m.real[2][0], m.imag[2][0]), getQcomp(m.real[2][1], m.imag[2][1]), getQcomp(m.real[2][2], m.imag[2][2]), getQcomp(m.real[2][3], m.imag[2][3])}, \
269 {getQcomp(m.real[3][0], m.imag[3][0]), getQcomp(m.real[3][1], m.imag[3][1]), getQcomp(m.real[3][2], m.imag[3][2]), getQcomp(m.real[3][3], m.imag[3][3])}}}
270
271
272
273/*
274 * PAULI OPERATOR TYPES
275 */
276
277enum pauliOpType {PAULI_I=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3};
278
279#define _WARN_DEPRECATED_PAULI_ENUM(enum, intcode, char1, char2, char3) \
280 _WARN_GENERAL_MSG( \
281 "The QuEST enum '" #enum "' is deprecated, although has been defined in the deprecation header for convenience. " \
282 "Please instead use integer " #intcode " or characters '" #char1 "', '" #char2 "', '" #char3 "'.") \
283
284typedef enum pauliOpType _NoWarnPauliOpType;
285
286#define pauliOpType \
287 _WARN_GENERAL_MSG("The QuEST type 'enum pauliOpType' is deprecated, although it is still defined in the deprecation header for convenience.") \
288 pauliOpType
289
290#define PAULI_I \
291 _WARN_DEPRECATED_PAULI_ENUM(PAULI_I, 0, I, i, 0) \
292 PAULI_I
293
294#define PAULI_X \
295 _WARN_DEPRECATED_PAULI_ENUM(PAULI_X, 1, X, x, 1) \
296 PAULI_X
297
298#define PAULI_Y \
299 _WARN_DEPRECATED_PAULI_ENUM(PAULI_Y, 2, Y, y, 2) \
300 PAULI_Y
301
302#define PAULI_Z \
303 _WARN_DEPRECATED_PAULI_ENUM(PAULI_Z, 3, Z, z, 3) \
304 PAULI_Z
305
306
307
308/*
309 * REMAINING TYPES
310 */
311
312
313#define _GET_QCOMP_FROM_COMPLEX_STRUCT(x) \
314 getQcomp((x).real, (x).imag)
315
316#define Complex \
317 _WARN_GENERAL_MSG( \
318 "The QuEST type 'Complex' is deprecated, and replaced with complex scalar primitive 'qcomp' which can be instantiated " \
319 "with literals and modified with overloaded arithmetic operators. References to 'Complex' will be automatically replaced " \
320 "with an anonymous inline struct, though the QuEST will only ever return 'qcomp' instances.") \
321 struct { qreal real; qreal imag; }
322
323
324#define ComplexMatrixN \
325 _WARN_TYPE_RENAMED("ComplexMatrixN", "CompMatr") \
326 CompMatr
327
328
329#define PauliHamil \
330 _WARN_TYPE_RENAMED("PauliHamil", "PauliStrSum") \
331 PauliStrSum
332
333
334#define DiagonalOp \
335 _WARN_TYPE_RENAMED("DiagonalOp", "FullStateDiagMatr") \
336 FullStateDiagMatr
337
338
339#define SubDiagonalOp \
340 _WARN_TYPE_RENAMED("SubDiagonalOp", "DiagMatr") \
341 DiagMatr
342
343
344#define Vector \
345 _WARN_GENERAL_MSG("The QuEST type 'Vector' is deprecated, and will be automatically replaced with an inline struct.") \
346 struct { qreal x; qreal y; qreal z; }
347
348
349#define phaseFunc \
350 _ERROR_GENERAL_MSG( \
351 "The QuEST type 'enum phaseFunc' is deprecated. The functions which replace the 'applyPhaseFunc' family, such as " \
352 "'setDiagMatrFromMultiVarFunc()' and 'setDiagMatrFromMultiDimArray()', do not use pre-defined enums." )
353
354#define bitEncoding \
355 _ERROR_GENERAL_MSG( \
356 "The QuEST type 'enum bitEncoding' is deprecated. The new v4 function 'setDiagMatrFromMultiVarFunc()' instead accepts " \
357 "an int flag to indicate whether (1) or not (0) to interpret the basis state bits under two's complement singed encoding." )
358
359
360
361/*
362 * REMOVED FUNCTIONS WITH NO REPLACEMENT
363 */
364
365
366#define toComplex(...) \
367 _ERROR_FUNC_REMOVED("toComplex()")
368
369#define fromComplex(...) \
370 _ERROR_FUNC_REMOVED("fromComplex()")
371
372
373#define applyMultiControlledMatrixN(...) \
374 _ERROR_FUNC_REMOVED("applyMultiControlledMatrixN()") // our new leftapplyCompMatr doesn't accept controls
375
376
377#define syncQuESTSuccess(...) \
378 _ERROR_FUNC_REMOVED("syncQuESTSuccess()")
379
380
381#define startRecordingQASM(...) \
382 _ERROR_FUNC_REMOVED("startRecordingQASM()")
383
384#define stopRecordingQASM(...) \
385 _ERROR_FUNC_REMOVED("stopRecordingQASM()")
386
387#define clearRecordedQASM(...) \
388 _ERROR_FUNC_REMOVED("clearRecordedQASM()")
389
390#define printRecordedQASM(...) \
391 _ERROR_FUNC_REMOVED("printRecordedQASM()")
392
393#define writeRecordedQASMToFile(...) \
394 _ERROR_FUNC_REMOVED("writeRecordedQASMToFile()")
395
396
397#define bindArraysToStackComplexMatrixN(...) \
398 _ERROR_FUNC_REMOVED("bindArraysToStackComplexMatrixN()")
399
400#define getStaticComplexMatrixN(...) \
401 _ERROR_FUNC_REMOVED("getStaticComplexMatrixN()")
402
403
404#define reportState(qureg) \
405 _ERROR_FUNC_REMOVED("reportState(qureg)", "reportQuregToFile(qureg, char* fn)")
406
407
408
409/*
410 * FUNCTIONS WITH REPLACEMENTS WHICH CANNOT BE AUTOMATICALLY CALLED
411 */
412
413
414#define initComplexMatrixN(...) \
415 _ERROR_FUNC_RENAMED("initComplexMatrixN(ComplexMatrixN, qreal[][], qreal[][])", "setCompMatr(CompMatr, qcomp[][])")
416
417
418#define createPauliHamil(...) \
419 _ERROR_FUNC_RENAMED( \
420 "createPauliHamil(int numQubits, int numTerms)", \
421 "createPauliStrSum(PauliStr* strings, qcomp* coeffs, qindex numTerms)")
422
423#define initPauliHamil(...) \
424 _ERROR_FUNC_RENAMED( \
425 "initPauliHamil(PauliHamil hamil, qreal* coeffs, enum pauliOpType* codes)", \
426 "createPauliStrSum(PauliStr* strings, qcomp* coeffs, qindex numTerms)")
427
428
429#define initDiagonalOp(...) \
430 _ERROR_FUNC_RENAMED( \
431 "initDiagonalOp(DiagonalOp obj, qreal* allElemsRe, qreal* allElemsIm)", \
432 "setFullStateDiagMatr(FullStateDiagMatr obj, qindex startInd, qcomp* someElems, qindex numElems)")
433
434#define setDiagonalOpElems(...) \
435 _ERROR_FUNC_RENAMED( \
436 "setDiagonalOpElems(DiagonalOp, qindex, qreal*, qreal*, qindex)", \
437 "setFullStateDiagMatr(FullStateDiagMatr, qindex, qcomp*, qindex)")
438
439
440#define initStateFromAmps(...) \
441 _ERROR_FUNC_RENAMED("initStateFromAmps(Qureg, qreal*, qreal*)", "initArbitraryPureState(Qureg, qcomp*)")
442
443#define setAmps(...) \
444 _ERROR_FUNC_RENAMED("setAmps(Qureg, qindex, qreal*, qreal*, qindex)", "setQuregAmps(Qureg, qindex, qcomp*, qindex)")
445
446#define setDensityAmps(...) \
447 _ERROR_FUNC_RENAMED( \
448 "setDensityAmps(Qureg, qindex startRow, qindex startCol, qreal* flatAmpsRe, qreal* flatAmpsIm, qindex numFlatAmps)", \
449 "setDensityQuregAmps(Qureg, qindex startRow, qindex startCol, qcomp** amps, qindex numRows, qindex numCols)")
450
451
452#define applyPhaseFunc(...) \
453 _ERROR_PHASE_FUNC_REMOVED("applyPhaseFunc")
454
455#define applyPhaseFuncOverrides(...) \
456 _ERROR_PHASE_FUNC_REMOVED("applyPhaseFuncOverrides")
457
458#define applyMultiVarPhaseFunc(...) \
459 _ERROR_PHASE_FUNC_REMOVED("applyMultiVarPhaseFunc")
460
461#define applyMultiVarPhaseFuncOverrides(...) \
462 _ERROR_PHASE_FUNC_REMOVED("applyMultiVarPhaseFuncOverrides")
463
464#define applyNamedPhaseFunc(...) \
465 _ERROR_PHASE_FUNC_REMOVED("applyNamedPhaseFunc")
466
467#define applyNamedPhaseFuncOverrides(...) \
468 _ERROR_PHASE_FUNC_REMOVED("applyNamedPhaseFuncOverrides")
469
470#define applyParamNamedPhaseFunc(...) \
471 _ERROR_PHASE_FUNC_REMOVED("applyParamNamedPhaseFunc")
472
473#define applyParamNamedPhaseFuncOverrides(...) \
474 _ERROR_PHASE_FUNC_REMOVED("applyParamNamedPhaseFuncOverrides")
475
476
477
478/*
479 * FUNCTIONS WITH THE SAME NAME BUT 1 INSTEAD OF 2 ARGS
480 *
481 * can be redirected to the new single-arg form, issuing a warning
482 * when given the second, superfluous parameter. Note that deprecated
483 * functions which can accept C99 inline temporary arrays, e.g.
484 * f((qcomp[]) {1,2,3}), can not be overloaded in this way, because
485 * the array elements confuse variadic macros
486 */
487
488
489#define _GET_MACRO_WITH_1_OR_2_ARGS(_1, _2, macroname, ...) macroname
490
491#define _CALL_MACRO_WITH_1_OR_2_ARGS(prefix, ...) \
492 _GET_MACRO_WITH_1_OR_2_ARGS(__VA_ARGS__, prefix##_2, prefix##_1)(__VA_ARGS__)
493
494
495#define _CREATE_QUREG_1(n) \
496 createQureg(n)
497
498#define _CREATE_QUREG_2(n, env) \
499 _WARN_FUNC_NOW_HAS_FEWER_ARGS("createQureg(int, QuESTEnv)", "createQureg(int)") \
500 _CREATE_QUREG_1(n)
501
502#define createQureg(...) \
503 _CALL_MACRO_WITH_1_OR_2_ARGS(_CREATE_QUREG, __VA_ARGS__)
504
505
506
507#define _CREATE_DENSITY_QUREG_1(n) \
508 createDensityQureg(n)
509
510#define _CREATE_DENSITY_QUREG_2(n, env) \
511 _WARN_FUNC_NOW_HAS_FEWER_ARGS("createDensityQureg(int, QuESTEnv)", "createDensityQureg(int)") \
512 _CREATE_DENSITY_QUREG_1(n)
513
514#define createDensityQureg(...) \
515 _CALL_MACRO_WITH_1_OR_2_ARGS(_CREATE_DENSITY_QUREG, __VA_ARGS__)
516
517
518
519#define _CREATE_CLONE_QUREG_1(n) \
520 createCloneQureg(n)
521
522#define _CREATE_CLONE_QUREG_2(n, env) \
523 _WARN_FUNC_NOW_HAS_FEWER_ARGS("createCloneQureg(Qureg, QuESTEnv)", "createCloneQureg(Qureg)") \
524 _CREATE_CLONE_QUREG_1(n)
525
526#define createCloneQureg(...) \
527 _CALL_MACRO_WITH_1_OR_2_ARGS(_CREATE_CLONE_QUREG, __VA_ARGS__)
528
529
530
531#define _DESTROY_QUREG_1(qureg) \
532 destroyQureg(qureg)
533
534#define _DESTROY_QUREG_2(n, env) \
535 _WARN_FUNC_NOW_HAS_FEWER_ARGS("destroyQureg(Qureg, QuESTEnv)", "destroyQureg(Qureg)") \
536 _DESTROY_QUREG_1(n)
537
538#define destroyQureg(...) \
539 _CALL_MACRO_WITH_1_OR_2_ARGS(_DESTROY_QUREG, __VA_ARGS__)
540
541
542
543#define _GET_ENVIRONMENT_STRING_1(str) \
544 getQuESTEnvironmentString(str)
545
546#define _GET_ENVIRONMENT_STRING_2(str) \
547 _WARN_FUNC_NOW_HAS_FEWER_ARGS("getQuESTEnvironmentString(QuESTEnv, char[200])", "getQuESTEnvironmentString(char[200])") \
548 _GET_ENVIRONMENT_STRING_1(str)
549
550#define getQuESTEnvironmentString(...) \
551 _CALL_MACRO_WITH_1_OR_2_ARGS(_GET_ENVIRONMENT_STRING, __VA_ARGS__)
552
553
554
555/*
556 * FUNCTIONS WITH THE SAME NAME BUT 1 INSTEAD OF 3 ARGS
557 *
558 * which are handled similar to above
559 */
560
561
562#define _GET_MACRO_WITH_1_OR_3_ARGS(_1, _2, _3, macroname, ...) macroname
563
564#define _CALL_MACRO_WITH_1_OR_3_ARGS(prefix, ...) \
565 _GET_MACRO_WITH_1_OR_3_ARGS(__VA_ARGS__, prefix##_3, prefix##_2, prefix##_1)(__VA_ARGS__)
566
567
568#define _GET_QUEST_SEEDS_1(out) \
569 getQuESTSeeds(out)
570
571#define _GET_QUEST_SEEDS_3(env, out, numOut) \
572 _WARN_FUNC_NOW_HAS_FEWER_ARGS( \
573 "getQuESTSeeds(QuESTEnv env, unsigned long int* out, int numOut)", \
574 "getQuESTSeeds(unsigned* out)") \
575 _GET_QUEST_SEEDS_1(out)
576
577#define getQuESTSeeds(...) \
578 _CALL_MACRO_WITH_1_OR_3_ARGS(_GET_QUEST_SEEDS, __VA_ARGS__)
579
580
581
582/*
583 * FUNCTIONS WITH THE SAME NAME BUT 0 INSTEAD OF 1 ARGS
584 *
585 * which are handled similar to above, but require more
586 * pre-processor trickery to handle the no-arg case
587 */
588
589
590#define _COUNT_ZERO_OR_ONE_ARGS(...) _COUNT_ZERO_OR_ONE_ARGS_INNER(__VA_ARGS__, 1, 0,)
591#define _COUNT_ZERO_OR_ONE_ARGS_INNER(_0, _1, X, ...) X
592#define _CONCAT_SYMBOLS(A, B) _CONCAT_SYMBOLS_INNER(A, B)
593#define _CONCAT_SYMBOLS_INNER(A, B) A ## B
594#define _COMMA_SEPERATOR ,
595
596
597
598#define _SYNC_QUEST_ENV_0(_) \
599 syncQuESTEnv()
600
601#define _SYNC_QUEST_ENV_1(env) \
602 _WARN_FUNC_NOW_HAS_FEWER_ARGS("syncQuESTEnv(QuESTEnv)", "syncQuESTEnv()") \
603 syncQuESTEnv()
604
605#define syncQuESTEnv(X) \
606 _CONCAT_SYMBOLS(_SYNC_QUEST_ENV_, _COUNT_ZERO_OR_ONE_ARGS(_COMMA_SEPERATOR ## X))(X)
607
608
609
610#define _REPORT_QUEST_ENV_0(_) \
611 reportQuESTEnv()
612
613#define _REPORT_QUEST_ENV_1(env) \
614 _WARN_FUNC_NOW_HAS_FEWER_ARGS("reportQuESTEnv(QuESTEnv)", "reportQuESTEnv()") \
615 reportQuESTEnv()
616
617#define reportQuESTEnv(X) \
618 _CONCAT_SYMBOLS(_REPORT_QUEST_ENV_, _COUNT_ZERO_OR_ONE_ARGS(_COMMA_SEPERATOR ## X))(X)
619
620
621
622/*
623 * KRAUS MAPS
624 *
625 * which we handle explicitly, because the name 'mixKrausMap' is retained
626 * (in v3, it is a 1-qubit Kraus map, but in v4, it has any-qubit) with
627 * the same number of arguments, albeit with different types. This requires
628 * us to use a C11 _Generic which must dispatch to compile-time (NOT
629 * preprocessor) functions. We re-use an inner macro for all Kraus map funcs,
630 * which accepts the variable number of target qubits at the end.
631 */
632
633
634#define _MIX_KRAUS_MAP_INNER(qureg, ops, numOps, targs, numTargs) \
635 int dim = 1 << numTargs; \
636 qcomp*** ptrs = (qcomp***) malloc(numOps * sizeof *ptrs); \
637 for (int n=0; n<numOps; n++) { \
638 ptrs[n] = (qcomp**) malloc(dim * sizeof **ptrs); \
639 for (int r=0; r<dim; r++) { \
640 ptrs[n][r] = (qcomp*) malloc(dim * sizeof ***ptrs); \
641 for (int c=0; c<dim; c++) \
642 ptrs[n][r][c] = getQcomp(ops[n].real[r][c], ops[n].imag[r][c]); \
643 } \
644 } \
645 \
646 KrausMap map = createKrausMap(numTargs, numOps); \
647 setKrausMap(map, ptrs); \
648 (mixKrausMap)(qureg, (targs), numTargs, map); /* calls below macro, wrapped to avoid warning */ \
649 destroyKrausMap(map); \
650 \
651 for (int n=0; n<numOps; n++) { \
652 for (int r=0; r<dim; r++) \
653 free(ptrs[n][r]); \
654 free(ptrs[n]); \
655 } \
656 free(ptrs);
657
658static inline void v3_mixKrausMap(Qureg qureg, int targ, _NoWarnComplexMatrix2 *ops, int numOps) {
659 _MIX_KRAUS_MAP_INNER(qureg, ops, numOps, &targ, 1);
660}
661
662#define mixKrausMap(...) \
663 _WARN_UNSUPPRESSABLE_MSG( \
664 "The QuEST function 'mixKrausMap()' has changed from v3 to v4. The old signature was " \
665 "'mixKrausMap(Qureg, int targ, ComplexMatrix2* ops, int numOps)' while the new signature is " \
666 "'mixKrausMap(Qureg, int* targs, int numTargs, KrausMap)'. Because the function name and its " \
667 "number of arguments have not changed, we are unable to automatically map a v3 invocation to " \
668 "the v4 API, nor can we detect when the v4 API has been used in order to avoid this message. " \
669 "Hence, this warning will either be obsolete (because you have already migrated to the v4 API), " \
670 "or precedes a compilation failure below due to continued use of the v3 API. To continue using " \
671 "the v3 API, replace 'mixKrausMap' with 'v3_mixKrausMap' which will issue no warning nor error. " \
672 "This warning cannot be suppressed.") \
673 mixKrausMap(__VA_ARGS__)
674
675
676
677
678
679static inline void _mixNonTPKrausMap(Qureg qureg, int targ, _NoWarnComplexMatrix2 *ops, int numOps) {
680 qreal eps = getQuESTValidationEpsilon();
682 _MIX_KRAUS_MAP_INNER(qureg, ops, numOps, &targ, 1);
684}
685
686#define mixNonTPKrausMap(...) \
687 _WARN_FUNC_RENAMED( \
688 "mixNonTPKrausMap(Qureg, int targ, ComplexMatrix2* ops, int numOps)", \
689 "mixUnnormalizedKrausMap(Qureg, int* targs, int numTargs, KrausMap)") \
690 _mixNonTPKrausMap(__VA_ARGS__)
691
692
693
694static inline void _mixTwoQubitKrausMap(Qureg qureg, int targ1, int targ2, _NoWarnComplexMatrix4 *ops, int numOps, int isNonCPTP) {
695 int targs[] = {targ1, targ2};
696 qreal eps = getQuESTValidationEpsilon();
697 if (isNonCPTP) setQuESTValidationEpsilon(0);
698 _MIX_KRAUS_MAP_INNER(qureg, ops, numOps, targs, 2);
700}
701
702#define mixTwoQubitKrausMap(...) \
703 _WARN_FUNC_RENAMED( \
704 "mixTwoQubitKrausMap(Qureg, int targ1, int targ2, ComplexMatrix4* ops, int numOps)", \
705 "mixKrausMap(Qureg, int* targs, int numTargs, KrausMap)") \
706 _mixTwoQubitKrausMap(__VA_ARGS__, 0)
707
708#define mixNonTPTwoQubitKrausMap(...) \
709 _WARN_FUNC_RENAMED( \
710 "mixNonTPTwoQubitKrausMap(Qureg, int targ1, int targ2, ComplexMatrix4* ops, int numOps)", \
711 "mixUnnormalizedKrausMap(Qureg, int* targs, int numTargs, KrausMap)") \
712 _mixTwoQubitKrausMap(__VA_ARGS__, 1)
713
714
715
716static inline void _mixMultiQubitKrausMap(Qureg qureg, int* targs, int numTargs, CompMatr *ops, int numOps, int isNonCPTP) {
717
718 qcomp*** ptrs = (qcomp***) malloc(numOps * sizeof *ptrs);
719 for (int n=0; n<numOps; n++)
720 ptrs[n] = ops[n].cpuElems;
721
722 KrausMap map = createKrausMap(numTargs, numOps);
723 setKrausMap(map, ptrs);
724 free(ptrs);
725
726 qreal eps = getQuESTValidationEpsilon();
727 if (isNonCPTP) setQuESTValidationEpsilon(0);
728 (mixKrausMap)(qureg, targs, numTargs, map); // calls above macro, wrapped to avoid warning */
729 destroyKrausMap(map);
731}
732
733#define mixMultiQubitKrausMap(...) \
734 _WARN_FUNC_RENAMED( \
735 "mixMultiQubitKrausMap(Qureg, int* targs, int numTargs, ComplexMatrixN* ops, int numOps)", \
736 "mixKrausMap(Qureg, int* targs, int numTargs, KrausMap)") \
737 _mixMultiQubitKrausMap(__VA_ARGS__, 0)
738
739#define mixNonTPMultiQubitKrausMap(...) \
740 _WARN_FUNC_RENAMED( \
741 "mixNonTPMultiQubitKrausMap(Qureg, int* targs, int numTargs, ComplexMatrixN* ops, int numOps)", \
742 "mixUnnormalisedKrausMap(Qureg, int* targs, int numTargs, KrausMap)") \
743 _mixMultiQubitKrausMap(__VA_ARGS__, 1)
744
745
746
747/*
748 * FUNCTIONS WITH CHANGED NAMES (AND POSSIBLY NUM ARGS)
749 *
750 * We use variadic args wherever possible so that users passing
751 * the wrong number of args will trigger a function-related
752 * compiler error, rather than the less-readable macro one. This
753 * also enables users to pass C99 inline compound literal arrays,
754 * which otherwise confuse the macros.
755 */
756
757
758static inline QuESTEnv _createQuESTEnv() {
759 initQuESTEnv();
760 return getQuESTEnv();
761}
762
763#define createQuESTEnv() \
764 _WARN_GENERAL_MSG( \
765 "The QuEST function 'createQuESTEnv()' is deprecated in favour of " \
766 "'initQuESTEnv()' which returns nothing, and 'getQuESTEnv()' which " \
767 "returns an immutable copy of the internally-managed environment. " \
768 "This second function is for convenience; the API no longer needs " \
769 "to receive the environment instance as a parameter. The above " \
770 "mentioned functions have been automatically invoked.") \
771 _createQuESTEnv()
772
773#define destroyQuESTEnv(...) \
774 _WARN_FUNC_RENAMED("destroyQuESTEnv(QuESTEnv)", "finalizeQuESTEnv()") \
775 finalizeQuESTEnv()
776
777
778
779#define createComplexMatrixN(...) \
780 _WARN_FUNC_RENAMED("createComplexMatrixN()", "createCompMatr()") \
781 createCompMatr(__VA_ARGS__)
782
783#define destroyComplexMatrixN(...) \
784 _WARN_FUNC_RENAMED("destroyComplexMatrixN()", "destroyCompMatr()") \
785 destroyCompMatr(__VA_ARGS__)
786
787
788
789#define destroyPauliHamil(...) \
790 _WARN_FUNC_RENAMED("destroyPauliHamil()", "destroyPauliStrSum()") \
791 destroyPauliStrSum(__VA_ARGS__)
792
793#define createPauliHamilFromFile(...) \
794 _WARN_FUNC_RENAMED("createPauliHamilFromFile()", "createPauliStrSumFromReversedFile()") \
795 createPauliStrSumFromReversedFile(__VA_ARGS__)
796
797#define reportPauliHamil(...) \
798 _WARN_FUNC_RENAMED("reportPauliHamil()", "reportPauliStrSum()") \
799 reportPauliStrSum(__VA_ARGS__)
800
801
802
803#define createDiagonalOp(numQb, env) \
804 _WARN_FUNC_RENAMED("createDiagonalOp(int, QuESTEnv)", "createFullStateDiagMatr(int)") \
805 createFullStateDiagMatr(numQb)
806
807#define destroyDiagonalOp(diagOp, env) \
808 _WARN_FUNC_RENAMED("destroyDiagonalOp(DiagonalOp, QuESTEnv)", "destroyFullStateDiagMatr(FullStateDiagMatr)") \
809 destroyFullStateDiagMatr(diagOp)
810
811#define syncDiagonalOp(...) \
812 _WARN_FUNC_RENAMED("syncDiagonalOp()", "syncFullStateDiagMatr()") \
813 syncFullStateDiagMatr(__VA_ARGS__)
814
815#define initDiagonalOpFromPauliHamil(...) \
816 _WARN_FUNC_RENAMED("initDiagonalOpFromPauliHamil()", "setFullStateDiagMatrFromPauliStrSum()") \
817 setFullStateDiagMatrFromPauliStrSum(__VA_ARGS__)
818
819#define createDiagonalOpFromPauliHamilFile(fn, env) \
820 _WARN_FUNC_RENAMED("createDiagonalOpFromPauliHamilFile(char*, QuESTEnv)", "createFullStateDiagMatrFromPauliStrSumFile(char*)") \
821 createFullStateDiagMatrFromPauliStrSumFile(fn)
822
823#define applyDiagonalOp(...) \
824 _WARN_FUNC_RENAMED("applyDiagonalOp()", "leftapplyFullStateDiagMatr()") \
825 leftapplyFullStateDiagMatr(__VA_ARGS__)
826
827#define calcExpecDiagonalOp(...) \
828 _WARN_FUNC_RENAMED("calcExpecDiagonalOp()", "calcExpecNonHermitianFullStateDiagMatr()") \
829 calcExpecNonHermitianFullStateDiagMatr(__VA_ARGS__)
830
831
832
833#define createSubDiagonalOp(...) \
834 _WARN_FUNC_RENAMED("createSubDiagonalOp()", "createDiagMatr()") \
835 createDiagMatr(__VA_ARGS__)
836
837#define destroySubDiagonalOp(...) \
838 _WARN_FUNC_RENAMED("destroySubDiagonalOp()", "destroyDiagMatr()") \
839 destroyDiagMatr(__VA_ARGS__)
840
841#define diagonalUnitary(...) \
842 _WARN_FUNC_RENAMED("diagonalUnitary()", "applyDiagMatr()") \
843 applyDiagMatr(__VA_ARGS__)
844
845#define applySubDiagonalOp(...) \
846 _WARN_FUNC_RENAMED("applySubDiagonalOp()", "leftapplyDiagMatr()") \
847 leftapplyDiagMatr(__VA_ARGS__)
848
849static inline void _applyGateSubDiagonalOp(Qureg qureg, int* targets, int numTargets, DiagMatr op) {
850 qreal eps = getQuESTValidationEpsilon();
852 applyDiagMatr(qureg, targets, numTargets, op);
854}
855#define applyGateSubDiagonalOp(...) \
856 _WARN_GENERAL_MSG( \
857 "The QuEST function 'applyGateSubDiagonalOp()' is deprecated. To achieve the same thing, disable " \
858 "numerical validation via 'setQuESTValidationEpsilon(0)' before calling 'applyDiagMatr()'. You can " \
859 "save the existing epsilon via 'getQuESTValidationEpsilon()' to thereafter restore. This procedure " \
860 "has been performed here automatically.") \
861 _applyGateSubDiagonalOp(__VA_ARGS__)
862
863
864
865#define reportStateToScreen(qureg, env, rank) \
866 _WARN_FUNC_RENAMED("reportStateToScreen(qureg, env, rank)", "reportQureg(qureg)") \
867 reportQureg(qureg)
868
869
870
871#define getNumQubits(qureg) \
872 _WARN_FUNC_RENAMED("getNumQubits(qureg)", "qureg.numQubits") \
873 (qureg).numQubits
874
875 #define getNumAmps(qureg) \
876 _WARN_FUNC_RENAMED("getNumAmps(qureg)", "qureg.numAmps") \
877 (qureg).numAmps
878
879
880
881#define setQuregToPauliHamil(...) \
882 _WARN_FUNC_RENAMED("setQuregToPauliHamil()", "setQuregToPauliStrSum()") \
883 setQuregToPauliStrSum(__VA_ARGS__)
884
885#define cloneQureg(...) \
886 _WARN_FUNC_RENAMED("cloneQureg()", "setQuregToClone()") \
887 setQuregToClone(__VA_ARGS__)
888
889
890
891static inline void _setWeightedQureg(qcomp f1, Qureg q1, qcomp f2, Qureg q2, qcomp fOut, Qureg qOut) {
892 qcomp coeffs[] = {fOut, f1, f2};
893 Qureg quregs[] = {qOut, q1, q2};
894 setQuregToWeightedSum(qOut, coeffs, quregs, 3);
895}
896
897#define setWeightedQureg(f1, q1, f2, q2, fOut, qOut) \
898 _WARN_GENERAL_MSG( \
899 "The QuEST function 'setWeightedQureg(f1,q1, f2,q2, fOut,qOut)' is deprecated, and replaced with " \
900 "'setQuregToWeightedSum(qOut, {f1,f2,...}, {q1,q2,..}, len)' which has been automatically invoked. " \
901 "Beware that the order of the arguments has changed, so that the first supplied Qureg is modified." ) \
902 _setWeightedQureg( \
903 _GET_QCOMP_FROM_COMPLEX_STRUCT(f1) ,q1, \
904 _GET_QCOMP_FROM_COMPLEX_STRUCT(f2) ,q2, \
905 _GET_QCOMP_FROM_COMPLEX_STRUCT(fOut), qOut)
906
907
908
909#define phaseShift(...) \
910 _WARN_FUNC_RENAMED("phaseShift()", "applyPhaseShift()") \
911 applyPhaseShift(__VA_ARGS__)
912
913#define controlledPhaseShift(...) \
914 _WARN_FUNC_RENAMED("controlledPhaseShift()", "applyTwoQubitPhaseShift()") \
915 applyTwoQubitPhaseShift(__VA_ARGS__)
916
917#define multiControlledPhaseShift(...) \
918 _WARN_FUNC_RENAMED("multiControlledPhaseShift()", "applyMultiQubitPhaseShift()") \
919 applyMultiQubitPhaseShift(__VA_ARGS__)
920
921#define controlledPhaseFlip(...) \
922 _WARN_FUNC_RENAMED("controlledPhaseFlip()", "applyTwoQubitPhaseFlip()") \
923 applyTwoQubitPhaseFlip(__VA_ARGS__)
924
925#define multiControlledPhaseFlip(...) \
926 _WARN_FUNC_RENAMED("multiControlledPhaseFlip()", "applyMultiQubitPhaseFlip()") \
927 applyMultiQubitPhaseFlip(__VA_ARGS__)
928
929
930
931#define sGate(...) \
932 _WARN_FUNC_RENAMED("sGate()", "applyS()") \
933 applyS(__VA_ARGS__)
934
935#define tGate(...) \
936 _WARN_FUNC_RENAMED("tGate()", "applyT()") \
937 applyT(__VA_ARGS__)
938
939
940
941#define copyStateToGPU(...) \
942 _WARN_FUNC_RENAMED("copyStateToGPU()", "syncQuregToGpu()") \
943 syncQuregToGpu(__VA_ARGS__)
944
945#define copyStateFromGPU(...) \
946 _WARN_FUNC_RENAMED("copyStateFromGPU()", "syncQuregFromGpu()") \
947 syncQuregFromGpu(__VA_ARGS__)
948
949#define copySubstateToGPU(...) \
950 _WARN_FUNC_RENAMED("copySubstateToGPU()", "syncSubQuregToGpu()") \
951 syncSubQuregToGpu(__VA_ARGS__)
952
953#define copySubstateFromGPU(...) \
954 _WARN_FUNC_RENAMED("copySubstateFromGPU()", "syncSubQuregFromGpu()") \
955 syncSubQuregFromGpu(__VA_ARGS__)
956
957
958
959#define getAmp(...) \
960 _WARN_FUNC_RENAMED("getAmp()", "getQuregAmp()") \
961 getQuregAmp(__VA_ARGS__)
962
963#define getDensityAmp(...) \
964 _WARN_FUNC_RENAMED("getDensityAmp()", "getDensityQuregAmp()") \
965 getDensityQuregAmp(__VA_ARGS__)
966
967#define getRealAmp(...) \
968 _WARN_FUNC_RENAMED("getRealAmp()", "real(getQuregAmp())") \
969 real(getQuregAmp(__VA_ARGS__))
970
971#define getImagAmp(...) \
972 _WARN_FUNC_RENAMED("getImagAmp()", "imag(getImagAmp())") \
973 imag(getQuregAmp(__VA_ARGS__))
974
975#define getProbAmp(...) \
976 _WARN_FUNC_RENAMED("getProbAmp()", "calcProbOfBasisState()") \
977 calcProbOfBasisState(__VA_ARGS__)
978
979#define calcProbOfOutcome(...) \
980 _WARN_FUNC_RENAMED("calcProbOfOutcome()", "calcProbOfQubitOutcome()") \
981 calcProbOfQubitOutcome(__VA_ARGS__)
982
983#define calcProbOfAllOutcomes(...) \
984 _WARN_FUNC_RENAMED("calcProbOfAllOutcomes()", "calcProbsOfAllMultiQubitOutcomes()") \
985 calcProbsOfAllMultiQubitOutcomes(__VA_ARGS__)
986
987#define calcDensityInnerProduct(...) \
988 _WARN_FUNC_RENAMED("calcDensityInnerProduct()", "calcInnerProduct()") \
989 calcInnerProduct(__VA_ARGS__)
990
991#define calcHilbertSchmidtDistance(...) \
992 _WARN_FUNC_RENAMED("calcHilbertSchmidtDistance()", "calcDistance()") \
993 calcDistance(__VA_ARGS__)
994
995#define calcExpecPauliHamil(qureg, hamil, workspace) \
996 _WARN_FUNC_RENAMED("calcExpecPauliHamil(Qureg, PauliHamil, Qureg)", "calcExpecPauliStrSum(Qureg, PauliStrSum)") \
997 calcExpecPauliStrSum(qureg, hamil)
998
999
1000
1001static inline qreal _calcExpecPauliStr(Qureg qureg, int* targs, _NoWarnPauliOpType* enums, int numTargs) {
1002
1003 int codes[100];
1004 for (int i=0; i<numTargs && i<100; i++)
1005 codes[i] = enums[i];
1006
1007 return calcExpecPauliStr(qureg, getPauliStr(codes, targs, numTargs));
1008}
1009
1010#define calcExpecPauliProd(qureg, targs, paulis, numTargs, workspace) \
1011 _WARN_FUNC_RENAMED( \
1012 "calcExpecPauliProd(qureg, targs, paulis, numTargs, workspace)", \
1013 "calcExpecPauliStr(qureg, getPauliStr(paulis, targs, numTargs))") \
1014 _calcExpecPauliStr(qureg, targs, paulis, numTargs)
1015
1016
1017
1018static inline PauliStrSum _createPauliStrSumFromCodes(int numQubits, _NoWarnPauliOpType* allPauliCodes, qreal* termCoeffs, int numTerms) {
1019
1020 int* targs = (int*) malloc(numQubits * sizeof *targs);
1021 for (int i=0; i<numQubits; i++)
1022 targs[i] = i;
1023
1024 PauliStr* strings = (PauliStr*) malloc(numTerms * sizeof *strings);
1025 for (int i=0; i<numTerms; i++) {
1026
1027 int codes[100]; // assumes numQubits<=100
1028 for (int j=0; j<numQubits && j<100; j++)
1029 codes[j] = (int) allPauliCodes[i*numQubits+j];
1030
1031 strings[i] = getPauliStr(codes, targs, numQubits);
1032 }
1033
1034 qcomp* coeffs = (qcomp*) malloc(numTerms * sizeof *coeffs);
1035 for (int i=0; i<numTerms; i++)
1036 coeffs[i] = termCoeffs[i];
1037
1038 PauliStrSum sum = createPauliStrSum(strings, coeffs, numTerms);
1039 free(targs);
1040 free(strings);
1041 free(coeffs);
1042
1043 return sum;
1044}
1045
1046static inline qreal _calcExpecPauliSum(Qureg qureg, _NoWarnPauliOpType* allPauliCodes, qreal* termCoeffs, int numTerms) {
1047 PauliStrSum sum = _createPauliStrSumFromCodes(qureg.numQubits, allPauliCodes, termCoeffs, numTerms);
1048 qreal out = calcExpecPauliStrSum(qureg, sum);
1049 destroyPauliStrSum(sum);
1050 return out;
1051}
1052
1053#define calcExpecPauliSum(qureg, paulis, coeffs, numTerms, workspace) \
1054 _WARN_FUNC_RENAMED("calcExpecPauliSum(Qureg, ...)", "calcExpecPauliStrSum(Qureg, PauliStrSum)") \
1055 _calcExpecPauliSum(qureg, paulis, coeffs, numTerms)
1056
1057static inline void _applyPauliSum(Qureg inQureg, _NoWarnPauliOpType* allPauliCodes, qreal* termCoeffs, int numSumTerms, Qureg outQureg) {
1058 PauliStrSum sum = _createPauliStrSumFromCodes(inQureg.numQubits, allPauliCodes, termCoeffs, numSumTerms);
1059 setQuregToClone(outQureg, inQureg);
1060 leftapplyPauliStrSum(outQureg, sum, inQureg);
1061 destroyPauliStrSum(sum);
1062}
1063
1064#define applyPauliSum(...) \
1065 _WARN_FUNC_RENAMED("applyPauliSum(inQureg, ..., outQureg)", "leftapplyPauliStrSum(outQureg, PauliStrSum)") \
1066 _applyPauliSum(__VA_ARGS__)
1067
1068static inline void _applyPauliHamil(Qureg inQureg, PauliStrSum hamil, Qureg outQureg) {
1069 setQuregToClone(outQureg, inQureg);
1070 leftapplyPauliStrSum(outQureg, hamil, inQureg);
1071}
1072
1073#define applyPauliHamil(...) \
1074 _WARN_FUNC_RENAMED("applyPauliHamil(inQureg, PauliHamil, outQureg)", "leftapplyPauliStrSum(qureg, PauliStrSum, workspace)") \
1075 _applyPauliHamil(__VA_ARGS__)
1076
1077
1078
1079#define compactUnitary(q, t, a, b) \
1080 _WARN_FUNC_RENAMED( \
1081 "compactUnitary(qureg, t, a, b)", \
1082 "applyCompMatr1(qureg, t, getInlineCompMatr1({{a,-conj(b)},{b,conj(a)}}))") \
1083 applyCompMatr1(q, t, getInlineCompMatr1({ \
1084 {_GET_QCOMP_FROM_COMPLEX_STRUCT(a), - conj(_GET_QCOMP_FROM_COMPLEX_STRUCT(b))}, \
1085 {_GET_QCOMP_FROM_COMPLEX_STRUCT(b), conj(_GET_QCOMP_FROM_COMPLEX_STRUCT(a))}} ))
1086
1087#define controlledCompactUnitary(q, c, t, a, b) \
1088 _WARN_FUNC_RENAMED( \
1089 "controlledCompactUnitary(qureg, c, t, a, b)", \
1090 "applyControlledCompMatr1(qureg, c, t, getInlineCompMatr1({{a,-conj(b)},{b,conj(a)}}))") \
1091 applyControlledCompMatr1(q, c, t, getInlineCompMatr1({ \
1092 {_GET_QCOMP_FROM_COMPLEX_STRUCT(a), - conj(_GET_QCOMP_FROM_COMPLEX_STRUCT(b))}, \
1093 {_GET_QCOMP_FROM_COMPLEX_STRUCT(b), conj(_GET_QCOMP_FROM_COMPLEX_STRUCT(a))}} ))
1094
1095
1096
1097#define unitary(qureg, targ, ...) \
1098 _WARN_FUNC_RENAMED("unitary()", "applyCompMatr1()") \
1099 applyCompMatr1(qureg, targ, _GET_COMP_MATR_1_FROM_COMPLEX_MATRIX_2(__VA_ARGS__))
1100
1101#define controlledUnitary(qureg, ctrl, targ, ...) \
1102 _WARN_FUNC_RENAMED("controlledUnitary()", "applyControlledCompMatr1()") \
1103 applyControlledCompMatr1(qureg, ctrl, targ, _GET_COMP_MATR_1_FROM_COMPLEX_MATRIX_2(__VA_ARGS__))
1104
1105#define multiControlledUnitary(qureg, ctrls, numctrls, targ, ...) \
1106 _WARN_FUNC_RENAMED("multiControlledUnitary()", "applyMultiControlledCompMatr1()") \
1107 applyMultiControlledCompMatr1(qureg, ctrls, numctrls, targ, _GET_COMP_MATR_1_FROM_COMPLEX_MATRIX_2(__VA_ARGS__))
1108
1109#define multiStateControlledUnitary(qureg, ctrls, states, numctrls, targ, ...) \
1110 _WARN_FUNC_RENAMED("multiStateControlledUnitary()", "applyMultiStateControlledCompMatr1()") \
1111 applyMultiStateControlledCompMatr1(qureg, ctrls, states, numctrls, targ, _GET_COMP_MATR_1_FROM_COMPLEX_MATRIX_2(__VA_ARGS__))
1112
1113#define twoQubitUnitary(qureg, t1, t2, ...) \
1114 _WARN_FUNC_RENAMED("twoQubitUnitary()", "applyCompMatr2()") \
1115 applyCompMatr2(qureg, t1, t2, _GET_COMP_MATR_2_FROM_COMPLEX_MATRIX_4(__VA_ARGS__))
1116
1117#define controlledTwoQubitUnitary(qureg, c, t1, t2, ...) \
1118 _WARN_FUNC_RENAMED("controlledTwoQubitUnitary()", "applyControlledCompMatr2()") \
1119 applyControlledCompMatr2(qureg, c, t1, t2, _GET_COMP_MATR_2_FROM_COMPLEX_MATRIX_4(__VA_ARGS__))
1120
1121#define multiControlledTwoQubitUnitary(qureg, ctrls, nctrls, t1, t2, ...) \
1122 _WARN_FUNC_RENAMED("multiControlledTwoQubitUnitary()", "applyMultiControlledCompMatr2()") \
1123 applyMultiControlledCompMatr2(qureg, ctrls, nctrls, t1, t2, _GET_COMP_MATR_2_FROM_COMPLEX_MATRIX_4(__VA_ARGS__))
1124
1125#define multiQubitUnitary(...) \
1126 _WARN_FUNC_RENAMED("multiQubitUnitary()", "applyCompMatr()") \
1127 applyCompMatr(__VA_ARGS__)
1128
1129#define controlledMultiQubitUnitary(...) \
1130 _WARN_FUNC_RENAMED("controlledMultiQubitUnitary()", "applyControlledCompMatr()") \
1131 applyControlledCompMatr(__VA_ARGS__)
1132
1133#define multiControlledMultiQubitUnitary(...) \
1134 _WARN_FUNC_RENAMED("multiControlledMultiQubitUnitary()", "applyMultiControlledCompMatr()") \
1135 applyMultiControlledCompMatr(__VA_ARGS__)
1136
1137
1138
1139#define applyMatrix2(qureg, targ, ...) \
1140 _WARN_FUNC_RENAMED("applyMatrix2()", "leftapplyCompMatr1()") \
1141 leftapplyCompMatr1(qureg, targ, _GET_COMP_MATR_1_FROM_COMPLEX_MATRIX_2(__VA_ARGS__))
1142
1143#define applyMatrix4(qureg, targ1, targ2, ...) \
1144 _WARN_FUNC_RENAMED("applyMatrix4()", "leftapplyCompMatr2()") \
1145 leftapplyCompMatr2(qureg, targ1, targ2, _GET_COMP_MATR_2_FROM_COMPLEX_MATRIX_4(__VA_ARGS__))
1146
1147#define applyMatrixN(...) \
1148 _WARN_FUNC_RENAMED("applyMatrixN()", "leftapplyCompMatr()") \
1149 leftapplyCompMatr(__VA_ARGS__)
1150
1151
1152
1153static inline void _applyGateMatrixN(Qureg qureg, int* targs, int numTargs, CompMatr u) {
1154 qreal eps = getQuESTValidationEpsilon();
1156 applyCompMatr(qureg, targs, numTargs, u);
1158}
1159
1160#define applyGateMatrixN(...) \
1161 _WARN_GENERAL_MSG( \
1162 "The QuEST function 'applyGateMatrixN()' is deprecated. To achieve the same thing, disable " \
1163 "numerical validation via 'setQuESTValidationEpsilon(0)' before calling 'applyCompMatr()'. You can " \
1164 "save the existing epsilon via 'getQuESTValidationEpsilon()' to thereafter restore. This procedure " \
1165 "has been performed here automatically.") \
1166 _applyGateMatrixN(__VA_ARGS__)
1167
1168static inline void _applyMultiControlledGateMatrixN(Qureg qureg, int* ctrls, int numCtrls, int* targs, int numTargs, CompMatr u) {
1169 qreal eps = getQuESTValidationEpsilon();
1171 applyMultiControlledCompMatr(qureg, ctrls, numCtrls, targs, numTargs, u);
1173}
1174
1175#define applyMultiControlledGateMatrixN(...) \
1176 _WARN_GENERAL_MSG( \
1177 "The QuEST function 'applyMultiControlledGateMatrixN()' is deprecated. To achieve the same thing, disable " \
1178 "numerical validation via 'setQuESTValidationEpsilon(0)' before calling 'applyMultiControlledCompMatr()'. You can " \
1179 "save the existing epsilon via 'getQuESTValidationEpsilon()' to thereafter restore. This procedure has been " \
1180 "performed here automatically.") \
1181 _applyMultiControlledGateMatrixN(__VA_ARGS__)
1182
1183
1184
1185#define pauliX(...) \
1186 _WARN_FUNC_RENAMED("pauliX()", "applyPauliX()") \
1187 applyPauliX(__VA_ARGS__)
1188
1189#define pauliY(...) \
1190 _WARN_FUNC_RENAMED("pauliY()", "applyPauliY()") \
1191 applyPauliY(__VA_ARGS__)
1192
1193#define pauliZ(...) \
1194 _WARN_FUNC_RENAMED("pauliZ()", "applyPauliZ()") \
1195 applyPauliZ(__VA_ARGS__)
1196
1197#define controlledPauliX(...) \
1198 _WARN_FUNC_RENAMED("controlledPauliX()", "applyControlledPauliX()") \
1199 applyControlledPauliX(__VA_ARGS__)
1200
1201#define controlledPauliY(...) \
1202 _WARN_FUNC_RENAMED("controlledPauliY()", "applyControlledPauliY()") \
1203 applyControlledPauliY(__VA_ARGS__)
1204
1205#define controlledPauliZ(...) \
1206 _WARN_FUNC_RENAMED("controlledPauliZ()", "applyControlledPauliZ()") \
1207 applyControlledPauliZ(__VA_ARGS__)
1208
1209
1210
1211#define rotateX(...) \
1212 _WARN_FUNC_RENAMED("rotateX()", "applyRotateX()") \
1213 applyRotateX(__VA_ARGS__)
1214
1215#define rotateY(...) \
1216 _WARN_FUNC_RENAMED("rotateY()", "applyRotateY()") \
1217 applyRotateY(__VA_ARGS__)
1218
1219#define rotateZ(...) \
1220 _WARN_FUNC_RENAMED("rotateZ()", "applyRotateZ()") \
1221 applyRotateZ(__VA_ARGS__)
1222
1223#define rotateAroundAxis(q, t, a, v) \
1224 _WARN_FUNC_RENAMED( \
1225 "rotateAroundAxis(Qureg, int, qreal, Vector)", \
1226 "applyRotateAroundAxis(Qureg, int, qreal, qreal vx, qreal vy, qreal vz)") \
1227 applyRotateAroundAxis(q, t, a, v.x, v.y, v.z)
1228
1229#define controlledRotateX(...) \
1230 _WARN_FUNC_RENAMED("controlledRotateX()", "applyControlledRotateX()") \
1231 applyControlledRotateX(__VA_ARGS__)
1232
1233#define controlledRotateY(...) \
1234 _WARN_FUNC_RENAMED("controlledRotateY()", "applyControlledRotateY()") \
1235 applyControlledRotateY(__VA_ARGS__)
1236
1237#define controlledRotateZ(...) \
1238 _WARN_FUNC_RENAMED("controlledRotateZ()", "applyControlledRotateZ()") \
1239 applyControlledRotateZ(__VA_ARGS__)
1240
1241#define controlledRotateAroundAxis(q, c, t, a, v) \
1242 _WARN_FUNC_RENAMED( \
1243 "controlledRotateAroundAxis(Qureg, int, int, qreal, Vector)", \
1244 "applyControlledRotateAroundAxis(Qureg, int, int, qreal, qreal vx, qreal vy, qreal vz)") \
1245 applyControlledRotateAroundAxis(q, c, t, a, v.x, v.y, v.z)
1246
1247
1248
1249#define hadamard(...) \
1250 _WARN_FUNC_RENAMED("hadamard()", "applyHadamard()") \
1251 applyHadamard(__VA_ARGS__)
1252
1253#define controlledNot(...) \
1254 _WARN_FUNC_RENAMED("controlledNot()", "applyControlledPauliX()") \
1255 applyControlledPauliX(__VA_ARGS__)
1256
1257
1258
1259#define multiRotateZ(...) \
1260 _WARN_FUNC_RENAMED("multiRotateZ()", "applyPhaseGadget()") \
1261 applyPhaseGadget(__VA_ARGS__)
1262
1263#define multiControlledMultiRotateZ(...) \
1264 _WARN_FUNC_RENAMED("multiControlledMultiRotateZ()", "applyMultiControlledPhaseGadget()") \
1265 applyMultiControlledPhaseGadget(__VA_ARGS__)
1266
1267static inline void _multiRotatePauli(Qureg qureg, int* targs, _NoWarnPauliOpType* enums, int numTargs, qreal angle) {
1268 int codes[100];
1269 for (int i=0; i<numTargs && i<100; i++)
1270 codes[i] = enums[i];
1271 applyPauliGadget(qureg, getPauliStr(codes, targs, numTargs), angle);
1272}
1273#define multiRotatePauli(...) \
1274 _WARN_FUNC_RENAMED( \
1275 "multiRotatePauli(qureg, targs, paulis, numTargs, angle)", \
1276 "applyPauliGadget(qureg, getPauliStr(paulis, targs, numTargs), angle)") \
1277 _multiRotatePauli(__VA_ARGS__)
1278
1279static inline void _multiControlledMultiRotatePauli(Qureg qureg, int* ctrls, int numCtrls, int* targs, _NoWarnPauliOpType* enums, int numTargs, qreal angle) {
1280 int codes[100];
1281 for (int i=0; i<numTargs && i<100; i++)
1282 codes[i] = enums[i];
1283 applyMultiControlledPauliGadget(qureg, ctrls, numCtrls, getPauliStr(codes, targs, numTargs), angle);
1284}
1285#define multiControlledMultiRotatePauli(...) \
1286 _WARN_FUNC_RENAMED( \
1287 "multiControlledMultiRotatePauli(qureg, ctrls, numCtrls, targs, paulis, numTargs, angle)", \
1288 "applyMultiControlledPauliGadget(qureg, ctrls, numCtrls, getPauliStr(paulis, targs, numTargs), angle)") \
1289 _multiControlledMultiRotatePauli(__VA_ARGS__)
1290
1291#define multiQubitNot(...) \
1292 _WARN_FUNC_RENAMED("multiQubitNot()", "applyMultiQubitNot()") \
1293 applyMultiQubitNot(__VA_ARGS__)
1294
1295#define multiControlledMultiQubitNot(...) \
1296 _WARN_FUNC_RENAMED("multiControlledMultiQubitNot()", "applyMultiControlledMultiQubitNot()") \
1297 applyMultiControlledMultiQubitNot(__VA_ARGS__)
1298
1299
1300
1301#define collapseToOutcome(...) \
1302 _WARN_FUNC_RENAMED("collapseToOutcome()", "applyForcedQubitMeasurement()") \
1303 applyForcedQubitMeasurement(__VA_ARGS__)
1304
1305#define measure(...) \
1306 _WARN_FUNC_RENAMED("measure()", "applyQubitMeasurement()") \
1307 applyQubitMeasurement(__VA_ARGS__)
1308
1309#define measureWithStats(...) \
1310 _WARN_FUNC_RENAMED("measureWithStats()", "applyQubitMeasurementAndGetProb()") \
1311 applyQubitMeasurementAndGetProb(__VA_ARGS__)
1312
1313#define applyProjector(...) \
1314 _WARN_FUNC_RENAMED("applyProjector()", "applyQubitProjector()") \
1315 applyQubitProjector(__VA_ARGS__)
1316
1317
1318
1319#define mixPauli(...) \
1320 _WARN_FUNC_RENAMED("mixPauli()", "mixPaulis()") \
1321 mixPaulis(__VA_ARGS__)
1322
1323#define mixDensityMatrix(outQureg, prob, inQureg) \
1324 _WARN_FUNC_RENAMED("mixDensityMatrix(outQureg, prob, inQureg)", "mixQureg(outQureg, inQureg, prob)") \
1325 mixQureg(outQureg, inQureg, prob)
1326
1327
1328
1329#define swapGate(...) \
1330 _WARN_FUNC_RENAMED("swapGate()", "applySwap()") \
1331 applySwap(__VA_ARGS__)
1332
1333#define sqrtSwapGate(...) \
1334 _WARN_FUNC_RENAMED("sqrtSwapGate()", "applySqrtSwap()") \
1335 applySqrtSwap(__VA_ARGS__)
1336
1337
1338
1339#define applyTrotterCircuit(...) \
1340 _WARN_FUNC_RENAMED("applyTrotterCircuit(..., PauliHamil, ...)", "applyTrotterizedPauliStrSumGadget(..., PauliStrSum, ...)") \
1341 applyTrotterizedPauliStrSumGadget(__VA_ARGS__)
1342
1343#define applyFullQFT(...) \
1344 _WARN_FUNC_RENAMED("applyFullQFT()", "applyFullQuantumFourierTransform()") \
1345 applyFullQuantumFourierTransform(__VA_ARGS__, false)
1346
1347#define applyQFT(...) \
1348 _WARN_FUNC_RENAMED("applyQFT()", "applyQuantumFourierTransform()") \
1349 applyQuantumFourierTransform(__VA_ARGS__, false)
1350
1351
1352
1353#define seedQuESTDefault(...) \
1354 _WARN_FUNC_RENAMED("seedQuESTDefault(QuESTEnv)", "setQuESTSeedsToDefault()") \
1355 setQuESTSeedsToDefault()
1356
1357#define seedQuEST(env, seeds, numSeeds) \
1358 _WARN_FUNC_RENAMED("seedQuEST(QuESTEnv, unsigned long int*, int)", "setQuESTSeeds(unsigned*, int)") \
1359 setQuESTSeeds(seeds, numSeeds)
1360
1361
1362
1363#endif // DEPRECATED_H
qreal calcExpecPauliStrSum(Qureg qureg, PauliStrSum sum)
qreal calcExpecPauliStr(Qureg qureg, PauliStr str)
KrausMap createKrausMap(int numQubits, int numOperators)
Definition channels.cpp:176
void destroyKrausMap(KrausMap map)
Definition channels.cpp:210
void setKrausMap(KrausMap map, qcomp ***matrices)
Definition channels.cpp:309
qreal getQuESTValidationEpsilon()
Definition debug.cpp:115
void setQuESTValidationEpsilon(qreal eps)
Definition debug.cpp:100
void mixKrausMap(Qureg qureg, int *targets, int numTargets, KrausMap map)
QuESTEnv getQuESTEnv()
void initQuESTEnv()
void setQuregToWeightedSum(Qureg out, qcomp *coeffs, Qureg *in, int numIn)
void setQuregToClone(Qureg outQureg, Qureg inQureg)
void leftapplyPauliStrSum(Qureg qureg, PauliStrSum sum, Qureg workspace)
void applyCompMatr(Qureg qureg, int *targets, int numTargets, CompMatr matrix)
void applyMultiControlledCompMatr(Qureg qureg, int *controls, int numControls, int *targets, int numTargets, CompMatr matrix)
void applyDiagMatr(Qureg qureg, int *targets, int numTargets, DiagMatr matrix)
void applyMultiControlledPauliGadget(Qureg qureg, int *controls, int numControls, PauliStr str, qreal angle)
void applyPauliGadget(Qureg qureg, PauliStr str, qreal angle)
PauliStrSum createPauliStrSum(PauliStr *strings, qcomp *coeffs, qindex numTerms)
Definition paulis.cpp:166
PauliStr getPauliStr(const char *paulis, int *indices, int numPaulis)
Definition paulis.cpp:76
void destroyPauliStrSum(PauliStrSum sum)
Definition paulis.cpp:251
Definition qureg.h:49