Skip to content

Commit

Permalink
test: enable PSR test in test_models_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Nov 4, 2024
1 parent bd228bc commit a9e2481
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/test_models_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import numpy as np
import pytest
import torch
from qibo import construct_backend, hamiltonians
from qibo import hamiltonians
from qibo.config import raise_error
from qibo.symbols import Z

import qiboml.models.ansatze as ans
import qiboml.models.decoding as dec
import qiboml.models.encoding as enc
from qiboml.operations.differentiation import PSR

torch.set_default_dtype(torch.float64)

Expand Down Expand Up @@ -228,6 +229,10 @@ def test_decoding(backend, frontend, layer, seed, analytic):
pytest.skip("Non pytorch/jax differentiation is not working yet.")
if analytic and not layer is dec.Expectation:
pytest.skip("Unused analytic argument.")
if not analytic and not layer is dec.Expectation:
pytest.skip(
"Expectation layer is the only differentiable decoding when the diffrule is not analytical."
)

set_seed(frontend, seed)

Expand All @@ -251,13 +256,19 @@ def test_decoding(backend, frontend, layer, seed, analytic):
)
kwargs["observable"] = observable
kwargs["analytic"] = analytic
if not analytic:
differentiation_rule = PSR()
else:
differentiation_rule = None
kwargs["nshots"] = None
decoding_layer = layer(nqubits, decoding_qubits, **kwargs)

# if not decoding_layer.analytic:
# pytest.skip("PSR differentiation is not working yet.")

q_model = frontend.QuantumModel(encoding_layer, training_layer, decoding_layer)
q_model = frontend.QuantumModel(
encoding_layer, training_layer, decoding_layer, differentiation_rule
)

data = random_tensor(frontend, (100, dim))
target = prepare_targets(frontend, q_model, data)
Expand Down

0 comments on commit a9e2481

Please sign in to comment.