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