Skip to content

Commit

Permalink
added re-init test
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin Strobl <[email protected]>
  • Loading branch information
Melvin Strobl committed Oct 7, 2024
1 parent 1a9b6c9 commit a5e6ac9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from qml_essentials.model import Model
from qml_essentials.ansaetze import Ansaetze, Circuit
import pytest
import numpy as np
import logging
import inspect
import shutil
import os
import hashlib
from typing import Optional
import pennylane as qml
import pennylane.numpy as np

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -207,6 +207,27 @@ def test_initialization() -> None:
)


@pytest.mark.unittest
def test_re_initialization() -> None:
model = Model(
n_qubits=2,
n_layers=1,
circuit_type="Circuit_19",
initialization_domain=[-2 * np.pi, 0],
random_seed=1000,
)

assert model.params.max() <= 0, "Parameters should be in [-2pi, 0]!"

temp_params = model.params.copy()

model.initialize_params(rng=np.random.default_rng(seed=1001))

assert not np.allclose(
model.params, temp_params, atol=1e-3
), "Re-Initialization failed!"


@pytest.mark.smoketest
def test_ansaetze() -> None:
ansatz_cases = Ansaetze.get_available()
Expand Down

0 comments on commit a5e6ac9

Please sign in to comment.