Hello!
When running GBS for molecular vibronic spectra, I would occasionally (~4% of the time) get the following error from numpy:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/strawberryfields/apps/qchem/vibronic.py", line 264, in sample
s = eng.run(gbs, shots=n_samples).samples
File "/usr/local/lib/python3.9/site-packages/strawberryfields/engine.py", line 494, in run
result = super()._run(
File "/usr/local/lib/python3.9/site-packages/strawberryfields/engine.py", line 277, in _run
_, self.samples, self.all_samples = self._run_program(p, **kwargs)
File "/usr/local/lib/python3.9/site-packages/strawberryfields/engine.py", line 349, in _run_program
val = cmd.op.apply(cmd.reg, self.backend, **kwargs)
File "/usr/local/lib/python3.9/site-packages/strawberryfields/ops.py", line 302, in apply
values = super().apply(reg, backend, **kwargs)
File "/usr/local/lib/python3.9/site-packages/strawberryfields/ops.py", line 228, in apply
return self._apply(temp, backend, **kwargs)
File "/usr/local/lib/python3.9/site-packages/strawberryfields/ops.py", line 1134, in _apply
samples = backend.measure_fock(reg, shots=shots, select=self.select, **kwargs)
File "/usr/local/lib/python3.9/site-packages/strawberryfields/backends/gaussianbackend/backend.py", line 239, in measure_fock
samples = hafnian_sample_state(reduced_cov, shots, mean=reduced_mean)
File "/usr/local/lib/python3.9/site-packages/thewalrus/samples.py", line 292, in hafnian_sample_state
return _hafnian_sample(params)
File "/usr/local/lib/python3.9/site-packages/thewalrus/samples.py", line 230, in _hafnian_sample
result = generate_hafnian_sample(
File "/usr/local/lib/python3.9/site-packages/thewalrus/samples.py", line 163, in generate_hafnian_sample
result.append(np.random.choice(a=range(len(probs3)), p=probs3))
File "mtrand.pyx", line 932, in numpy.random.mtrand.RandomState.choice
ValueError: probabilities do not sum to 1
This error seems to also occur somewhere else based on this other thread so I’m not sure if the fix would be the same.
To help you debug the issue, I’d like to attach a test script with data to this thread, but I can’t since I’m a relatively new user. Please let me know how I should share the files.
Thank you!
Andre