Skip to content

Commit

Permalink
feat: analytic as property
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Nov 5, 2024
1 parent 46de4e9 commit 69b8f12
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/qiboml/models/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class QuantumDecoding:
nqubits: int
qubits: list[int] = None
nshots: int = None
analytic: bool = True
backend: Backend = None
_circuit: Circuit = None

Expand All @@ -42,9 +41,17 @@ def set_backend(self, backend):
def output_shape(self):
raise_error(NotImplementedError)

@property
def analytic(self):
if self.nshots is None:
return True
else:
return False


@dataclass
class Probabilities(QuantumDecoding):
# TODO: collapse on ExpectationDecoding if not analytic

def __call__(self, x: Circuit) -> ndarray:
return super().__call__(x).probabilities()
Expand All @@ -53,6 +60,10 @@ def __call__(self, x: Circuit) -> ndarray:
def output_shape(self):
return (1, 2**self.nqubits)

@property
def analytic(self):
return True


@dataclass
class Expectation(QuantumDecoding):
Expand Down Expand Up @@ -100,6 +111,10 @@ def __call__(self, x: Circuit) -> ndarray:
def output_shape(self):
return (2, 1, 2**self.nqubits)

@property
def analytic(self):
return True


@dataclass
class Samples(QuantumDecoding):
Expand All @@ -114,3 +129,7 @@ def forward(self, x: Circuit) -> ndarray:
@property
def output_shape(self):
return (self.nshots, len(self.qubits))

@property
def analytic(self):
return False

0 comments on commit 69b8f12

Please sign in to comment.