From aeb0025e56773673843b7d0c48640e3ec29de0ce Mon Sep 17 00:00:00 2001 From: israelferrazaraujo Date: Sun, 24 Mar 2024 21:21:53 +0900 Subject: [PATCH] refactoring --- qdna/embedding/__init__.py | 12 ++++----- qdna/embedding/util/__init__.py | 0 qdna/embedding/util/state_tree_preparation.py | 25 +------------------ 3 files changed, 7 insertions(+), 30 deletions(-) create mode 100644 qdna/embedding/util/__init__.py diff --git a/qdna/embedding/__init__.py b/qdna/embedding/__init__.py index 247d4c2..0332722 100644 --- a/qdna/embedding/__init__.py +++ b/qdna/embedding/__init__.py @@ -1,7 +1,7 @@ -from qdna.embedding.iqp_feature_map import IqpFeatureMap -from qdna.embedding.ae_feature_map import AeFeatureMap +from .iqp_feature_map import IqpFeatureMap +from .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 -from qdna.embedding.nqe_ae_feature_map import NqeAeFeatureMap +from .nqe_z_feature_map import NqeZFeatureMap +from .nqe_zz_feature_map import NqeZZFeatureMap +from .nqe_iqp_feature_map import NqeIqpFeatureMap +from .nqe_ae_feature_map import NqeAeFeatureMap diff --git a/qdna/embedding/util/__init__.py b/qdna/embedding/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/qdna/embedding/util/state_tree_preparation.py b/qdna/embedding/util/state_tree_preparation.py index 5e5adbe..57e8838 100644 --- a/qdna/embedding/util/state_tree_preparation.py +++ b/qdna/embedding/util/state_tree_preparation.py @@ -42,16 +42,6 @@ def __str__(self): f"{self.sign*self.norm}" ) -# def _abs(self): -# # SymPy's `Abs` function doesn't work with hybrid optimization backwards. -# """Absolute value of a ParameterExpression""" -# if _optionals.HAS_SYMENGINE: -# import symengine -# return ParameterExpression(self._parameter_symbols, symengine.Abs(self._symbol_expr)) -# else: -# from sympy import Abs as sp_abs -# return ParameterExpression(self._parameter_symbols, sp_abs(self._symbol_expr)) - def _sqrt(self): """Square root of a ParameterExpression""" if _optionals.HAS_SYMENGINE: @@ -60,21 +50,8 @@ def _sqrt(self): return self._call(sp_sqrt) def _sign(self): - # SymPy's `sign` function doesn't work with hybrid optimization backwards. """Sign of a ParameterExpression""" - # if _optionals.HAS_SYMENGINE: - # import symengine - # return ParameterExpression( - # self._parameter_symbols, symengine.sign(self._symbol_expr + 1e-4) - # ) - # else: - # from sympy import sign - # return ParameterExpression( - # self._parameter_symbols, sign(self._symbol_expr + 1e-4) - # ) - - # If self is exactly `-10^-4`, the algorithm is interrupted. - # This is because the `sign` function will return 0, zeroing the norms. + # SymPy's `sign` function doesn't work with hybrid optimization backwards. return self / _sqrt(self*self) def state_decomposition(nqubits, data, normalize=False):