MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / validate_matrixAndQuregAreCompatible

Function validate_matrixAndQuregAreCompatible

quest/src/core/validation.cpp:2576–2601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2574void validate_matrixDimMatchesTargets(DiagMatr matr, int numTargs, const char* caller) { assertMatrixDimMatchesTargs(matr, numTargs, caller); }
2575
2576void validate_matrixAndQuregAreCompatible(FullStateDiagMatr matr, Qureg qureg, bool expecOnly, const char* caller) {
2577
2578 // we do not need to define this function for the other matrix types,
2579 // since their validation will happen through validation of the
2580 // user-given list of target qubits. But we do need to define it for
2581 // FullStatedDiagMatr to check both distribution compatibility, and
2582 // that dimensions match. When expecOnly=true, we relax the necessity
2583 // that the distributions match; one or both can be distributed
2584
2585 tokenSubs vars = {
2586 {"${NUM_MATR_QUBITS}", matr.numQubits},
2587 {"${NUM_QUREG_QUBITS}", qureg.numQubits}};
2588
2589 // dimensions must match
2590 assertThat(matr.numQubits == qureg.numQubits, report::FULL_STATE_DIAG_MATR_MISMATCHES_QUREG_DIM, vars, caller);
2591
2592 // when matrix is duplicated on every node, its application is trivial
2593 if (!matr.isDistributed)
2594 return;
2595
2596 // but when it's distributed, so too must be the qureg; the precise reason why is
2597 // specific to whether qureg is a statevector or density matrix, but boils down
2598 // to there being no communication buffers available to broadcast matr
2599 if (!expecOnly)
2600 assertThat(qureg.isDistributed, report::FULL_STATE_DIAG_MATR_IS_DISTRIB_BUT_QUREG_ISNT, caller); // did not pass vars
2601}
2602
2603
2604

Calls 1

assertThatFunction · 0.85

Tested by

no test coverage detected