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

Function GENERATE_NUM_TARGS

tests/unit/operations.cpp:294–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

292
293template <NumQubitsFlag Ctrls, NumQubitsFlag Targs, ArgsFlag Args>
294int GENERATE_NUM_TARGS(int numQuregQubits) {
295
296 assertNumQubitsFlagsAreValid(zero, Targs);
297 DEMAND( Targs != one || numQuregQubits >= 1 );
298 DEMAND( Targs != two || numQuregQubits >= 2 );
299 DEMAND( numQuregQubits > 0 );
300
301 // single choice if #targs is compile-time set
302 if constexpr (Targs == one)
303 return 1;
304 if constexpr (Targs == two)
305 return 2;
306
307 if constexpr (Targs == any) {
308
309 // we can target all qubits...
310 int maxNumTargs = numQuregQubits;
311
312 // unless we're applying CompMatr in distributed
313 // mode. Technically we can support all targets
314 // if the Qureg is a density matrix or not
315 // distributed, but we safely choose the min here
316 if (Args == compmatr)
317 maxNumTargs = numQuregQubits - getLog2(getQuESTEnv().numNodes);
318
319 // we must also ensure there is space left for a forced ctrl
320 if (Ctrls == one && maxNumTargs == numQuregQubits)
321 maxNumTargs -= 1;
322
323 return GENERATE_COPY( range(1, maxNumTargs+1) );
324 }
325}
326
327template <NumQubitsFlag Ctrls>
328int GENERATE_NUM_CTRLS(int numFreeQubits) {

Callers

nothing calls this directly

Calls 3

getLog2Function · 0.85
getQuESTEnvFunction · 0.85

Tested by

no test coverage detected