Warning when too many qubits are allocated in QuantumSimulator
Please describe what you would like the feature to accomplish.
When allocating too many qubits using QuantumSimulator, the program allocates a lot of memory is blocked for a long time.
Describe the solution you'd like
A warning that too many qubits are allocated to use QuantumSimulator (before the actual memory is allocated), possibly with a suggestion to use SparseSimulator instead.
Describe alternatives you've considered
Noticing that program uses a lot of memory using Activity Monitor and then stop program manually.
Additional context
Here is an example program that just idles and requests more than 100 gb of main and virtual memory.
QDK version: 0.24.201332
macOS 12.3.1 (21E258)
Processor: 2.3 GHz Quad-Core Intel Core i7
Memory: 32 GB 3733 MHz LPDDR4X
Program:
namespace Project {
@EntryPoint()
operation RunProgram() : Unit {
use qs = Qubit[48];
}
}
Running
dotnet run
idles as described above with no warning or error, but
dotnet run -- -s SparseSimulator
terminates successfully immediately.
I've seen this problem causing InteropServices.SEHException on a Windows machine.
A related issue is reported in https://github.com/microsoft/qsharp-compiler/issues/584