Skip to content

cudaqx::tensor fails to allocate large PCMs #379

@kvmto

Description

@kvmto

Summary

The cudaq::qec::generate_random_pcm() function fails with error "xbuffer_storage not resizable" when attempting to create Parity Check Matrices (PCMs) with more than ~50,000 error mechanisms. This appears to be a limitation in the underlying xtensor library used by cudaqx::tensor.

Environment

  • Component: cudaqx::tensor (xtensor implementation)
  • Affected Functions: cudaq::qec::generate_random_pcm() in libs/qec/lib/pcm_utils.cpp
  • Error: std::runtime_error: xbuffer_storage not resizable
  • nvq++ Version: (https://github.com/NVIDIA/cuda-quantum d7f1551f6c9544b6123a4daf11c391fade6ea590)

Reproduction

Test Code

#include "cudaq/qec/pcm_utils.h"
#include <iostream>
#include <random>

int main() {
  std::cout << "Testing PCM generation for different sizes...\n\n";
  
  std::vector<size_t> test_sizes = {1000, 10000, 50000, 100000};
  
  for (size_t num_mechs : test_sizes) {
    std::cout << "Attempting " << num_mechs << " mechanisms... " << std::flush;
    
    try {
      size_t n_rounds = std::max(size_t(1), num_mechs / 100);
      size_t n_errs_per_round = num_mechs / n_rounds;
      size_t n_syndromes_per_round = std::max(size_t(1), n_errs_per_round / 2);
      int weight = 3;
      
      std::mt19937_64 rng(42);
      auto pcm = cudaq::qec::generate_random_pcm(
          n_rounds, n_errs_per_round, n_syndromes_per_round, weight, std::move(rng));
      
      std::cout << " Success! Shape: " << pcm.shape()[0] << "×" << pcm.shape()[1] 
                << " (rows×cols)\n";
    } catch (const std::exception& e) {
      std::cout << " Failed! Error: " << e.what() << "\n";
    }
  }
  
  return 0;
}

Execution Results

$ ./test-pcm-allocation
Testing PCM generation for different sizes...

Attempting 1000 mechanisms...  Success! Shape: 500×1000 (rows×cols)
Attempting 10000 mechanisms...  Success! Shape: 5000×10000 (rows×cols)
Attempting 50000 mechanisms...  Success! Shape: 25000×50000 (rows×cols)
Attempting 100000 mechanisms...  Failed! Error: xbuffer_storage not resizable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions