Skip to content

Commit

Permalink
test: enable ut without torch
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaoyilunnn committed Jul 22, 2024
1 parent 8af7dd2 commit 0b5035d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 1 addition & 6 deletions tests/quafu/algorithms/ansatz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""TODO: test of ansatz needs improvement once ansatz has more featuers"""

import numpy as np
from quafu.algorithms.ansatz import AlterLayeredAnsatz, QAOAAnsatz, QuantumNeuralNetwork
from quafu.algorithms.ansatz import AlterLayeredAnsatz, QAOAAnsatz
from quafu.algorithms.hamiltonian import Hamiltonian, PauliOp


Expand All @@ -37,8 +37,3 @@ def test_build(self):
circ = AlterLayeredAnsatz(4, 4)
# print("\n ::: testing ::: \n")
# circ.plot_circuit(save_path="TestAlterLayeredAnsatz.svg")


class TestQuantumNeuralNetwork:
def test_build(self):
circ = QuantumNeuralNetwork(2, [])
3 changes: 3 additions & 0 deletions tests/quafu/algorithms/construct_qlayers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest

pytest.importorskip("torch")
import numpy as np
from quafu.algorithms import AmplitudeEmbedding, AngleEmbedding
from quafu.algorithms.ansatz import QuantumNeuralNetwork
Expand Down
3 changes: 3 additions & 0 deletions tests/quafu/algorithms/qnn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
import numpy as np
import pytest

pytest.importorskip("torch")
import torch
from quafu.algorithms.ansatz import QuantumNeuralNetwork
from quafu.algorithms.gradients import compute_vjp, jacobian
Expand Down Expand Up @@ -112,6 +114,7 @@ def forward(self, features):
# yield nn.Parameter(p)


@pytest.importorskip("torch")
class TestLayers:
circ = QuantumCircuit(2)
theta = [Parameter(f"theta_{i}", 0.1) for i in range(3)]
Expand Down

0 comments on commit 0b5035d

Please sign in to comment.