Skip to content

Commit

Permalink
Add a 'strong' validation for qubit allocation batching to match the …
Browse files Browse the repository at this point in the history
…assumption of the underlying simulator backends (#1797)
  • Loading branch information
1tnguyen committed Jul 25, 2024
1 parent 478e00c commit cd69ac5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions runtime/cudaq/qis/managers/default/DefaultExecutionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,32 @@ class DefaultExecutionManager : public cudaq::BasicExecutionManager {
const void *state,
cudaq::simulation_precision precision) override {
// Here we have qubits in requestedAllocations
// want to allocate and set state
// want to allocate and set state.
// There could be previous 'default' allocations whereby we just cached them
// in requestedAllocations.
// These default allocations need to be dispatched separately.
// FIXME: this assumes no qubit reuse, aka the qubits in targets are the
// last ones to be allocated. This is consistent with the Kronecker product
// assumption in CircuitSimulator.
if (!requestedAllocations.empty() &&
targets.size() != requestedAllocations.size()) {
assert(targets.size() < requestedAllocations.size());
// This assumes no qubit reuse, aka the qubits are allocated in order.
// This is consistent with the Kronecker product assumption in
// CircuitSimulator.
for (std::size_t i = 0; i < requestedAllocations.size() - 1; ++i) {
// Verify this assumption to make sure the simulator set
// the state of appropriate qubits.
const auto &thisAlloc = requestedAllocations[i];
const auto &nextAlloc = requestedAllocations[i + 1];
if (nextAlloc.id != (thisAlloc.id + 1)) {
std::stringstream errorMsg;
errorMsg << "Out of order allocation detected. This is not supported "
"by simulator backends. Qubit allocations: [ ";
for (const auto &alloc : requestedAllocations) {
errorMsg << alloc.id << " ";
}
errorMsg << "]";
throw std::logic_error(errorMsg.str());
}
}
const auto numDefaultAllocs =
requestedAllocations.size() - targets.size();
simulator()->allocateQubits(numDefaultAllocs);
Expand Down

0 comments on commit cd69ac5

Please sign in to comment.