Skip to content

Commit

Permalink
Merge pull request #527 from qiboteam/fixcpufall
Browse files Browse the repository at this point in the history
Move CPU fallback for frequencies
  • Loading branch information
scarrazza authored Dec 27, 2021
2 parents 5ebf0d1 + 64b7c55 commit 1207b98
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/qibo/backends/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def cpu_fallback(self, func, *args):
except self.oom_error: # pragma: no cover
# case not covered by GitHub workflows because it requires OOM
# Force using CPU to perform sampling
log.warn("Falling back to CPU because the GPU is out-of-memory.")
log.warn(f"Falling back to CPU for '{func.__name__}' because the GPU is out-of-memory.")
with self.device(self.get_cpu()):
return func(*args)

Expand Down
4 changes: 2 additions & 2 deletions src/qibo/core/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def frequencies(self, binary: bool = True) -> collections.Counter:
measured shots.
"""
if self._frequencies is None:
self._frequencies = K.cpu_fallback(self._calculate_frequencies)
self._frequencies = self._calculate_frequencies()
if binary:
return collections.Counter(
{"{0:b}".format(k).zfill(self.nqubits): v
Expand Down Expand Up @@ -192,7 +192,7 @@ def _calculate_frequencies(self):
raise_error(RuntimeError, "Cannot calculate measurement "
"frequencies without a probability "
"distribution or samples.")
freqs = K.sample_frequencies(self.probabilities, self.nshots)
freqs = K.cpu_fallback(K.sample_frequencies, self.probabilities, self.nshots)
freqs = K.to_numpy(freqs)
return collections.Counter(
{k: v for k, v in enumerate(freqs) if v > 0})
Expand Down

0 comments on commit 1207b98

Please sign in to comment.