error message unclear for initStateFromAmps
Closed this issue · 1 comments
nataliejpg commented
When the number of amplitudes in the lists submitted to the initialisation function initStateFromAmps becomes too long (>24 qubits for QuEST_PREC=2 or >25 for QuEST_PREC=1) the programme crashes with the error message "segmentation fault". It would be helpful to have a warning in the documentation for this or generate an error message when the number of amplitudes exceeds the supported number.
rrmeister commented
Hi Natalie!
I cannot reproduce this on the current version of QuEST. Building the following with QuEST_PREC=2
#include <stdio.h>
#include <stdlib.h>
#include "QuEST.h"
int main (int narg, char *varg[]) {
QuESTEnv env = createQuESTEnv();
int numQb = 25;
printf("allocating memory...\n");
Qureg qubits = createQureg(numQb, env);
long long int numAmps = 1ll << numQb;
qreal* re_amps = malloc(numAmps * sizeof(qreal));
qreal* im_amps = malloc(numAmps * sizeof(qreal));
if (re_amps == NULL || im_amps == NULL) {
printf("out of memory\n");
return 1;
}
printf("allocated memory, randomly generating amplitudes...\n");
for (long long int i = 0; i < numAmps; i++) {
re_amps[i] = rand();
im_amps[i] = rand();
}
printf("setting amplitudes...\n");
initStateFromAmps(qubits, re_amps, im_amps);
printf("successfully set amplitudes\n");
free(re_amps);
free(im_amps);
destroyQureg(qubits, env);
destroyQuESTEnv(env);
return 0;
}
gives me the output
allocating memory...
allocated memory, randomly generating amplitudes...
setting amplitudes...
successfully set amplitudes
Can you post a minimal example to reproduce your issue?