Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a strong validation for qubit allocation batching #1797

Merged
merged 6 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading