Skip to content

Commit

Permalink
fix: fixed exp layer tests and commented amp encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Jul 17, 2024
1 parent 42c0a1b commit 87ea094
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/qiboml/models/encoding_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def forward(self, x: "ndarray") -> Circuit:
return self.circuit


class AmplitudeEncodingLayer(QuantumEncodingLayer):
pass
# class AmplitudeEncodingLayer(QuantumEncodingLayer):
# pass


"""
Expand Down Expand Up @@ -111,7 +111,6 @@ def __post_init__(self):

def forward(self, x: Circuit) -> "ndarray":
if self.nshots is None:
# breakpoint()
return self.observable.expectation(
super().forward(x).state(),
).reshape(1, 1)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_models_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
from qibo import hamiltonians
from qibo.config import raise_error
from qibo.symbols import Z
from qibo.symbols import I, Z

import qiboml.models.ansatze as ans
import qiboml.models.encoding_decoding as ed
Expand Down Expand Up @@ -89,8 +89,12 @@ def test_pytorch_decoding(backend, layer):
)
kwargs = {"backend": backend}
if layer is ed.ExpectationLayer:
identity = I(0)
for i in range(1, nqubits):
identity *= I(i)
observable = hamiltonians.SymbolicHamiltonian(
sum([Z(int(i)) for i in random_subset(nqubits, dim)])
sum([Z(int(i)) * identity for i in random_subset(nqubits, dim)]),
backend=backend,
)
kwargs["observable"] = observable
decoding_layer = layer(nqubits, random_subset(nqubits, dim), **kwargs)
Expand Down

0 comments on commit 87ea094

Please sign in to comment.