Skip to content

Commit

Permalink
Corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
niccololaurora committed Nov 6, 2024
1 parent bf04905 commit 9f5575c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/qiboml/models/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def compute_output_shape(
):
return self.output_shape

def draw(
self,
):
breakpoint()
print("ciao")

@property
def output_shape(
self,
Expand Down
32 changes: 21 additions & 11 deletions tests/test_models_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ def backprop_test(frontend, model, data, target):
# assert grad < 1e-3


@pytest.mark.parametrize("layer", ENCODING_LAYERS)
def test_draw(backend, frontend, layer):
nqubits = 7
dim = 5
training_layer = ans.ReuploadingCircuit(
nqubits,
random_subset(nqubits, dim),
)
decoding_layer = dec.Probabilities(
nqubits, random_subset(nqubits, dim), backend=backend
)
encoding_layer = layer(nqubits, random_subset(nqubits, dim))

q_model = frontend.QuantumModel(
encoding_layer, training_layer, decoding_layer, differentiation="Jax"
)

q_model.draw()


@pytest.mark.parametrize("layer", ENCODING_LAYERS)
def test_encoding(backend, frontend, layer):
# if frontend.__name__ == "qiboml.models.keras":
Expand All @@ -232,32 +252,25 @@ def test_encoding(backend, frontend, layer):
encoding_layer = layer(nqubits, random_subset(nqubits, dim))
# Ogni frontend costruisce il suo QuantumModel
# Questo è solo una istanza
print("Layers inizializzati")
q_model = frontend.QuantumModel(
encoding_layer, training_layer, decoding_layer, differentiation="Jax"
)
print("Q Model costruito")

binary = True if encoding_layer.__class__.__name__ == "BinaryEncoding" else False

# Vengono generati dei dati: tensore uniforme con la shape (100, dim)
data = random_tensor(frontend, (5, dim), binary)
# Genero i dati target del problema
print("Pre target")
target = prepare_targets(frontend, q_model, data)
print("Post target")

# ============
# Pure QuantumModel
# ============
print("Pure QuantumModel")
backprop_test(frontend, q_model, data, target)

"""
# ============
# Sequential: Hybrid classical and QuantumModel
# ============
print("Sequential")
batch_size = 5
input_size = 32
data = random_tensor(frontend, (batch_size, input_size), binary)
Expand All @@ -273,12 +286,9 @@ def test_encoding(backend, frontend, layer):
input_size,
)

print("Sequential: pre prepare targets")
target = prepare_targets(frontend, model, data)
print("Sequential: post prepare targets")
breakpoint()

backprop_test(frontend, model, data, target)
"""


@pytest.mark.parametrize("layer", DECODING_LAYERS)
Expand Down

0 comments on commit 9f5575c

Please sign in to comment.