Skip to content

Commit

Permalink
Merge pull request #5 from qDNA-yonsei/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
israelferrazaraujo authored Dec 2, 2023
2 parents aeb6cab + edce076 commit 128c13c
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 31 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion qdna_lib/ansatz/__init__.py → qdna/ansatz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
ConvU4UpToDiagonal,
PoolDefault,
PoolSimple
)
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from qiskit import QuantumCircuit
from qclib.unitary import unitary as decompose_unitary
from qclib.isometry import decompose as decompose_isometry
from qdna_lib.compression.compressor import Compressor
from qclib.entanglement import schmidt_decomposition, _to_qubits
from qdna.compression.compressor import Compressor

# pylint: disable=maybe-no-member

Expand Down
6 changes: 6 additions & 0 deletions qdna/embedding/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from qdna.embedding.iqp_feature_map import IqpFeatureMap
from qdna.embedding.ae_feature_map import AeFeatureMap

from qdna.embedding.nqe_z_feature_map import NqeZFeatureMap
from qdna.embedding.nqe_zz_feature_map import NqeZZFeatureMap
from qdna.embedding.nqe_iqp_feature_map import NqeIqpFeatureMap
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@

from typing import Sequence, Mapping

import numpy
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.circuit import Parameter, ParameterVector, ParameterExpression

from qiskit.circuit.library import BlueprintCircuit, RYGate

from qdna_lib.embedding.util.state_tree_preparation import state_decomposition
from qdna_lib.embedding.util.angle_tree_preparation import create_angles_tree
from qdna_lib.embedding.util.ucr import ucr

#from qclib.gates.ucr import ucr
from qclib.state_preparation.util.tree_utils import children

from qdna.embedding.util.state_tree_preparation import state_decomposition
from qdna.embedding.util.angle_tree_preparation import create_angles_tree
from qdna.embedding.util.ucr import ucr


class AeFeatureMap(BlueprintCircuit):
"""The AeFeatureMap circuit class.
Expand All @@ -47,7 +46,7 @@ def __init__(
parameter_prefix: str = "x",
name: str | None = "AeFeatureMap"
) -> None:

super().__init__(name=name)

self._num_qubits: int | None = None
Expand Down Expand Up @@ -256,7 +255,7 @@ def num_parameters_settable(self) -> int:
"""

return 2**self.num_qubits


def _build(self) -> None:
"""If not already built, build the circuit."""
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

from typing import Callable, List, Union
from qdna_lib.embedding.nqe_base import NqeBase
from qdna_lib.embedding.iqp_feature_map import IqpFeatureMap
from qdna.embedding.nqe_base import NqeBase
from qdna.embedding.iqp_feature_map import IqpFeatureMap


class NqeIqpFeatureMap(IqpFeatureMap, NqeBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Callable, Optional
import numpy as np
from qiskit.circuit.library import ZFeatureMap
from qdna_lib.embedding.nqe_base import NqeBase
from qdna.embedding.nqe_base import NqeBase


class NqeZFeatureMap(ZFeatureMap, NqeBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Callable, List, Union, Optional
import numpy as np
from qiskit.circuit.library import ZZFeatureMap
from qdna_lib.embedding.nqe_base import NqeBase
from qdna.embedding.nqe_base import NqeBase


class NqeZZFeatureMap(ZZFeatureMap, NqeBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_angles_tree(state_tree):
:param tree: used in the recursive calls
:return: tree with angles that will be used to perform the state preparation
"""

amplitude = state_tree.right.norm / state_tree.norm
angle_y = 2 * amplitude.arcsin()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from dataclasses import dataclass
from qiskit.circuit import ParameterExpression
from qiskit.utils import optionals as _optionals
from sympy import sqrt as _sqrt
import symengine

@dataclass
class Node:
Expand All @@ -42,12 +44,8 @@ def __str__(self):
def _sqrt(self):
"""Square root of a ParameterExpression"""
if _optionals.HAS_SYMENGINE:
import symengine

return self._call(symengine.sqrt)
else:
from sympy import sqrt as _sqrt

return self._call(_sqrt)

def state_decomposition(nqubits, data):
Expand Down Expand Up @@ -90,7 +88,7 @@ def state_decomposition(nqubits, data):
norm = _sqrt(
nodes[k].norm*nodes[k].norm + nodes[k + 1].norm*nodes[k + 1].norm
)

new_nodes.append(
Node(nodes[k].index // 2, nqubits, nodes[k], nodes[k + 1], norm)
)
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions qdna_lib/embedding/__init__.py

This file was deleted.

9 changes: 5 additions & 4 deletions test/compression/test_schmidt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"""

from unittest import TestCase
import numpy as np
import random
import numpy as np
from qiskit import QuantumCircuit
from qdna_lib.compression import SchmidtCompressor
from qiskit.quantum_info import Statevector
from qdna.compression import SchmidtCompressor


# pylint: disable=missing-function-docstring
# pylint: disable=missing-class-docstring
Expand All @@ -34,7 +35,7 @@ def test_exact(self):
state_vector = np.random.rand(2**n_qubits) + np.random.rand(2**n_qubits) * 1j
state_vector = state_vector / np.linalg.norm(state_vector)


partition = random.sample(range(n_qubits), n_qubits//2)
compressor = SchmidtCompressor(state_vector, opt_params={'partition': partition})
decompressor = compressor.inverse()
Expand All @@ -47,7 +48,7 @@ def test_exact(self):
circuit.append(decompressor.definition, list(range(n_qubits)))

state = Statevector(circuit)

self.assertTrue(np.allclose(state_vector, state))

def test_trash(self):
Expand Down
2 changes: 1 addition & 1 deletion test/embedding/test_ae_feature_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from unittest import TestCase
import numpy as np
from qiskit import QuantumCircuit
from qdna_lib.embedding import AeFeatureMap
from qiskit.quantum_info import Statevector
from qdna.embedding import AeFeatureMap

# pylint: disable=missing-function-docstring
# pylint: disable=missing-class-docstring
Expand Down

0 comments on commit 128c13c

Please sign in to comment.