Skip to content

Commit

Permalink
fix: align tf backend with qibo's one
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Mar 20, 2024
1 parent d2a0a37 commit d019e61
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/qiboml/backends/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import numpy as np

from qibo import __version__
from qibo.backends.npmatrices import NumpyMatrices
from qibo.backends.numpy import NumpyBackend
Expand All @@ -14,7 +13,6 @@ class TensorflowMatrices(NumpyMatrices):

def __init__(self, dtype):
super().__init__(dtype)

import tensorflow as tf # pylint: disable=import-error
import tensorflow.experimental.numpy as tnp # pylint: disable=import-error

Expand Down Expand Up @@ -95,9 +93,6 @@ def to_numpy(self, x):
def compile(self, func):
return self.tf.function(func)

def customize_gradient(self, func):
return self.tf.custom_gradient(func)

def zero_state(self, nqubits):
idx = self.tf.constant([[0]], dtype="int32")
state = self.tf.zeros((2**nqubits,), dtype=self.dtype)
Expand Down Expand Up @@ -203,18 +198,16 @@ def calculate_hamiltonian_state_product(self, matrix, state):
else:
raise_error(
ValueError,
"Cannot multiply Hamiltonian with " "rank-{} tensor.".format(rank),
f"Cannot multiply Hamiltonian with rank-{rank} tensor.",
)

return expectation_with_custom_gradient(params)

def test_regressions(self, name):
if name == "test_measurementresult_apply_bitflips":
return [
[4, 0, 0, 1, 0, 2, 2, 4, 4, 0],
[4, 0, 0, 1, 0, 2, 2, 4, 4, 0],
[4, 0, 0, 1, 0, 0, 0, 4, 4, 0],
[4, 0, 0, 0, 0, 0, 0, 4, 4, 0],
[4, 0, 0, 1, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 2, 1, 1, 4, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 4, 0, 0, 0, 4],
]
elif name == "test_probabilistic_measurement":
if "GPU" in self.device: # pragma: no cover
Expand All @@ -229,6 +222,6 @@ def test_regressions(self, name):
elif name == "test_post_measurement_bitflips_on_circuit":
return [
{5: 30},
{5: 16, 7: 10, 6: 2, 3: 1, 4: 1},
{3: 6, 5: 6, 7: 5, 2: 4, 4: 3, 0: 2, 1: 2, 6: 2},
{5: 12, 7: 6, 4: 6, 1: 5, 6: 1},
{3: 7, 6: 4, 2: 4, 7: 4, 0: 4, 5: 3, 4: 2, 1: 2},
]

0 comments on commit d019e61

Please sign in to comment.