Skip to content

Commit

Permalink
test: test merging encoding_layer and entangle_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
qtzhuang committed Mar 5, 2024
1 parent cc3f7b5 commit cc59cd3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
1 change: 0 additions & 1 deletion quafu/algorithms/templates/basic_entangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def _build(self):
Parameter("theta_%d" % j, np.round(np.random.rand(), 3))
for j in range(repeat * self.num_qubits)
]
print(theta)
for layer in range(repeat):
j = layer * self.num_qubits
for i in range(self.num_qubits):
Expand Down
40 changes: 40 additions & 0 deletions tests/quafu/algorithms/merge_circuits_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# (C) Copyright 2023 Beijing Academy of Quantum Information Sciences
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 numpy as np
from quafu.algorithms import AmplitudeEmbedding, AngleEmbedding
from quafu.algorithms.ansatz import QuantumNeuralNetwork
from quafu.algorithms.templates.basic_entangle import BasicEntangleLayers
from quafu.circuits.quantum_circuit import QuantumCircuit


class TestMergeCircuits:
"""Example of merging circuits"""

def test_merge_circuits(self):
state = np.array([7, 2, 3, 4])
encoding_layer = AmplitudeEmbedding(state=state, num_qubits=2, normalize=True)

# feature = np.array([[6, -12.5], [8, 9.5], [5, 0.5]])
# encoding_layer = AngleEmbedding(features=feature, num_qubits=2, rotation="Y")

weights = np.array([[-0.850, 1.287], [0.871, 0.184]])
entangle_layer = BasicEntangleLayers(weights=weights, num_qubits=2)

# entangle_layer2 = BasicEntangleLayers(num_qubits=2, repeat=3)

circuit = encoding_layer + entangle_layer

qnn = QuantumNeuralNetwork(2, circuit)

qnn.draw_circuit(width=2)

0 comments on commit cc59cd3

Please sign in to comment.