diff --git a/_build/backend.py b/_build/backend.py index c0077bc0a..c2587ed3b 100644 --- a/_build/backend.py +++ b/_build/backend.py @@ -181,17 +181,17 @@ def update_library_path_from_env(ld_path_var, install_prefix): def update_library_path(ld_path_var): """Update XXX_LIBRARY_PATH environment variable.""" logging.info('Updating %s environment variable', ld_path_var) - mq_lib_paths = os.getenv('MQ_LIB_PATHS', '') + quafu_lib_paths = os.getenv('QUAFU_LIB_PATHS', '') try: - update_library_path_from_file(ld_path_var, mq_lib_paths) + update_library_path_from_file(ld_path_var, quafu_lib_paths) return except FileNotFoundError: pass try: prefix = 'build/temp.macosx' - if platform.system() == 'Darwin' and mq_lib_paths.startswith(prefix): - re_match = re.match(r'build/temp\.macosx-([^-]+)-(.*)', mq_lib_paths) + if platform.system() == 'Darwin' and quafu_lib_paths.startswith(prefix): + re_match = re.match(r'build/temp\.macosx-([^-]+)-(.*)', quafu_lib_paths) if re_match: macos_ver = os.getenv('MACOSX_DEPLOYMENT_TARGET', 'NA') suffix = re_match.group(2) @@ -203,11 +203,11 @@ def update_library_path(ld_path_var): pass for install_prefix in ( - 'MQLIBS_CACHE_PATH', + 'QUAFULIBS_CACHE_PATH', 'MSLIBS_CACHE_PATH', - 'MQLIBS_LOCAL_PREFIX_PATH', + 'QUAFULIBS_LOCAL_PREFIX_PATH', 'MSLIBS_LOCAL_PREFIX_PATH', - 'MQ_BUILD_DIR', + 'QUAFU_BUILD_DIR', ): try: update_library_path_from_env(ld_path_var, os.getenv(install_prefix, '')) @@ -227,10 +227,10 @@ def get_requires_for_build_wheel(config_settings=None): requirements = setuptools.build_meta.get_requires_for_build_wheel(config_settings=config_settings) executable_list = ['cmake'] - if int(os.environ.get('MQ_USE_NINJA', False)): + if int(os.environ.get('QUAFU_USE_NINJA', False)): executable_list.append('ninja') - delocate_wheel = int(os.environ.get('MQ_DELOCATE_WHEEL', False)) + delocate_wheel = int(os.environ.get('QUAFU_DELOCATE_WHEEL', False)) if delocate_wheel: if platform.system() == 'Linux': requirements.append('auditwheel') @@ -298,7 +298,7 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): # Delocate the wheel if requested delocated_wheel_directory = Path(wheel_directory, 'delocated') - delocate_wheel = int(os.environ.get('MQ_DELOCATE_WHEEL', False)) + delocate_wheel = int(os.environ.get('QUAFU_DELOCATE_WHEEL', False)) done_delocate = False delocated_wheel = None @@ -309,12 +309,12 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): if platform.system() == 'Darwin': ld_lib_var = 'DYLD_LIBRARY_PATH' elif platform.system() == 'Windows': - ld_lib_var = 'MQ_LIB' # Name of variable intentionally custom + ld_lib_var = 'QUAFU_LIB' # Name of variable intentionally custom update_library_path(ld_lib_var) if platform.system() == 'Linux': done_delocate = True - plat = os.environ.get('MQ_DELOCATE_WHEEL_PLAT', '') + plat = os.environ.get('QUAFU_DELOCATE_WHEEL_PLAT', '') call_auditwheel('show', name_full) if plat: diff --git a/_build/utils.py b/_build/utils.py index 30bdcf29e..f67c80afe 100644 --- a/_build/utils.py +++ b/_build/utils.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Helper functions for building MindQuantum.""" +"""Helper functions for building quafu.""" import contextlib import errno @@ -26,7 +26,7 @@ from operator import itemgetter from pathlib import Path -sys.path.append(str(Path(__file__).parent.parent / 'mindquantum' / 'utils')) +sys.path.append(str(Path(__file__).parent.parent / 'quafu' / 'utils')) from fdopen import ( # noqa: E402 pylint: disable=wrong-import-position,import-error fdopen, ) diff --git a/cmake/mindquantumConfig.cmake.in b/cmake/quafuConfig.cmake.in similarity index 100% rename from cmake/mindquantumConfig.cmake.in rename to cmake/quafuConfig.cmake.in diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.BasicCompilerRule.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.BasicCompilerRule.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.BasicCompilerRule.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.BasicCompilerRule.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.BasicDecompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.BasicDecompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.BasicDecompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.BasicDecompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.CXToCZ.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.CXToCZ.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.CXToCZ.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.CXToCZ.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.CZBasedChipCompiler.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.CZBasedChipCompiler.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.CZBasedChipCompiler.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.CZBasedChipCompiler.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.CZToCX.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.CZToCX.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.CZToCX.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.CZToCX.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.DAGCircuit.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.DAGCircuit.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.DAGCircuit.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.DAGCircuit.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.DAGNode.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.DAGNode.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.DAGNode.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.DAGNode.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.DAGQubitNode.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.DAGQubitNode.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.DAGQubitNode.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.DAGQubitNode.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.FullyNeighborCanceler.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.FullyNeighborCanceler.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.FullyNeighborCanceler.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.FullyNeighborCanceler.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.GateNode.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.GateNode.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.GateNode.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.GateNode.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.GateReplacer.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.GateReplacer.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.GateReplacer.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.GateReplacer.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.KroneckerSeqCompiler.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.KroneckerSeqCompiler.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.KroneckerSeqCompiler.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.KroneckerSeqCompiler.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.SequentialCompiler.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.SequentialCompiler.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.SequentialCompiler.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.SequentialCompiler.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.SimpleNeighborCanceler.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.SimpleNeighborCanceler.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.SimpleNeighborCanceler.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.SimpleNeighborCanceler.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.abc_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.abc_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.abc_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.abc_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ccx_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ccx_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ccx_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ccx_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ch_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ch_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ch_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ch_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cnry_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cnry_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cnry_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cnry_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cnrz_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cnrz_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cnrz_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cnrz_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.compile_circuit.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.compile_circuit.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.compile_circuit.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.compile_circuit.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.connect_two_node.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.connect_two_node.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.connect_two_node.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.connect_two_node.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.crx_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.crx_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.crx_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.crx_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.crxx_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.crxx_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.crxx_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.crxx_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cry_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cry_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cry_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cry_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cryy_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cryy_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cryy_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cryy_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.crz_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.crz_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.crz_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.crz_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cs_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cs_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cs_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cs_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cswap_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cswap_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cswap_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cswap_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ct_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ct_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ct_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ct_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cu_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cu_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cu_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cu_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cy_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cy_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cy_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cy_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cz_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cz_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.cz_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.cz_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.euler_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.euler_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.euler_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.euler_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.kak_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.kak_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.kak_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.kak_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.qs_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.qs_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.qs_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.qs_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.rxx_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.rxx_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.rxx_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.rxx_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ryy_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ryy_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.ryy_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.ryy_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.rzz_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.rzz_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.rzz_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.rzz_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.swap_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.swap_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.swap_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.swap_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.tensor_product_decompose.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.tensor_product_decompose.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.tensor_product_decompose.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.tensor_product_decompose.rst diff --git a/docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.try_merge.rst b/docs/api_python/algorithm/compiler/quafu.algorithm.compiler.try_merge.rst similarity index 100% rename from docs/api_python/algorithm/compiler/mindquantum.algorithm.compiler.try_merge.rst rename to docs/api_python/algorithm/compiler/quafu.algorithm.compiler.try_merge.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.fold_at_random.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.fold_at_random.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.fold_at_random.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.fold_at_random.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.generate_double_qubits_rb_circ.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.generate_double_qubits_rb_circ.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.generate_double_qubits_rb_circ.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.generate_double_qubits_rb_circ.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.generate_single_qubit_rb_circ.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.generate_single_qubit_rb_circ.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.generate_single_qubit_rb_circ.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.generate_single_qubit_rb_circ.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.query_double_qubits_clifford_elem.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.query_double_qubits_clifford_elem.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.query_double_qubits_clifford_elem.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.query_double_qubits_clifford_elem.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.query_single_qubit_clifford_elem.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.query_single_qubit_clifford_elem.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.query_single_qubit_clifford_elem.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.query_single_qubit_clifford_elem.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.virtual_distillation.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.virtual_distillation.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.virtual_distillation.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.virtual_distillation.rst diff --git a/docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.zne.rst b/docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.zne.rst similarity index 100% rename from docs/api_python/algorithm/error_mitigation/mindquantum.algorithm.error_mitigation.zne.rst rename to docs/api_python/algorithm/error_mitigation/quafu.algorithm.error_mitigation.zne.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.amplitude_encoder.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.amplitude_encoder.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.amplitude_encoder.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.amplitude_encoder.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.bitphaseflip_operator.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.bitphaseflip_operator.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.bitphaseflip_operator.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.bitphaseflip_operator.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.general_ghz_state.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.general_ghz_state.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.general_ghz_state.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.general_ghz_state.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.general_w_state.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.general_w_state.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.general_w_state.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.general_w_state.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.mat_to_op.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.mat_to_op.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.mat_to_op.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.mat_to_op.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.qft.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.qft.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.qft.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.qft.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.qjpeg.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.qjpeg.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.qjpeg.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.qjpeg.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.qudit_symmetric_decoding.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.qudit_symmetric_decoding.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.qudit_symmetric_decoding.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.qudit_symmetric_decoding.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.qudit_symmetric_encoding.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.qudit_symmetric_encoding.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.qudit_symmetric_encoding.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.qudit_symmetric_encoding.rst diff --git a/docs/api_python/algorithm/library/mindquantum.algorithm.library.qutrit_symmetric_ansatz.rst b/docs/api_python/algorithm/library/quafu.algorithm.library.qutrit_symmetric_ansatz.rst similarity index 100% rename from docs/api_python/algorithm/library/mindquantum.algorithm.library.qutrit_symmetric_ansatz.rst rename to docs/api_python/algorithm/library/quafu.algorithm.library.qutrit_symmetric_ansatz.rst diff --git a/docs/api_python/algorithm/mapping/mindquantum.algorithm.mapping.MQSABRE.rst b/docs/api_python/algorithm/mapping/quafu.algorithm.mapping.MQSABRE.rst similarity index 100% rename from docs/api_python/algorithm/mapping/mindquantum.algorithm.mapping.MQSABRE.rst rename to docs/api_python/algorithm/mapping/quafu.algorithm.mapping.MQSABRE.rst diff --git a/docs/api_python/algorithm/mapping/mindquantum.algorithm.mapping.SABRE.rst b/docs/api_python/algorithm/mapping/quafu.algorithm.mapping.SABRE.rst similarity index 100% rename from docs/api_python/algorithm/mapping/mindquantum.algorithm.mapping.SABRE.rst rename to docs/api_python/algorithm/mapping/quafu.algorithm.mapping.SABRE.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.ASWAP.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.ASWAP.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.ASWAP.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.ASWAP.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz1.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz1.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz1.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz1.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz10.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz10.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz10.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz10.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz11.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz11.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz11.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz11.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz12.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz12.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz12.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz12.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz13.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz13.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz13.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz13.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz14.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz14.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz14.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz14.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz15.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz15.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz15.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz15.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz16.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz16.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz16.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz16.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz17.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz17.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz17.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz17.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz18.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz18.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz18.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz18.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz19.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz19.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz19.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz19.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz2.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz2.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz2.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz2.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz3.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz3.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz3.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz3.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz4.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz4.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz4.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz4.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz5.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz5.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz5.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz5.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz6.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz6.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz6.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz6.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz7.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz7.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz7.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz7.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz8.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz8.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz8.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz8.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz9.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz9.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz9.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Ansatz9.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.HardwareEfficientAnsatz.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.HardwareEfficientAnsatz.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.HardwareEfficientAnsatz.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.HardwareEfficientAnsatz.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.IQPEncoding.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.IQPEncoding.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.IQPEncoding.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.IQPEncoding.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Max2SATAnsatz.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Max2SATAnsatz.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Max2SATAnsatz.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Max2SATAnsatz.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.MaxCutAnsatz.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.MaxCutAnsatz.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.MaxCutAnsatz.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.MaxCutAnsatz.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ1F.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ1F.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ1F.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ1F.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ2F.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ2F.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ2F.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ2F.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.QuantumNeuron.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.QuantumNeuron.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.QuantumNeuron.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.QuantumNeuron.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.QubitUCCAnsatz.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.QubitUCCAnsatz.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.QubitUCCAnsatz.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.QubitUCCAnsatz.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYCascade.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYCascade.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYCascade.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYCascade.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYFull.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYFull.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYFull.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYFull.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYLinear.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYLinear.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYLinear.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYLinear.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYRZFull.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYRZFull.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.RYRZFull.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.RYRZFull.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.StronglyEntangling.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.StronglyEntangling.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.StronglyEntangling.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.StronglyEntangling.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Transform.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Transform.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.Transform.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.Transform.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.UCCAnsatz.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.UCCAnsatz.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.UCCAnsatz.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.UCCAnsatz.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.ansatz_variance.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.ansatz_variance.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.ansatz_variance.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.ansatz_variance.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.generate_uccsd.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.generate_uccsd.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.generate_uccsd.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.generate_uccsd.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.get_qubit_hamiltonian.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.get_qubit_hamiltonian.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.get_qubit_hamiltonian.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.get_qubit_hamiltonian.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.get_reference_circuit.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.get_reference_circuit.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.get_reference_circuit.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.get_reference_circuit.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.quccsd_generator.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.quccsd_generator.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.quccsd_generator.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.quccsd_generator.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.uccsd0_singlet_generator.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.uccsd0_singlet_generator.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.uccsd0_singlet_generator.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.uccsd0_singlet_generator.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.uccsd_singlet_generator.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.uccsd_singlet_generator.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.uccsd_singlet_generator.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.uccsd_singlet_generator.rst diff --git a/docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.uccsd_singlet_get_packed_amplitudes.rst b/docs/api_python/algorithm/nisq/quafu.algorithm.nisq.uccsd_singlet_get_packed_amplitudes.rst similarity index 100% rename from docs/api_python/algorithm/nisq/mindquantum.algorithm.nisq.uccsd_singlet_get_packed_amplitudes.rst rename to docs/api_python/algorithm/nisq/quafu.algorithm.nisq.uccsd_singlet_get_packed_amplitudes.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.ASB.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.ASB.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.ASB.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.ASB.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.BSB.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.BSB.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.BSB.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.BSB.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.CAC.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.CAC.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.CAC.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.CAC.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.CFC.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.CFC.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.CFC.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.CFC.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.DSB.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.DSB.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.DSB.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.DSB.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.LQA.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.LQA.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.LQA.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.LQA.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.NMFA.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.NMFA.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.NMFA.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.NMFA.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.QAIA.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.QAIA.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.QAIA.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.QAIA.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.SFC.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.SFC.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.SFC.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.SFC.rst diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.SimCIM.rst b/docs/api_python/algorithm/qaia/quafu.algorithm.qaia.SimCIM.rst similarity index 100% rename from docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.SimCIM.rst rename to docs/api_python/algorithm/qaia/quafu.algorithm.qaia.SimCIM.rst diff --git a/docs/api_python/algorithm/mindquantum.algorithm.compiler.rst b/docs/api_python/algorithm/quafu.algorithm.compiler.rst similarity index 100% rename from docs/api_python/algorithm/mindquantum.algorithm.compiler.rst rename to docs/api_python/algorithm/quafu.algorithm.compiler.rst diff --git a/docs/api_python/algorithm/mindquantum.algorithm.error_mitigation.rst b/docs/api_python/algorithm/quafu.algorithm.error_mitigation.rst similarity index 100% rename from docs/api_python/algorithm/mindquantum.algorithm.error_mitigation.rst rename to docs/api_python/algorithm/quafu.algorithm.error_mitigation.rst diff --git a/docs/api_python/algorithm/mindquantum.algorithm.library.rst b/docs/api_python/algorithm/quafu.algorithm.library.rst similarity index 100% rename from docs/api_python/algorithm/mindquantum.algorithm.library.rst rename to docs/api_python/algorithm/quafu.algorithm.library.rst diff --git a/docs/api_python/algorithm/mindquantum.algorithm.mapping.rst b/docs/api_python/algorithm/quafu.algorithm.mapping.rst similarity index 100% rename from docs/api_python/algorithm/mindquantum.algorithm.mapping.rst rename to docs/api_python/algorithm/quafu.algorithm.mapping.rst diff --git a/docs/api_python/algorithm/mindquantum.algorithm.nisq.rst b/docs/api_python/algorithm/quafu.algorithm.nisq.rst similarity index 100% rename from docs/api_python/algorithm/mindquantum.algorithm.nisq.rst rename to docs/api_python/algorithm/quafu.algorithm.nisq.rst diff --git a/docs/api_python/algorithm/mindquantum.algorithm.qaia.rst b/docs/api_python/algorithm/quafu.algorithm.qaia.rst similarity index 100% rename from docs/api_python/algorithm/mindquantum.algorithm.qaia.rst rename to docs/api_python/algorithm/quafu.algorithm.qaia.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.BitFlipAdder.rst b/docs/api_python/core/circuit/quafu.core.circuit.BitFlipAdder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.BitFlipAdder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.BitFlipAdder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.ChannelAdderBase.rst b/docs/api_python/core/circuit/quafu.core.circuit.ChannelAdderBase.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.ChannelAdderBase.rst rename to docs/api_python/core/circuit/quafu.core.circuit.ChannelAdderBase.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.Circuit.rst b/docs/api_python/core/circuit/quafu.core.circuit.Circuit.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.Circuit.rst rename to docs/api_python/core/circuit/quafu.core.circuit.Circuit.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.DepolarizingChannelAdder.rst b/docs/api_python/core/circuit/quafu.core.circuit.DepolarizingChannelAdder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.DepolarizingChannelAdder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.DepolarizingChannelAdder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.GateSelector.rst b/docs/api_python/core/circuit/quafu.core.circuit.GateSelector.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.GateSelector.rst rename to docs/api_python/core/circuit/quafu.core.circuit.GateSelector.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.MeasureAccepter.rst b/docs/api_python/core/circuit/quafu.core.circuit.MeasureAccepter.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.MeasureAccepter.rst rename to docs/api_python/core/circuit/quafu.core.circuit.MeasureAccepter.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.MixerAdder.rst b/docs/api_python/core/circuit/quafu.core.circuit.MixerAdder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.MixerAdder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.MixerAdder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.NoiseChannelAdder.rst b/docs/api_python/core/circuit/quafu.core.circuit.NoiseChannelAdder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.NoiseChannelAdder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.NoiseChannelAdder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.NoiseExcluder.rst b/docs/api_python/core/circuit/quafu.core.circuit.NoiseExcluder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.NoiseExcluder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.NoiseExcluder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.QubitIDConstrain.rst b/docs/api_python/core/circuit/quafu.core.circuit.QubitIDConstrain.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.QubitIDConstrain.rst rename to docs/api_python/core/circuit/quafu.core.circuit.QubitIDConstrain.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.QubitNumberConstrain.rst b/docs/api_python/core/circuit/quafu.core.circuit.QubitNumberConstrain.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.QubitNumberConstrain.rst rename to docs/api_python/core/circuit/quafu.core.circuit.QubitNumberConstrain.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.ReverseAdder.rst b/docs/api_python/core/circuit/quafu.core.circuit.ReverseAdder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.ReverseAdder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.ReverseAdder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.SequentialAdder.rst b/docs/api_python/core/circuit/quafu.core.circuit.SequentialAdder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.SequentialAdder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.SequentialAdder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.SwapParts.rst b/docs/api_python/core/circuit/quafu.core.circuit.SwapParts.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.SwapParts.rst rename to docs/api_python/core/circuit/quafu.core.circuit.SwapParts.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.UN.rst b/docs/api_python/core/circuit/quafu.core.circuit.UN.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.UN.rst rename to docs/api_python/core/circuit/quafu.core.circuit.UN.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.add_prefix.rst b/docs/api_python/core/circuit/quafu.core.circuit.add_prefix.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.add_prefix.rst rename to docs/api_python/core/circuit/quafu.core.circuit.add_prefix.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.add_suffix.rst b/docs/api_python/core/circuit/quafu.core.circuit.add_suffix.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.add_suffix.rst rename to docs/api_python/core/circuit/quafu.core.circuit.add_suffix.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.apply.rst b/docs/api_python/core/circuit/quafu.core.circuit.apply.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.apply.rst rename to docs/api_python/core/circuit/quafu.core.circuit.apply.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.as_ansatz.rst b/docs/api_python/core/circuit/quafu.core.circuit.as_ansatz.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.as_ansatz.rst rename to docs/api_python/core/circuit/quafu.core.circuit.as_ansatz.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.as_encoder.rst b/docs/api_python/core/circuit/quafu.core.circuit.as_encoder.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.as_encoder.rst rename to docs/api_python/core/circuit/quafu.core.circuit.as_encoder.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.change_param_name.rst b/docs/api_python/core/circuit/quafu.core.circuit.change_param_name.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.change_param_name.rst rename to docs/api_python/core/circuit/quafu.core.circuit.change_param_name.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.controlled.rst b/docs/api_python/core/circuit/quafu.core.circuit.controlled.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.controlled.rst rename to docs/api_python/core/circuit/quafu.core.circuit.controlled.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.dagger.rst b/docs/api_python/core/circuit/quafu.core.circuit.dagger.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.dagger.rst rename to docs/api_python/core/circuit/quafu.core.circuit.dagger.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.decompose_single_term_time_evolution.rst b/docs/api_python/core/circuit/quafu.core.circuit.decompose_single_term_time_evolution.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.decompose_single_term_time_evolution.rst rename to docs/api_python/core/circuit/quafu.core.circuit.decompose_single_term_time_evolution.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.partial_psi_partial_psi.rst b/docs/api_python/core/circuit/quafu.core.circuit.partial_psi_partial_psi.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.partial_psi_partial_psi.rst rename to docs/api_python/core/circuit/quafu.core.circuit.partial_psi_partial_psi.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.partial_psi_psi.rst b/docs/api_python/core/circuit/quafu.core.circuit.partial_psi_psi.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.partial_psi_psi.rst rename to docs/api_python/core/circuit/quafu.core.circuit.partial_psi_psi.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.pauli_word_to_circuits.rst b/docs/api_python/core/circuit/quafu.core.circuit.pauli_word_to_circuits.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.pauli_word_to_circuits.rst rename to docs/api_python/core/circuit/quafu.core.circuit.pauli_word_to_circuits.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.qfi.rst b/docs/api_python/core/circuit/quafu.core.circuit.qfi.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.qfi.rst rename to docs/api_python/core/circuit/quafu.core.circuit.qfi.rst diff --git a/docs/api_python/core/circuit/mindquantum.core.circuit.shift.rst b/docs/api_python/core/circuit/quafu.core.circuit.shift.rst similarity index 100% rename from docs/api_python/core/circuit/mindquantum.core.circuit.shift.rst rename to docs/api_python/core/circuit/quafu.core.circuit.shift.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.AmplitudeDampingChannel.rst b/docs/api_python/core/gates/quafu.core.gates.AmplitudeDampingChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.AmplitudeDampingChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.AmplitudeDampingChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.BarrierGate.rst b/docs/api_python/core/gates/quafu.core.gates.BarrierGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.BarrierGate.rst rename to docs/api_python/core/gates/quafu.core.gates.BarrierGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.BasicGate.rst b/docs/api_python/core/gates/quafu.core.gates.BasicGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.BasicGate.rst rename to docs/api_python/core/gates/quafu.core.gates.BasicGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.BitFlipChannel.rst b/docs/api_python/core/gates/quafu.core.gates.BitFlipChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.BitFlipChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.BitFlipChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.BitPhaseFlipChannel.rst b/docs/api_python/core/gates/quafu.core.gates.BitPhaseFlipChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.BitPhaseFlipChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.BitPhaseFlipChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.CNOTGate.rst b/docs/api_python/core/gates/quafu.core.gates.CNOTGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.CNOTGate.rst rename to docs/api_python/core/gates/quafu.core.gates.CNOTGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.DepolarizingChannel.rst b/docs/api_python/core/gates/quafu.core.gates.DepolarizingChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.DepolarizingChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.DepolarizingChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.FSim.rst b/docs/api_python/core/gates/quafu.core.gates.FSim.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.FSim.rst rename to docs/api_python/core/gates/quafu.core.gates.FSim.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Givens.rst b/docs/api_python/core/gates/quafu.core.gates.Givens.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Givens.rst rename to docs/api_python/core/gates/quafu.core.gates.Givens.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.GlobalPhase.rst b/docs/api_python/core/gates/quafu.core.gates.GlobalPhase.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.GlobalPhase.rst rename to docs/api_python/core/gates/quafu.core.gates.GlobalPhase.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.GroupedPauli.rst b/docs/api_python/core/gates/quafu.core.gates.GroupedPauli.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.GroupedPauli.rst rename to docs/api_python/core/gates/quafu.core.gates.GroupedPauli.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.GroupedPauliChannel.rst b/docs/api_python/core/gates/quafu.core.gates.GroupedPauliChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.GroupedPauliChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.GroupedPauliChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.HGate.rst b/docs/api_python/core/gates/quafu.core.gates.HGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.HGate.rst rename to docs/api_python/core/gates/quafu.core.gates.HGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.IGate.rst b/docs/api_python/core/gates/quafu.core.gates.IGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.IGate.rst rename to docs/api_python/core/gates/quafu.core.gates.IGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.ISWAPGate.rst b/docs/api_python/core/gates/quafu.core.gates.ISWAPGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.ISWAPGate.rst rename to docs/api_python/core/gates/quafu.core.gates.ISWAPGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.KrausChannel.rst b/docs/api_python/core/gates/quafu.core.gates.KrausChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.KrausChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.KrausChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Measure.rst b/docs/api_python/core/gates/quafu.core.gates.Measure.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Measure.rst rename to docs/api_python/core/gates/quafu.core.gates.Measure.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.MeasureResult.rst b/docs/api_python/core/gates/quafu.core.gates.MeasureResult.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.MeasureResult.rst rename to docs/api_python/core/gates/quafu.core.gates.MeasureResult.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.NoiseGate.rst b/docs/api_python/core/gates/quafu.core.gates.NoiseGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.NoiseGate.rst rename to docs/api_python/core/gates/quafu.core.gates.NoiseGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.NoneParameterGate.rst b/docs/api_python/core/gates/quafu.core.gates.NoneParameterGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.NoneParameterGate.rst rename to docs/api_python/core/gates/quafu.core.gates.NoneParameterGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.ParameterGate.rst b/docs/api_python/core/gates/quafu.core.gates.ParameterGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.ParameterGate.rst rename to docs/api_python/core/gates/quafu.core.gates.ParameterGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.PauliChannel.rst b/docs/api_python/core/gates/quafu.core.gates.PauliChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.PauliChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.PauliChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.PhaseDampingChannel.rst b/docs/api_python/core/gates/quafu.core.gates.PhaseDampingChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.PhaseDampingChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.PhaseDampingChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.PhaseFlipChannel.rst b/docs/api_python/core/gates/quafu.core.gates.PhaseFlipChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.PhaseFlipChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.PhaseFlipChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.PhaseShift.rst b/docs/api_python/core/gates/quafu.core.gates.PhaseShift.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.PhaseShift.rst rename to docs/api_python/core/gates/quafu.core.gates.PhaseShift.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Power.rst b/docs/api_python/core/gates/quafu.core.gates.Power.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Power.rst rename to docs/api_python/core/gates/quafu.core.gates.Power.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.QuantumGate.rst b/docs/api_python/core/gates/quafu.core.gates.QuantumGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.QuantumGate.rst rename to docs/api_python/core/gates/quafu.core.gates.QuantumGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.RX.rst b/docs/api_python/core/gates/quafu.core.gates.RX.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.RX.rst rename to docs/api_python/core/gates/quafu.core.gates.RX.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.RY.rst b/docs/api_python/core/gates/quafu.core.gates.RY.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.RY.rst rename to docs/api_python/core/gates/quafu.core.gates.RY.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.RZ.rst b/docs/api_python/core/gates/quafu.core.gates.RZ.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.RZ.rst rename to docs/api_python/core/gates/quafu.core.gates.RZ.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Rn.rst b/docs/api_python/core/gates/quafu.core.gates.Rn.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Rn.rst rename to docs/api_python/core/gates/quafu.core.gates.Rn.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.RotPauliString.rst b/docs/api_python/core/gates/quafu.core.gates.RotPauliString.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.RotPauliString.rst rename to docs/api_python/core/gates/quafu.core.gates.RotPauliString.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Rxx.rst b/docs/api_python/core/gates/quafu.core.gates.Rxx.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Rxx.rst rename to docs/api_python/core/gates/quafu.core.gates.Rxx.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Rxy.rst b/docs/api_python/core/gates/quafu.core.gates.Rxy.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Rxy.rst rename to docs/api_python/core/gates/quafu.core.gates.Rxy.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Rxz.rst b/docs/api_python/core/gates/quafu.core.gates.Rxz.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Rxz.rst rename to docs/api_python/core/gates/quafu.core.gates.Rxz.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Ryy.rst b/docs/api_python/core/gates/quafu.core.gates.Ryy.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Ryy.rst rename to docs/api_python/core/gates/quafu.core.gates.Ryy.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Ryz.rst b/docs/api_python/core/gates/quafu.core.gates.Ryz.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Ryz.rst rename to docs/api_python/core/gates/quafu.core.gates.Ryz.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.Rzz.rst b/docs/api_python/core/gates/quafu.core.gates.Rzz.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.Rzz.rst rename to docs/api_python/core/gates/quafu.core.gates.Rzz.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.SGate.rst b/docs/api_python/core/gates/quafu.core.gates.SGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.SGate.rst rename to docs/api_python/core/gates/quafu.core.gates.SGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.SWAPGate.rst b/docs/api_python/core/gates/quafu.core.gates.SWAPGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.SWAPGate.rst rename to docs/api_python/core/gates/quafu.core.gates.SWAPGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.SWAPalpha.rst b/docs/api_python/core/gates/quafu.core.gates.SWAPalpha.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.SWAPalpha.rst rename to docs/api_python/core/gates/quafu.core.gates.SWAPalpha.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.SXGate.rst b/docs/api_python/core/gates/quafu.core.gates.SXGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.SXGate.rst rename to docs/api_python/core/gates/quafu.core.gates.SXGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.TGate.rst b/docs/api_python/core/gates/quafu.core.gates.TGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.TGate.rst rename to docs/api_python/core/gates/quafu.core.gates.TGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.ThermalRelaxationChannel.rst b/docs/api_python/core/gates/quafu.core.gates.ThermalRelaxationChannel.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.ThermalRelaxationChannel.rst rename to docs/api_python/core/gates/quafu.core.gates.ThermalRelaxationChannel.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.U3.rst b/docs/api_python/core/gates/quafu.core.gates.U3.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.U3.rst rename to docs/api_python/core/gates/quafu.core.gates.U3.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.UnivMathGate.rst b/docs/api_python/core/gates/quafu.core.gates.UnivMathGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.UnivMathGate.rst rename to docs/api_python/core/gates/quafu.core.gates.UnivMathGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.XGate.rst b/docs/api_python/core/gates/quafu.core.gates.XGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.XGate.rst rename to docs/api_python/core/gates/quafu.core.gates.XGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.YGate.rst b/docs/api_python/core/gates/quafu.core.gates.YGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.YGate.rst rename to docs/api_python/core/gates/quafu.core.gates.YGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.ZGate.rst b/docs/api_python/core/gates/quafu.core.gates.ZGate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.ZGate.rst rename to docs/api_python/core/gates/quafu.core.gates.ZGate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.gene_univ_parameterized_gate.rst b/docs/api_python/core/gates/quafu.core.gates.gene_univ_parameterized_gate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.gene_univ_parameterized_gate.rst rename to docs/api_python/core/gates/quafu.core.gates.gene_univ_parameterized_gate.rst diff --git a/docs/api_python/core/gates/mindquantum.core.gates.gene_univ_two_params_gate.rst b/docs/api_python/core/gates/quafu.core.gates.gene_univ_two_params_gate.rst similarity index 100% rename from docs/api_python/core/gates/mindquantum.core.gates.gene_univ_two_params_gate.rst rename to docs/api_python/core/gates/quafu.core.gates.gene_univ_two_params_gate.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.FermionOperator.rst b/docs/api_python/core/operators/quafu.core.operators.FermionOperator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.FermionOperator.rst rename to docs/api_python/core/operators/quafu.core.operators.FermionOperator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.Hamiltonian.rst b/docs/api_python/core/operators/quafu.core.operators.Hamiltonian.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.Hamiltonian.rst rename to docs/api_python/core/operators/quafu.core.operators.Hamiltonian.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.InteractionOperator.rst b/docs/api_python/core/operators/quafu.core.operators.InteractionOperator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.InteractionOperator.rst rename to docs/api_python/core/operators/quafu.core.operators.InteractionOperator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.PolynomialTensor.rst b/docs/api_python/core/operators/quafu.core.operators.PolynomialTensor.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.PolynomialTensor.rst rename to docs/api_python/core/operators/quafu.core.operators.PolynomialTensor.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.Projector.rst b/docs/api_python/core/operators/quafu.core.operators.Projector.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.Projector.rst rename to docs/api_python/core/operators/quafu.core.operators.Projector.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.QubitExcitationOperator.rst b/docs/api_python/core/operators/quafu.core.operators.QubitExcitationOperator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.QubitExcitationOperator.rst rename to docs/api_python/core/operators/quafu.core.operators.QubitExcitationOperator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.QubitOperator.rst b/docs/api_python/core/operators/quafu.core.operators.QubitOperator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.QubitOperator.rst rename to docs/api_python/core/operators/quafu.core.operators.QubitOperator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.TimeEvolution.rst b/docs/api_python/core/operators/quafu.core.operators.TimeEvolution.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.TimeEvolution.rst rename to docs/api_python/core/operators/quafu.core.operators.TimeEvolution.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.commutator.rst b/docs/api_python/core/operators/quafu.core.operators.commutator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.commutator.rst rename to docs/api_python/core/operators/quafu.core.operators.commutator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.count_qubits.rst b/docs/api_python/core/operators/quafu.core.operators.count_qubits.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.count_qubits.rst rename to docs/api_python/core/operators/quafu.core.operators.count_qubits.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.down_index.rst b/docs/api_python/core/operators/quafu.core.operators.down_index.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.down_index.rst rename to docs/api_python/core/operators/quafu.core.operators.down_index.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.get_fermion_operator.rst b/docs/api_python/core/operators/quafu.core.operators.get_fermion_operator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.get_fermion_operator.rst rename to docs/api_python/core/operators/quafu.core.operators.get_fermion_operator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.ground_state_of_sum_zz.rst b/docs/api_python/core/operators/quafu.core.operators.ground_state_of_sum_zz.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.ground_state_of_sum_zz.rst rename to docs/api_python/core/operators/quafu.core.operators.ground_state_of_sum_zz.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.hermitian_conjugated.rst b/docs/api_python/core/operators/quafu.core.operators.hermitian_conjugated.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.hermitian_conjugated.rst rename to docs/api_python/core/operators/quafu.core.operators.hermitian_conjugated.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.normal_ordered.rst b/docs/api_python/core/operators/quafu.core.operators.normal_ordered.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.normal_ordered.rst rename to docs/api_python/core/operators/quafu.core.operators.normal_ordered.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.number_operator.rst b/docs/api_python/core/operators/quafu.core.operators.number_operator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.number_operator.rst rename to docs/api_python/core/operators/quafu.core.operators.number_operator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.sz_operator.rst b/docs/api_python/core/operators/quafu.core.operators.sz_operator.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.sz_operator.rst rename to docs/api_python/core/operators/quafu.core.operators.sz_operator.rst diff --git a/docs/api_python/core/operators/mindquantum.core.operators.up_index.rst b/docs/api_python/core/operators/quafu.core.operators.up_index.rst similarity index 100% rename from docs/api_python/core/operators/mindquantum.core.operators.up_index.rst rename to docs/api_python/core/operators/quafu.core.operators.up_index.rst diff --git a/docs/api_python/core/parameterresolver/mindquantum.core.parameterresolver.PRGenerator.rst b/docs/api_python/core/parameterresolver/quafu.core.parameterresolver.PRGenerator.rst similarity index 100% rename from docs/api_python/core/parameterresolver/mindquantum.core.parameterresolver.PRGenerator.rst rename to docs/api_python/core/parameterresolver/quafu.core.parameterresolver.PRGenerator.rst diff --git a/docs/api_python/core/parameterresolver/mindquantum.core.parameterresolver.ParameterResolver.rst b/docs/api_python/core/parameterresolver/quafu.core.parameterresolver.ParameterResolver.rst similarity index 100% rename from docs/api_python/core/parameterresolver/mindquantum.core.parameterresolver.ParameterResolver.rst rename to docs/api_python/core/parameterresolver/quafu.core.parameterresolver.ParameterResolver.rst diff --git a/docs/api_python/core/mindquantum.core.circuit.rst b/docs/api_python/core/quafu.core.circuit.rst similarity index 100% rename from docs/api_python/core/mindquantum.core.circuit.rst rename to docs/api_python/core/quafu.core.circuit.rst diff --git a/docs/api_python/core/mindquantum.core.gates.rst b/docs/api_python/core/quafu.core.gates.rst similarity index 100% rename from docs/api_python/core/mindquantum.core.gates.rst rename to docs/api_python/core/quafu.core.gates.rst diff --git a/docs/api_python/core/mindquantum.core.operators.rst b/docs/api_python/core/quafu.core.operators.rst similarity index 100% rename from docs/api_python/core/mindquantum.core.operators.rst rename to docs/api_python/core/quafu.core.operators.rst diff --git a/docs/api_python/core/mindquantum.core.parameterresolver.rst b/docs/api_python/core/quafu.core.parameterresolver.rst similarity index 100% rename from docs/api_python/core/mindquantum.core.parameterresolver.rst rename to docs/api_python/core/quafu.core.parameterresolver.rst diff --git a/docs/api_python/device/mindquantum.device.GridQubits.rst b/docs/api_python/device/quafu.device.GridQubits.rst similarity index 100% rename from docs/api_python/device/mindquantum.device.GridQubits.rst rename to docs/api_python/device/quafu.device.GridQubits.rst diff --git a/docs/api_python/device/mindquantum.device.LinearQubits.rst b/docs/api_python/device/quafu.device.LinearQubits.rst similarity index 100% rename from docs/api_python/device/mindquantum.device.LinearQubits.rst rename to docs/api_python/device/quafu.device.LinearQubits.rst diff --git a/docs/api_python/device/mindquantum.device.QubitNode.rst b/docs/api_python/device/quafu.device.QubitNode.rst similarity index 100% rename from docs/api_python/device/mindquantum.device.QubitNode.rst rename to docs/api_python/device/quafu.device.QubitNode.rst diff --git a/docs/api_python/device/mindquantum.device.QubitsTopology.rst b/docs/api_python/device/quafu.device.QubitsTopology.rst similarity index 100% rename from docs/api_python/device/mindquantum.device.QubitsTopology.rst rename to docs/api_python/device/quafu.device.QubitsTopology.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.is_double_precision.rst b/docs/api_python/dtype/quafu.dtype.is_double_precision.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.is_double_precision.rst rename to docs/api_python/dtype/quafu.dtype.is_double_precision.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.is_same_precision.rst b/docs/api_python/dtype/quafu.dtype.is_same_precision.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.is_same_precision.rst rename to docs/api_python/dtype/quafu.dtype.is_same_precision.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.is_single_precision.rst b/docs/api_python/dtype/quafu.dtype.is_single_precision.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.is_single_precision.rst rename to docs/api_python/dtype/quafu.dtype.is_single_precision.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.precision_str.rst b/docs/api_python/dtype/quafu.dtype.precision_str.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.precision_str.rst rename to docs/api_python/dtype/quafu.dtype.precision_str.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_complex_type.rst b/docs/api_python/dtype/quafu.dtype.to_complex_type.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_complex_type.rst rename to docs/api_python/dtype/quafu.dtype.to_complex_type.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_double_precision.rst b/docs/api_python/dtype/quafu.dtype.to_double_precision.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_double_precision.rst rename to docs/api_python/dtype/quafu.dtype.to_double_precision.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_mq_type.rst b/docs/api_python/dtype/quafu.dtype.to_mq_type.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_mq_type.rst rename to docs/api_python/dtype/quafu.dtype.to_mq_type.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_np_type.rst b/docs/api_python/dtype/quafu.dtype.to_np_type.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_np_type.rst rename to docs/api_python/dtype/quafu.dtype.to_np_type.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_precision_like.rst b/docs/api_python/dtype/quafu.dtype.to_precision_like.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_precision_like.rst rename to docs/api_python/dtype/quafu.dtype.to_precision_like.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_real_type.rst b/docs/api_python/dtype/quafu.dtype.to_real_type.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_real_type.rst rename to docs/api_python/dtype/quafu.dtype.to_real_type.rst diff --git a/docs/api_python/dtype/mindquantum.dtype.to_single_precision.rst b/docs/api_python/dtype/quafu.dtype.to_single_precision.rst similarity index 100% rename from docs/api_python/dtype/mindquantum.dtype.to_single_precision.rst rename to docs/api_python/dtype/quafu.dtype.to_single_precision.rst diff --git a/docs/api_python/engine/mindquantum.engine.BasicQubit.rst b/docs/api_python/engine/quafu.engine.BasicQubit.rst similarity index 100% rename from docs/api_python/engine/mindquantum.engine.BasicQubit.rst rename to docs/api_python/engine/quafu.engine.BasicQubit.rst diff --git a/docs/api_python/engine/mindquantum.engine.CircuitEngine.rst b/docs/api_python/engine/quafu.engine.CircuitEngine.rst similarity index 100% rename from docs/api_python/engine/mindquantum.engine.CircuitEngine.rst rename to docs/api_python/engine/quafu.engine.CircuitEngine.rst diff --git a/docs/api_python/engine/mindquantum.engine.circuit_generator.rst b/docs/api_python/engine/quafu.engine.circuit_generator.rst similarity index 100% rename from docs/api_python/engine/mindquantum.engine.circuit_generator.rst rename to docs/api_python/engine/quafu.engine.circuit_generator.rst diff --git a/docs/api_python/framework/layer/mindquantum.framework.MQAnsatzOnlyLayer.rst b/docs/api_python/framework/layer/quafu.framework.MQAnsatzOnlyLayer.rst similarity index 100% rename from docs/api_python/framework/layer/mindquantum.framework.MQAnsatzOnlyLayer.rst rename to docs/api_python/framework/layer/quafu.framework.MQAnsatzOnlyLayer.rst diff --git a/docs/api_python/framework/layer/mindquantum.framework.MQLayer.rst b/docs/api_python/framework/layer/quafu.framework.MQLayer.rst similarity index 100% rename from docs/api_python/framework/layer/mindquantum.framework.MQLayer.rst rename to docs/api_python/framework/layer/quafu.framework.MQLayer.rst diff --git a/docs/api_python/framework/layer/mindquantum.framework.MQN2AnsatzOnlyLayer.rst b/docs/api_python/framework/layer/quafu.framework.MQN2AnsatzOnlyLayer.rst similarity index 100% rename from docs/api_python/framework/layer/mindquantum.framework.MQN2AnsatzOnlyLayer.rst rename to docs/api_python/framework/layer/quafu.framework.MQN2AnsatzOnlyLayer.rst diff --git a/docs/api_python/framework/layer/mindquantum.framework.MQN2Layer.rst b/docs/api_python/framework/layer/quafu.framework.MQN2Layer.rst similarity index 100% rename from docs/api_python/framework/layer/mindquantum.framework.MQN2Layer.rst rename to docs/api_python/framework/layer/quafu.framework.MQN2Layer.rst diff --git a/docs/api_python/framework/layer/mindquantum.framework.QRamVecLayer.rst b/docs/api_python/framework/layer/quafu.framework.QRamVecLayer.rst similarity index 100% rename from docs/api_python/framework/layer/mindquantum.framework.QRamVecLayer.rst rename to docs/api_python/framework/layer/quafu.framework.QRamVecLayer.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.MQAnsatzOnlyOps.rst b/docs/api_python/framework/operations/quafu.framework.MQAnsatzOnlyOps.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.MQAnsatzOnlyOps.rst rename to docs/api_python/framework/operations/quafu.framework.MQAnsatzOnlyOps.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.MQEncoderOnlyOps.rst b/docs/api_python/framework/operations/quafu.framework.MQEncoderOnlyOps.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.MQEncoderOnlyOps.rst rename to docs/api_python/framework/operations/quafu.framework.MQEncoderOnlyOps.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.MQN2AnsatzOnlyOps.rst b/docs/api_python/framework/operations/quafu.framework.MQN2AnsatzOnlyOps.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.MQN2AnsatzOnlyOps.rst rename to docs/api_python/framework/operations/quafu.framework.MQN2AnsatzOnlyOps.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.MQN2EncoderOnlyOps.rst b/docs/api_python/framework/operations/quafu.framework.MQN2EncoderOnlyOps.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.MQN2EncoderOnlyOps.rst rename to docs/api_python/framework/operations/quafu.framework.MQN2EncoderOnlyOps.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.MQN2Ops.rst b/docs/api_python/framework/operations/quafu.framework.MQN2Ops.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.MQN2Ops.rst rename to docs/api_python/framework/operations/quafu.framework.MQN2Ops.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.MQOps.rst b/docs/api_python/framework/operations/quafu.framework.MQOps.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.MQOps.rst rename to docs/api_python/framework/operations/quafu.framework.MQOps.rst diff --git a/docs/api_python/framework/operations/mindquantum.framework.QRamVecOps.rst b/docs/api_python/framework/operations/quafu.framework.QRamVecOps.rst similarity index 100% rename from docs/api_python/framework/operations/mindquantum.framework.QRamVecOps.rst rename to docs/api_python/framework/operations/quafu.framework.QRamVecOps.rst diff --git a/docs/api_python/io/mindquantum.io.BlochScene.rst b/docs/api_python/io/quafu.io.BlochScene.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.BlochScene.rst rename to docs/api_python/io/quafu.io.BlochScene.rst diff --git a/docs/api_python/io/mindquantum.io.HiQASM.rst b/docs/api_python/io/quafu.io.HiQASM.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.HiQASM.rst rename to docs/api_python/io/quafu.io.HiQASM.rst diff --git a/docs/api_python/io/mindquantum.io.OpenQASM.rst b/docs/api_python/io/quafu.io.OpenQASM.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.OpenQASM.rst rename to docs/api_python/io/quafu.io.OpenQASM.rst diff --git a/docs/api_python/io/mindquantum.io.QCIS.rst b/docs/api_python/io/quafu.io.QCIS.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.QCIS.rst rename to docs/api_python/io/quafu.io.QCIS.rst diff --git a/docs/api_python/io/mindquantum.io.bprint.rst b/docs/api_python/io/quafu.io.bprint.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.bprint.rst rename to docs/api_python/io/quafu.io.bprint.rst diff --git a/docs/api_python/io/mindquantum.io.draw_topology.rst b/docs/api_python/io/quafu.io.draw_topology.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.draw_topology.rst rename to docs/api_python/io/quafu.io.draw_topology.rst diff --git a/docs/api_python/io/mindquantum.io.draw_topology_plt.rst b/docs/api_python/io/quafu.io.draw_topology_plt.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.draw_topology_plt.rst rename to docs/api_python/io/quafu.io.draw_topology_plt.rst diff --git a/docs/api_python/io/mindquantum.io.random_hiqasm.rst b/docs/api_python/io/quafu.io.random_hiqasm.rst similarity index 100% rename from docs/api_python/io/mindquantum.io.random_hiqasm.rst rename to docs/api_python/io/quafu.io.random_hiqasm.rst diff --git a/docs/api_python/mindquantum.algorithm.rst b/docs/api_python/quafu.algorithm.rst similarity index 100% rename from docs/api_python/mindquantum.algorithm.rst rename to docs/api_python/quafu.algorithm.rst diff --git a/docs/api_python/mindquantum.core.rst b/docs/api_python/quafu.core.rst similarity index 100% rename from docs/api_python/mindquantum.core.rst rename to docs/api_python/quafu.core.rst diff --git a/docs/api_python/mindquantum.device.rst b/docs/api_python/quafu.device.rst similarity index 100% rename from docs/api_python/mindquantum.device.rst rename to docs/api_python/quafu.device.rst diff --git a/docs/api_python/mindquantum.dtype.rst b/docs/api_python/quafu.dtype.rst similarity index 100% rename from docs/api_python/mindquantum.dtype.rst rename to docs/api_python/quafu.dtype.rst diff --git a/docs/api_python/mindquantum.engine.rst b/docs/api_python/quafu.engine.rst similarity index 100% rename from docs/api_python/mindquantum.engine.rst rename to docs/api_python/quafu.engine.rst diff --git a/docs/api_python/mindquantum.framework.rst b/docs/api_python/quafu.framework.rst similarity index 100% rename from docs/api_python/mindquantum.framework.rst rename to docs/api_python/quafu.framework.rst diff --git a/docs/api_python/mindquantum.io.rst b/docs/api_python/quafu.io.rst similarity index 100% rename from docs/api_python/mindquantum.io.rst rename to docs/api_python/quafu.io.rst diff --git a/docs/api_python/mindquantum.simulator.rst b/docs/api_python/quafu.simulator.rst similarity index 100% rename from docs/api_python/mindquantum.simulator.rst rename to docs/api_python/quafu.simulator.rst diff --git a/docs/api_python/mindquantum.utils.rst b/docs/api_python/quafu.utils.rst similarity index 100% rename from docs/api_python/mindquantum.utils.rst rename to docs/api_python/quafu.utils.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.GradOpsWrapper.rst b/docs/api_python/simulator/quafu.simulator.GradOpsWrapper.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.GradOpsWrapper.rst rename to docs/api_python/simulator/quafu.simulator.GradOpsWrapper.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.NoiseBackend.rst b/docs/api_python/simulator/quafu.simulator.NoiseBackend.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.NoiseBackend.rst rename to docs/api_python/simulator/quafu.simulator.NoiseBackend.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.Simulator.rst b/docs/api_python/simulator/quafu.simulator.Simulator.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.Simulator.rst rename to docs/api_python/simulator/quafu.simulator.Simulator.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.decompose_stabilizer.rst b/docs/api_python/simulator/quafu.simulator.decompose_stabilizer.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.decompose_stabilizer.rst rename to docs/api_python/simulator/quafu.simulator.decompose_stabilizer.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.fidelity.rst b/docs/api_python/simulator/quafu.simulator.fidelity.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.fidelity.rst rename to docs/api_python/simulator/quafu.simulator.fidelity.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.get_stabilizer_string.rst b/docs/api_python/simulator/quafu.simulator.get_stabilizer_string.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.get_stabilizer_string.rst rename to docs/api_python/simulator/quafu.simulator.get_stabilizer_string.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.get_supported_simulator.rst b/docs/api_python/simulator/quafu.simulator.get_supported_simulator.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.get_supported_simulator.rst rename to docs/api_python/simulator/quafu.simulator.get_supported_simulator.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.get_tableau_string.rst b/docs/api_python/simulator/quafu.simulator.get_tableau_string.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.get_tableau_string.rst rename to docs/api_python/simulator/quafu.simulator.get_tableau_string.rst diff --git a/docs/api_python/simulator/mindquantum.simulator.inner_product.rst b/docs/api_python/simulator/quafu.simulator.inner_product.rst similarity index 100% rename from docs/api_python/simulator/mindquantum.simulator.inner_product.rst rename to docs/api_python/simulator/quafu.simulator.inner_product.rst diff --git a/docs/api_python/utils/mindquantum.utils.SingleLoopProgress.rst b/docs/api_python/utils/quafu.utils.SingleLoopProgress.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.SingleLoopProgress.rst rename to docs/api_python/utils/quafu.utils.SingleLoopProgress.rst diff --git a/docs/api_python/utils/mindquantum.utils.TwoLoopsProgress.rst b/docs/api_python/utils/quafu.utils.TwoLoopsProgress.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.TwoLoopsProgress.rst rename to docs/api_python/utils/quafu.utils.TwoLoopsProgress.rst diff --git a/docs/api_python/utils/mindquantum.utils.fdopen.rst b/docs/api_python/utils/quafu.utils.fdopen.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.fdopen.rst rename to docs/api_python/utils/quafu.utils.fdopen.rst diff --git a/docs/api_python/utils/mindquantum.utils.ket_string.rst b/docs/api_python/utils/quafu.utils.ket_string.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.ket_string.rst rename to docs/api_python/utils/quafu.utils.ket_string.rst diff --git a/docs/api_python/utils/mindquantum.utils.mod.rst b/docs/api_python/utils/quafu.utils.mod.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.mod.rst rename to docs/api_python/utils/quafu.utils.mod.rst diff --git a/docs/api_python/utils/mindquantum.utils.normalize.rst b/docs/api_python/utils/quafu.utils.normalize.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.normalize.rst rename to docs/api_python/utils/quafu.utils.normalize.rst diff --git a/docs/api_python/utils/mindquantum.utils.random_circuit.rst b/docs/api_python/utils/quafu.utils.random_circuit.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.random_circuit.rst rename to docs/api_python/utils/quafu.utils.random_circuit.rst diff --git a/docs/api_python/utils/mindquantum.utils.random_hamiltonian.rst b/docs/api_python/utils/quafu.utils.random_hamiltonian.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.random_hamiltonian.rst rename to docs/api_python/utils/quafu.utils.random_hamiltonian.rst diff --git a/docs/api_python/utils/mindquantum.utils.random_insert_gates.rst b/docs/api_python/utils/quafu.utils.random_insert_gates.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.random_insert_gates.rst rename to docs/api_python/utils/quafu.utils.random_insert_gates.rst diff --git a/docs/api_python/utils/mindquantum.utils.random_state.rst b/docs/api_python/utils/quafu.utils.random_state.rst similarity index 100% rename from docs/api_python/utils/mindquantum.utils.random_state.rst rename to docs/api_python/utils/quafu.utils.random_state.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.ASWAP.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.ASWAP.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.ASWAP.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.ASWAP.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz1.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz1.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz1.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz1.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz10.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz10.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz10.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz10.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz11.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz11.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz11.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz11.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz12.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz12.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz12.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz12.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz13.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz13.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz13.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz13.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz14.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz14.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz14.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz14.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz15.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz15.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz15.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz15.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz16.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz16.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz16.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz16.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz17.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz17.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz17.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz17.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz18.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz18.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz18.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz18.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz19.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz19.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz19.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz19.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz2.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz2.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz2.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz2.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz3.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz3.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz3.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz3.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz4.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz4.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz4.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz4.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz5.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz5.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz5.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz5.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz6.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz6.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz6.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz6.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz7.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz7.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz7.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz7.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz8.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz8.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz8.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz8.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz9.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz9.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.Ansatz9.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.Ansatz9.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ1F.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ1F.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ1F.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ1F.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ2F.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ2F.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.PCHeaXYZ2F.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.PCHeaXYZ2F.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYCascade.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYCascade.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYCascade.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYCascade.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYFull.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYFull.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYFull.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYFull.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYLinear.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYLinear.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYLinear.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYLinear.rst diff --git a/docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYRZFull.rst b/docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYRZFull.rst similarity index 100% rename from docs/api_python_en/algorithm/nisq/mindquantum.algorithm.nisq.RYRZFull.rst rename to docs/api_python_en/algorithm/nisq/quafu.algorithm.nisq.RYRZFull.rst diff --git a/docs/api_python_en/algorithm/mindquantum.algorithm.compiler.rst b/docs/api_python_en/algorithm/quafu.algorithm.compiler.rst similarity index 100% rename from docs/api_python_en/algorithm/mindquantum.algorithm.compiler.rst rename to docs/api_python_en/algorithm/quafu.algorithm.compiler.rst diff --git a/docs/api_python_en/algorithm/mindquantum.algorithm.error_mitigation.rst b/docs/api_python_en/algorithm/quafu.algorithm.error_mitigation.rst similarity index 100% rename from docs/api_python_en/algorithm/mindquantum.algorithm.error_mitigation.rst rename to docs/api_python_en/algorithm/quafu.algorithm.error_mitigation.rst diff --git a/docs/api_python_en/algorithm/mindquantum.algorithm.library.rst b/docs/api_python_en/algorithm/quafu.algorithm.library.rst similarity index 100% rename from docs/api_python_en/algorithm/mindquantum.algorithm.library.rst rename to docs/api_python_en/algorithm/quafu.algorithm.library.rst diff --git a/docs/api_python_en/algorithm/mindquantum.algorithm.mapping.rst b/docs/api_python_en/algorithm/quafu.algorithm.mapping.rst similarity index 100% rename from docs/api_python_en/algorithm/mindquantum.algorithm.mapping.rst rename to docs/api_python_en/algorithm/quafu.algorithm.mapping.rst diff --git a/docs/api_python_en/algorithm/mindquantum.algorithm.nisq.rst b/docs/api_python_en/algorithm/quafu.algorithm.nisq.rst similarity index 100% rename from docs/api_python_en/algorithm/mindquantum.algorithm.nisq.rst rename to docs/api_python_en/algorithm/quafu.algorithm.nisq.rst diff --git a/docs/api_python_en/algorithm/mindquantum.algorithm.qaia.rst b/docs/api_python_en/algorithm/quafu.algorithm.qaia.rst similarity index 100% rename from docs/api_python_en/algorithm/mindquantum.algorithm.qaia.rst rename to docs/api_python_en/algorithm/quafu.algorithm.qaia.rst diff --git a/docs/api_python_en/core/mindquantum.core.circuit.rst b/docs/api_python_en/core/quafu.core.circuit.rst similarity index 100% rename from docs/api_python_en/core/mindquantum.core.circuit.rst rename to docs/api_python_en/core/quafu.core.circuit.rst diff --git a/docs/api_python_en/core/mindquantum.core.gates.rst b/docs/api_python_en/core/quafu.core.gates.rst similarity index 100% rename from docs/api_python_en/core/mindquantum.core.gates.rst rename to docs/api_python_en/core/quafu.core.gates.rst diff --git a/docs/api_python_en/core/mindquantum.core.operators.rst b/docs/api_python_en/core/quafu.core.operators.rst similarity index 100% rename from docs/api_python_en/core/mindquantum.core.operators.rst rename to docs/api_python_en/core/quafu.core.operators.rst diff --git a/docs/api_python_en/core/mindquantum.core.parameterresolver.rst b/docs/api_python_en/core/quafu.core.parameterresolver.rst similarity index 100% rename from docs/api_python_en/core/mindquantum.core.parameterresolver.rst rename to docs/api_python_en/core/quafu.core.parameterresolver.rst diff --git a/docs/api_python_en/mindquantum.algorithm.rst b/docs/api_python_en/quafu.algorithm.rst similarity index 100% rename from docs/api_python_en/mindquantum.algorithm.rst rename to docs/api_python_en/quafu.algorithm.rst diff --git a/docs/api_python_en/mindquantum.core.rst b/docs/api_python_en/quafu.core.rst similarity index 100% rename from docs/api_python_en/mindquantum.core.rst rename to docs/api_python_en/quafu.core.rst diff --git a/docs/api_python_en/mindquantum.device.rst b/docs/api_python_en/quafu.device.rst similarity index 100% rename from docs/api_python_en/mindquantum.device.rst rename to docs/api_python_en/quafu.device.rst diff --git a/docs/api_python_en/mindquantum.dtype.rst b/docs/api_python_en/quafu.dtype.rst similarity index 100% rename from docs/api_python_en/mindquantum.dtype.rst rename to docs/api_python_en/quafu.dtype.rst diff --git a/docs/api_python_en/mindquantum.engine.rst b/docs/api_python_en/quafu.engine.rst similarity index 100% rename from docs/api_python_en/mindquantum.engine.rst rename to docs/api_python_en/quafu.engine.rst diff --git a/docs/api_python_en/mindquantum.framework.rst b/docs/api_python_en/quafu.framework.rst similarity index 100% rename from docs/api_python_en/mindquantum.framework.rst rename to docs/api_python_en/quafu.framework.rst diff --git a/docs/api_python_en/mindquantum.io.rst b/docs/api_python_en/quafu.io.rst similarity index 100% rename from docs/api_python_en/mindquantum.io.rst rename to docs/api_python_en/quafu.io.rst diff --git a/docs/api_python_en/mindquantum.simulator.rst b/docs/api_python_en/quafu.simulator.rst similarity index 100% rename from docs/api_python_en/mindquantum.simulator.rst rename to docs/api_python_en/quafu.simulator.rst diff --git a/docs/api_python_en/mindquantum.utils.rst b/docs/api_python_en/quafu.utils.rst similarity index 100% rename from docs/api_python_en/mindquantum.utils.rst rename to docs/api_python_en/quafu.utils.rst diff --git a/docs/MindQuantum-architecture.png b/docs/quafu-architecture.png similarity index 100% rename from docs/MindQuantum-architecture.png rename to docs/quafu-architecture.png diff --git a/docs/MindQuantum-architecture_EN.png b/docs/quafu-architecture_EN.png similarity index 100% rename from docs/MindQuantum-architecture_EN.png rename to docs/quafu-architecture_EN.png diff --git a/docs/source/conf.py b/docs/source/conf.py index ec07c9763..ac4332e14 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,7 +19,7 @@ # list see the documentation: # http://www.sphinx-doc.org/en/master/config -"""Sphinx configuration file for MindQuantum.""" +"""Sphinx configuration file for quafu.""" # pylint: disable=invalid-name # Sphinx variables @@ -46,19 +46,19 @@ on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if on_rtd: - # C++ compilation will fail on RTD so we create a "dummy" package to allow a successful importation of MindQuantum - mqbackend = conf_path.parent.parent / 'mindquantum' / 'mqbackend.py' - if not mqbackend.exists(): - mqbackend.write_text('') + # C++ compilation will fail on RTD so we create a "dummy" package to allow a successful importation of quafu + quafubackend = conf_path.parent.parent / 'quafu' / 'quafubackend.py' + if not quafubackend.exists(): + quafubackend.write_text('') print(f'INFO: Calling doxygen in {conf_path.parent}') subprocess.check_call(['doxygen'], cwd=conf_path.parent) # -- Project information ----------------------------------------------------- -project = 'MindQuantum' -description = '''MindQuantum is a general quantum computing framework developed by MindSpore and HiQ, that can be used +project = 'quafu' +description = '''quafu is a general quantum computing framework developed by MindSpore and HiQ, that can be used to build and train different quantum neural networks. Thanks to the powerful algorithm of quantum software group of -Huawei and High-performance automatic differentiation ability of MindSpore, MindQuantum can efficiently handle +Huawei and High-performance automatic differentiation ability of MindSpore, quafu can efficiently handle problems such as quantum machine learning, quantum chemistry simulation, and quantum optimization, which provides an efficient platform for researchers, teachers and students to quickly design and verify quantum machine learning algorithms.''' @@ -95,7 +95,7 @@ # The master toctree document. master_doc = 'index' -release = importlib_metadata.version('mindquantum') # Full version string +release = importlib_metadata.version('quafu') # Full version string version = '.'.join(release.split('.')[:3]) # X.Y.Z # The language for content autogenerated by Sphinx. Refer to documentation for a list of supported languages. @@ -116,7 +116,7 @@ # -- Options for C++ documentation -breathe_projects = {'mindquantum': f'{doxygen_output_path}/xml'} +breathe_projects = {'quafu': f'{doxygen_output_path}/xml'} breathe_default_members = ('members', 'undoc-members') highlight_language = 'c++' @@ -128,7 +128,7 @@ html_theme = 'sphinx_rtd_theme' # Output file base name for HTML help builder. -htmlhelp_basename = 'mqdoc' +htmlhelp_basename = 'quafudoc' # ---------------------------------------------------------------------------- @@ -137,7 +137,7 @@ # Grouping the document tree into LaTeX files. List of tuples (source start file, target name, title, author, # documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'MindQuantum.tex', f'{project} Documentation', 'a', 'manual'), + (master_doc, 'quafu.tex', f'{project} Documentation', 'a', 'manual'), ] # -- Options for manual page output --------------------------------------- diff --git a/mindquantum/__init__.py b/quafu/__init__.py similarity index 85% rename from mindquantum/__init__.py rename to quafu/__init__.py index 2b2cd4481..039c2fcfa 100644 --- a/mindquantum/__init__.py +++ b/quafu/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -""".. MindQuantum package.""" +""".. quafu package.""" import os import sys @@ -20,7 +20,7 @@ import numpy as np -from .mqbackend import logging +from .quafubackend import logging from .framework import framework_modules # isort: split @@ -55,7 +55,7 @@ from importlib.metadata import PackageNotFoundError, version try: - __version__ = version("mindquantum") + __version__ = version("quafu") __version_info__ = tuple(__version__.split('.')) __all__ = ['__version__', '__version_info__'] except (PackageNotFoundError, AttributeError): @@ -77,8 +77,8 @@ def __getattr__(name): if name in framework_modules: raise ImportError( - f"cannot import '{name}' from 'mindquantum'. " - "MindSpore not installed, 'mindquantum.framework' modules " + f"cannot import '{name}' from 'quafu'. " + "MindSpore not installed, 'quafu.framework' modules " "(for hybrid quantum-classical neural network) are disabled." ) - raise ImportError(f"cannot import '{name}' from 'mindquantum'. '{name}' does not exist in mindquantum.") + raise ImportError(f"cannot import '{name}' from 'quafu'. '{name}' does not exist in quafu.") diff --git a/mindquantum/__main__.py b/quafu/__main__.py similarity index 87% rename from mindquantum/__main__.py rename to quafu/__main__.py index b3b28f820..7aa69aa80 100644 --- a/mindquantum/__main__.py +++ b/quafu/__main__.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Console entry point to access MindQuantum installation variables.""" +"""Console entry point to access quafu installation variables.""" -from mindquantum_config import main +from quafu_config import main # ============================================================================== diff --git a/mindquantum/algorithm/__init__.py b/quafu/algorithm/__init__.py similarity index 100% rename from mindquantum/algorithm/__init__.py rename to quafu/algorithm/__init__.py diff --git a/mindquantum/algorithm/compiler/__init__.py b/quafu/algorithm/compiler/__init__.py similarity index 95% rename from mindquantum/algorithm/compiler/__init__.py rename to quafu/algorithm/compiler/__init__.py index 9abec8088..65882bd0d 100644 --- a/mindquantum/algorithm/compiler/__init__.py +++ b/quafu/algorithm/compiler/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""MindQuantum compiler related modules.""" +"""quafu compiler related modules.""" import sys sys.setrecursionlimit(20000) diff --git a/mindquantum/algorithm/compiler/dag/__init__.py b/quafu/algorithm/compiler/dag/__init__.py similarity index 100% rename from mindquantum/algorithm/compiler/dag/__init__.py rename to quafu/algorithm/compiler/dag/__init__.py diff --git a/mindquantum/algorithm/compiler/dag/dag.py b/quafu/algorithm/compiler/dag/dag.py similarity index 95% rename from mindquantum/algorithm/compiler/dag/dag.py rename to quafu/algorithm/compiler/dag/dag.py index 788743999..6f715cbb4 100644 --- a/mindquantum/algorithm/compiler/dag/dag.py +++ b/quafu/algorithm/compiler/dag/dag.py @@ -15,8 +15,8 @@ """DAG Circuit.""" import typing -from mindquantum.core import Circuit, gates -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core import Circuit, gates +from quafu.utils.type_value_check import _check_input_type # pylint: disable=invalid-name @@ -155,8 +155,8 @@ class DAGCircuit: circuit (:class:`~.core.circuit.Circuit`): the input quantum circuit. Examples: - >>> from mindquantum.algorithm.compiler import DAGCircuit - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.algorithm.compiler import DAGCircuit + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().h(0).x(1, 0) >>> dag_circ = DAGCircuit(circ) >>> dag_circ.head_node[0] @@ -192,8 +192,8 @@ def replace_node_with_dag_circuit(node: DAGNode, coming: "DAGCircuit"): coming (:class:`~.algorithm.compiler.DAGCircuit`): the coming DAG circuit. Examples: - >>> from mindquantum.algorithm.compiler import DAGCircuit - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.algorithm.compiler import DAGCircuit + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().x(1, 0) >>> circ q0: ────■───── @@ -228,9 +228,9 @@ def append_node(self, node: DAGNode): node (:class:`~.algorithm.compiler.DAGNode`): the DAG node you want to append. Examples: - >>> from mindquantum.algorithm.compiler import DAGCircuit, GateNode - >>> from mindquantum.core.circuit import Circuit - >>> import mindquantum.core.gates as G + >>> from quafu.algorithm.compiler import DAGCircuit, GateNode + >>> from quafu.core.circuit import Circuit + >>> import quafu.core.gates as G >>> circ = Circuit().h(0).x(1, 0) >>> circ ┏━━━┓ @@ -265,8 +265,8 @@ def depth(self) -> int: Return the depth of quantum circuit. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.algorithm.compiler import DAGCircuit + >>> from quafu.core.circuit import Circuit + >>> from quafu.algorithm.compiler import DAGCircuit >>> circ = Circuit().h(0).h(1).x(1, 0) >>> circ ┏━━━┓ @@ -289,8 +289,8 @@ def find_all_gate_node(self) -> typing.List[GateNode]: of this :class:`~.algorithm.compiler.DAGCircuit`. Examples: - >>> from mindquantum.algorithm.compiler import DAGCircuit - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.algorithm.compiler import DAGCircuit + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().h(0).x(1, 0) >>> dag_circ = DAGCircuit(circ) >>> dag_circ.find_all_gate_node() @@ -319,8 +319,8 @@ def layering(self) -> typing.List[Circuit]: List[:class:`~.core.circuit.Circuit`], a list of layered quantum circuit. Examples: - >>> from mindquantum.algorithm.compiler import DAGCircuit - >>> from mindquantum.utils import random_circuit + >>> from quafu.algorithm.compiler import DAGCircuit + >>> from quafu.utils import random_circuit >>> circ = random_circuit(3, 5, seed=42) >>> circ ┏━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━┓ @@ -398,8 +398,8 @@ def to_circuit(self) -> Circuit: :class:`~.core.circuit.Circuit`, the quantum circuit of this DAG. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.algorithm.compiler import DAGCircuit + >>> from quafu.core.circuit import Circuit + >>> from quafu.algorithm.compiler import DAGCircuit >>> circ = Circuit().h(0).h(1).x(1, 0) >>> circ ┏━━━┓ diff --git a/mindquantum/algorithm/compiler/decompose/__init__.py b/quafu/algorithm/compiler/decompose/__init__.py similarity index 100% rename from mindquantum/algorithm/compiler/decompose/__init__.py rename to quafu/algorithm/compiler/decompose/__init__.py diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/__init__.py b/quafu/algorithm/compiler/decompose/fixed_decompose/__init__.py similarity index 100% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/__init__.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/__init__.py diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/h_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/h_related.py similarity index 87% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/h_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/h_related.py index 71a484075..2a2be57ad 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/h_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/h_related.py @@ -14,9 +14,9 @@ # ============================================================================ """H gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def ch_decompose(gate: gates.HGate): @@ -30,9 +30,9 @@ def ch_decompose(gate: gates.HGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import ch_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import T, X, H, S + >>> from quafu.algorithm.compiler import ch_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import T, X, H, S >>> ch = H.on(1, 0) >>> origin_circ = Circuit() + ch >>> decomposed_circ = ch_decompose(ch)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rx_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/rx_related.py similarity index 88% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/rx_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/rx_related.py index a6a9007d4..dcc423325 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rx_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/rx_related.py @@ -14,9 +14,9 @@ # ============================================================================ """RX gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def crx_decompose(gate: gates.RX): @@ -30,9 +30,9 @@ def crx_decompose(gate: gates.RX): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import crx_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RX + >>> from quafu.algorithm.compiler import crx_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RX >>> crx = RX(1).on(1, 0) >>> origin_circ = Circuit() + crx >>> decomposed_circ = crx_decompose(crx)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rxx_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/rxx_related.py similarity index 89% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/rxx_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/rxx_related.py index 96b0592dd..844b023e5 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rxx_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/rxx_related.py @@ -14,9 +14,9 @@ # ============================================================================ """Rxx gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def rxx_decompose(gate: gates.Rxx): @@ -30,9 +30,9 @@ def rxx_decompose(gate: gates.Rxx): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import rxx_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Rxx + >>> from quafu.algorithm.compiler import rxx_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Rxx >>> rxx = Rxx(1).on([0, 1]) >>> origin_circ = Circuit() + rxx >>> decomposed_circ = rxx_decompose(rxx)[0] @@ -67,8 +67,8 @@ def crxx_decompose(gate: gates.Rxx): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler.decompose import crxx_decompose - >>> from mindquantum.core import Circuit, Rxx + >>> from quafu.algorithm.compiler.decompose import crxx_decompose + >>> from quafu.core import Circuit, Rxx >>> crxx = Rxx(2).on([0, 1], [2, 3]) >>> origin_circ = Circuit() + crxx >>> decomposed_circ = crxx_decompose(crxx)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/ry_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/ry_related.py similarity index 88% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/ry_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/ry_related.py index c2c78078d..d6ea55388 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/ry_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/ry_related.py @@ -14,9 +14,9 @@ # ============================================================================ """RY gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def cry_decompose(gate: gates.RY): @@ -30,9 +30,9 @@ def cry_decompose(gate: gates.RY): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cry_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RY + >>> from quafu.algorithm.compiler import cry_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RY >>> cry = RY(1).on(1, 0) >>> origin_circ = Circuit() + cry >>> decomposed_circ = cry_decompose(cry)[0] @@ -60,6 +60,7 @@ def cry_decompose(gate: gates.RY): circuit += gates.X.on(target, control) return [circuit] + def _cnry_frame(ctrl_qubits, obj_qubit, angle): """The function used to construct iteratively the circuit of the cnry_decompose compiler. @@ -73,17 +74,18 @@ def _cnry_frame(ctrl_qubits, obj_qubit, angle): """ circ = Circuit() if len(ctrl_qubits) == 1: - circ.ry(angle/2, obj_qubit) + circ.ry(angle / 2, obj_qubit) circ.x(obj_qubit, ctrl_qubits[0]) - circ.ry(-angle/2, obj_qubit) + circ.ry(-angle / 2, obj_qubit) circ.x(obj_qubit, ctrl_qubits[0]) else: - circ += _cnry_frame(ctrl_qubits[1:], obj_qubit, angle/2) + circ += _cnry_frame(ctrl_qubits[1:], obj_qubit, angle / 2) circ.x(obj_qubit, ctrl_qubits[0]) - circ += _cnry_frame(ctrl_qubits[1:], obj_qubit, -angle/2) + circ += _cnry_frame(ctrl_qubits[1:], obj_qubit, -angle / 2) circ.x(obj_qubit, ctrl_qubits[0]) return circ + def cnry_decompose(gate: gates.RY): """ Decompose controlled :class:`~.core.gates.RY` gate. @@ -95,9 +97,9 @@ def cnry_decompose(gate: gates.RY): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cnry_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RY + >>> from quafu.algorithm.compiler import cnry_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RY >>> cry = RY(1).on(2, [0, 1]) >>> origin_circ = Circuit() + cry >>> decomposed_circ = cnry_decompose(cry)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/ryy_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/ryy_related.py similarity index 90% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/ryy_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/ryy_related.py index 7597b9924..665bae8fd 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/ryy_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/ryy_related.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def ryy_decompose(gate: gates.Ryy): @@ -32,9 +32,9 @@ def ryy_decompose(gate: gates.Ryy): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import ryy_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Ryy + >>> from quafu.algorithm.compiler import ryy_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Ryy >>> ryy = Ryy(1).on([0, 1]) >>> origin_circ = Circuit() + ryy >>> decomposed_circ = ryy_decompose(ryy)[0] @@ -69,9 +69,9 @@ def cryy_decompose(gate: gates.Ryy): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cryy_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Ryy + >>> from quafu.algorithm.compiler import cryy_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Ryy >>> cryy = Ryy(2).on([0, 1], [2, 3]) >>> origin_circ = Circuit() + cryy >>> decomposed_circ = cryy_decompose(cryy)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rz_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/rz_related.py similarity index 88% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/rz_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/rz_related.py index 6318c5e12..bd787c00d 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rz_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/rz_related.py @@ -14,9 +14,9 @@ # ============================================================================ """RZ gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def crz_decompose(gate: gates.RZ): @@ -30,9 +30,9 @@ def crz_decompose(gate: gates.RZ): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import crz_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import X, RZ + >>> from quafu.algorithm.compiler import crz_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import X, RZ >>> crz = RZ(1).on(1, 0) >>> origin_circ = Circuit() + crz >>> decomposed_circ = crz_decompose(crz)[0] @@ -60,6 +60,7 @@ def crz_decompose(gate: gates.RZ): circuit += gates.X.on(target, control) return [circuit] + def _cnrz_frame(ctrl_qubits, obj_qubit, angle): """The function used to construct iteratively the circuit of the cnrz_decompose compiler. @@ -73,17 +74,18 @@ def _cnrz_frame(ctrl_qubits, obj_qubit, angle): """ circ = Circuit() if len(ctrl_qubits) == 1: - circ.rz(angle/2, obj_qubit) + circ.rz(angle / 2, obj_qubit) circ.x(obj_qubit, ctrl_qubits[0]) - circ.rz(-angle/2, obj_qubit) + circ.rz(-angle / 2, obj_qubit) circ.x(obj_qubit, ctrl_qubits[0]) else: - circ += _cnrz_frame(ctrl_qubits[1:], obj_qubit, angle/2) + circ += _cnrz_frame(ctrl_qubits[1:], obj_qubit, angle / 2) circ.x(obj_qubit, ctrl_qubits[0]) - circ += _cnrz_frame(ctrl_qubits[1:], obj_qubit, -angle/2) + circ += _cnrz_frame(ctrl_qubits[1:], obj_qubit, -angle / 2) circ.x(obj_qubit, ctrl_qubits[0]) return circ + def cnrz_decompose(gate: gates.RZ): """ Decompose controlled :class:`~.core.gates.RZ` gate. @@ -95,9 +97,9 @@ def cnrz_decompose(gate: gates.RZ): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cnrz_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RZ + >>> from quafu.algorithm.compiler import cnrz_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RZ >>> crz = RZ(1).on(2, [0, 1]) >>> origin_circ = Circuit() + crz >>> decomposed_circ = cnrz_decompose(crz)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rzz_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/rzz_related.py similarity index 86% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/rzz_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/rzz_related.py index 812382b23..28cf016a2 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/rzz_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/rzz_related.py @@ -14,9 +14,9 @@ # ============================================================================ """Rzz gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def rzz_decompose(gate: gates.Rzz): @@ -30,9 +30,9 @@ def rzz_decompose(gate: gates.Rzz): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import rzz_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Rzz + >>> from quafu.algorithm.compiler import rzz_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Rzz >>> rzz = Rzz(1).on([0, 1]) >>> origin_circ = Circuit() + rzz >>> decomposed_circ = rzz_decompose(rzz)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/s_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/s_related.py similarity index 88% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/s_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/s_related.py index ae0607815..ee34119c2 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/s_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/s_related.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def cs_decompose(gate: gates.SGate): @@ -32,9 +32,9 @@ def cs_decompose(gate: gates.SGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cs_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import S + >>> from quafu.algorithm.compiler import cs_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import S >>> cs = S.on(1, 0) >>> origin_circ = Circuit() + cs >>> decomposed_circ = cs_decompose(cs)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/swap_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/swap_related.py similarity index 87% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/swap_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/swap_related.py index a81beaeb3..786e735e3 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/swap_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/swap_related.py @@ -14,9 +14,9 @@ # ============================================================================ """SWAP gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def swap_decompose(gate: gates.SWAPGate): @@ -30,9 +30,9 @@ def swap_decompose(gate: gates.SWAPGate): List[:class:`~.core.circuit.Circuit`], All possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler.decompose import swap_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import SWAP + >>> from quafu.algorithm.compiler.decompose import swap_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import SWAP >>> swap = SWAP.on([1, 0]) >>> origin_circ = Circuit() + swap >>> decomposed_circ = swap_decompose(swap)[0] @@ -72,8 +72,8 @@ def cswap_decompose(gate: gates.SWAPGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler.decompose import cswap_decompose - >>> from mindquantum.core import Circuit, SWAP + >>> from quafu.algorithm.compiler.decompose import cswap_decompose + >>> from quafu.core import Circuit, SWAP >>> cswap = SWAP.on([1, 2], 0) >>> origin_circ = Circuit() + cswap >>> decomposed_circ = cswap_decompose(cswap)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/t_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/t_related.py similarity index 87% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/t_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/t_related.py index a63298b78..f572156a0 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/t_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/t_related.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def ct_decompose(gate: gates.TGate): @@ -32,9 +32,9 @@ def ct_decompose(gate: gates.TGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import ct_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import T + >>> from quafu.algorithm.compiler import ct_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import T >>> ct = T.on(1, 0) >>> origin_circ = Circuit() + ct >>> decomposed_circ = ct_decompose(ct)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/x_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/x_related.py similarity index 93% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/x_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/x_related.py index aeb7f234d..807bd10c4 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/x_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/x_related.py @@ -14,9 +14,9 @@ # ============================================================================ """X gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def ccx_decompose(gate: gates.XGate): @@ -30,9 +30,9 @@ def ccx_decompose(gate: gates.XGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler.decompose import ccx_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import X + >>> from quafu.algorithm.compiler.decompose import ccx_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import X >>> ccx = X.on(2, [0,1]) >>> origin_circ = Circuit() + ccx >>> decomposed_circ = ccx_decompose(ccx)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/y_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/y_related.py similarity index 85% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/y_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/y_related.py index 6c2844ebd..7bb749e40 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/y_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/y_related.py @@ -14,9 +14,9 @@ # ============================================================================ """y gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def cy_decompose(gate: gates.YGate): @@ -30,9 +30,9 @@ def cy_decompose(gate: gates.YGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cy_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Y + >>> from quafu.algorithm.compiler import cy_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Y >>> cy = Y.on(1, 0) >>> origin_circ = Circuit() + cy >>> decomposed_circ = cy_decompose(cy)[0] diff --git a/mindquantum/algorithm/compiler/decompose/fixed_decompose/z_related.py b/quafu/algorithm/compiler/decompose/fixed_decompose/z_related.py similarity index 85% rename from mindquantum/algorithm/compiler/decompose/fixed_decompose/z_related.py rename to quafu/algorithm/compiler/decompose/fixed_decompose/z_related.py index 1b4b0075b..1b9182599 100644 --- a/mindquantum/algorithm/compiler/decompose/fixed_decompose/z_related.py +++ b/quafu/algorithm/compiler/decompose/fixed_decompose/z_related.py @@ -14,9 +14,9 @@ # ============================================================================ """Z gate related decompose rule.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.utils.type_value_check import _check_control_num, _check_input_type +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.utils.type_value_check import _check_control_num, _check_input_type def cz_decompose(gate: gates.ZGate): @@ -30,9 +30,9 @@ def cz_decompose(gate: gates.ZGate): List[:class:`~.core.circuit.Circuit`], all possible decompose solution. Examples: - >>> from mindquantum.algorithm.compiler import cz_decompose - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Z + >>> from quafu.algorithm.compiler import cz_decompose + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Z >>> cz = Z.on(1, 0) >>> origin_circ = Circuit() + cz >>> decomposed_circ = cz_decompose(cz)[0] diff --git a/mindquantum/algorithm/compiler/decompose/universal_decompose/__init__.py b/quafu/algorithm/compiler/decompose/universal_decompose/__init__.py similarity index 100% rename from mindquantum/algorithm/compiler/decompose/universal_decompose/__init__.py rename to quafu/algorithm/compiler/decompose/universal_decompose/__init__.py diff --git a/mindquantum/algorithm/compiler/decompose/universal_decompose/one_qubit_decompose.py b/quafu/algorithm/compiler/decompose/universal_decompose/one_qubit_decompose.py similarity index 94% rename from mindquantum/algorithm/compiler/decompose/universal_decompose/one_qubit_decompose.py rename to quafu/algorithm/compiler/decompose/universal_decompose/one_qubit_decompose.py index c32e64cd1..2b38a2176 100644 --- a/mindquantum/algorithm/compiler/decompose/universal_decompose/one_qubit_decompose.py +++ b/quafu/algorithm/compiler/decompose/universal_decompose/one_qubit_decompose.py @@ -14,9 +14,9 @@ # ============================================================================ """One-qubit gate decomposition.""" -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import QuantumGate +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.core.gates import QuantumGate from ..utils import params_u3, params_zyz diff --git a/mindquantum/algorithm/compiler/decompose/universal_decompose/qs_and_cu_decompose.py b/quafu/algorithm/compiler/decompose/universal_decompose/qs_and_cu_decompose.py similarity index 93% rename from mindquantum/algorithm/compiler/decompose/universal_decompose/qs_and_cu_decompose.py rename to quafu/algorithm/compiler/decompose/universal_decompose/qs_and_cu_decompose.py index 733764bae..4b5557f74 100644 --- a/mindquantum/algorithm/compiler/decompose/universal_decompose/qs_and_cu_decompose.py +++ b/quafu/algorithm/compiler/decompose/universal_decompose/qs_and_cu_decompose.py @@ -19,10 +19,10 @@ import numpy as np from scipy import linalg -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import BarrierGate, QuantumGate -from mindquantum.utils.f import is_power_of_two +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.core.gates import BarrierGate, QuantumGate +from quafu.utils.f import is_power_of_two from .. import utils from ..fixed_decompose import ccx_decompose @@ -47,17 +47,17 @@ def cu_decompose(gate: QuantumGate, with_barrier: bool = False) -> Circuit: :class:`~.core.circuit.Circuit`, composed of 1-qubit gates and CNOT gates. Examples: - >>> import mindquantum as mq - >>> from mindquantum.algorithm.compiler import cu_decompose + >>> import quafu + >>> from quafu.algorithm.compiler import cu_decompose >>> from scipy.stats import unitary_group >>> cqs = [0, 2, 4, 5] >>> tqs = [1, 6] >>> m = len(cqs) >>> n = len(tqs) >>> u = unitary_group.rvs(2 ** n, random_state=123) - >>> g = mq.UnivMathGate('U', u).on(tqs, cqs) + >>> g = quafu.UnivMathGate('U', u).on(tqs, cqs) >>> circ = cu_decompose(g) - >>> num_cnot = len([g for g in circ if isinstance(g, mq.XGate) and len(g.ctrl_qubits)==1]) + >>> num_cnot = len([g for g in circ if isinstance(g, quafu.XGate) and len(g.ctrl_qubits)==1]) >>> print('total gate number: {}, CNOT number: {}'.format(len(circ), num_cnot)) total gate number: 632, CNOT number: 314 """ @@ -115,15 +115,15 @@ def qs_decompose(gate: QuantumGate, with_barrier: bool = False) -> Circuit: :class:`~.core.circuit.Circuit`, composed of 1-qubit gates and CNOT gates. Examples: - >>> import mindquantum as mq - >>> from mindquantum.algorithm.compiler.decompose import qs_decompose + >>> import quafu + >>> from quafu.algorithm.compiler.decompose import qs_decompose >>> from scipy.stats import unitary_group >>> tqs = [1,2,3,6] # arbitrary qubit index order is OK >>> n = len(tqs) # qubit number >>> u = unitary_group.rvs(2 ** n, random_state=123) - >>> g = mq.UnivMathGate('U', u).on(tqs) + >>> g = quafu.UnivMathGate('U', u).on(tqs) >>> circ = qs_decompose(g) - >>> num_cnot = len([g for g in circ if isinstance(g, mq.XGate) and len(g.ctrl_qubits)==1]) + >>> num_cnot = len([g for g in circ if isinstance(g, quafu.XGate) and len(g.ctrl_qubits)==1]) >>> print('total gate number: {}, CNOT number: {}'.format(len(circ), num_cnot)) total gate number: 412, CNOT number: 180 """ diff --git a/mindquantum/algorithm/compiler/decompose/universal_decompose/two_qubit_decompose.py b/quafu/algorithm/compiler/decompose/universal_decompose/two_qubit_decompose.py similarity index 93% rename from mindquantum/algorithm/compiler/decompose/universal_decompose/two_qubit_decompose.py rename to quafu/algorithm/compiler/decompose/universal_decompose/two_qubit_decompose.py index 6e73bb81d..3b1439a36 100644 --- a/mindquantum/algorithm/compiler/decompose/universal_decompose/two_qubit_decompose.py +++ b/quafu/algorithm/compiler/decompose/universal_decompose/two_qubit_decompose.py @@ -19,9 +19,9 @@ import numpy as np from scipy import linalg -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import QuantumGate +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.core.gates import QuantumGate from .. import utils from ..fixed_decompose import crx_decompose, cry_decompose, crz_decompose @@ -53,10 +53,10 @@ def tensor_product_decompose(gate: QuantumGate, return_u3: bool = True) -> Circu Examples: >>> import numpy as np - >>> import mindquantum as mq - >>> from mindquantum.algorithm.compiler.decompose import tensor_product_decompose - >>> g = mq.UnivMathGate('XY', np.kron(mq.X.matrix(), mq.Y.matrix())).on([0, 1]) - >>> print(mq.Circuit() + g) + >>> import quafu + >>> from quafu.algorithm.compiler.decompose import tensor_product_decompose + >>> g = quafu.UnivMathGate('XY', np.kron(quafu.X.matrix(), quafu.Y.matrix())).on([0, 1]) + >>> print(quafu.Circuit() + g) ┏━━━━┓ q0: ──┨ ┠─── ┃ ┃ @@ -100,11 +100,11 @@ def abc_decompose(gate: QuantumGate, return_u3: bool = True) -> Circuit: :class:`~.core.circuit.Circuit`, including at most 2 CNOT gates and 4 single-qubit gates. Examples: - >>> import mindquantum as mq - >>> from mindquantum.algorithm.compiler.decompose import abc_decompose + >>> import quafu + >>> from quafu.algorithm.compiler.decompose import abc_decompose >>> from scipy.stats import unitary_group - >>> g = mq.UnivMathGate('U', unitary_group.rvs(2, random_state=123)).on(1, 0) - >>> print(mq.Circuit() + g) + >>> g = quafu.UnivMathGate('U', unitary_group.rvs(2, random_state=123)).on(1, 0) + >>> print(quafu.Circuit() + g) q0: ────■───── ┃ ┏━┻━┓ @@ -168,11 +168,11 @@ def kak_decompose(gate: QuantumGate, return_u3: bool = True) -> Circuit: :class:`~.core.circuit.Circuit`, including at most 3 CNOT gates and 6 single-qubit gates. Examples: - >>> import mindquantum as mq - >>> from mindquantum.algorithm.compiler.decompose import kak_decompose + >>> import quafu + >>> from quafu.algorithm.compiler.decompose import kak_decompose >>> from scipy.stats import unitary_group - >>> g = mq.UnivMathGate('U', unitary_group.rvs(4, random_state=123)).on([0, 1]) - >>> print(mq.Circuit() + g) + >>> g = quafu.UnivMathGate('U', unitary_group.rvs(4, random_state=123)).on([0, 1]) + >>> print(quafu.Circuit() + g) ┏━━━┓ q0: ──┨ ┠─── ┃ ┃ diff --git a/mindquantum/algorithm/compiler/decompose/utils.py b/quafu/algorithm/compiler/decompose/utils.py similarity index 98% rename from mindquantum/algorithm/compiler/decompose/utils.py rename to quafu/algorithm/compiler/decompose/utils.py index 46ad19455..cf930333a 100644 --- a/mindquantum/algorithm/compiler/decompose/utils.py +++ b/quafu/algorithm/compiler/decompose/utils.py @@ -21,10 +21,10 @@ import numpy as np from scipy import linalg -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import QuantumGate -from mindquantum.utils.f import is_power_of_two +from quafu.core import gates +from quafu.core.circuit import Circuit +from quafu.core.gates import QuantumGate +from quafu.utils.f import is_power_of_two M = np.array([[1, 0, 0, 1j], [0, 1j, 1, 0], [0, 1j, -1, 0], [1, 0, 0, -1j]]) / sqrt(2) diff --git a/mindquantum/algorithm/compiler/rules/__init__.py b/quafu/algorithm/compiler/rules/__init__.py similarity index 100% rename from mindquantum/algorithm/compiler/rules/__init__.py rename to quafu/algorithm/compiler/rules/__init__.py diff --git a/mindquantum/algorithm/compiler/rules/basic_decompose.py b/quafu/algorithm/compiler/rules/basic_decompose.py similarity index 97% rename from mindquantum/algorithm/compiler/rules/basic_decompose.py rename to quafu/algorithm/compiler/rules/basic_decompose.py index e2b408aab..4dc4a2384 100644 --- a/mindquantum/algorithm/compiler/rules/basic_decompose.py +++ b/quafu/algorithm/compiler/rules/basic_decompose.py @@ -14,8 +14,8 @@ # ============================================================================ """Decompose gate with control qubits.""" # pylint: disable=unused-argument -from mindquantum.core.circuit import controlled -from mindquantum.core.gates import ( +from quafu.core.circuit import controlled +from quafu.core.gates import ( RX, RY, RZ, @@ -34,7 +34,7 @@ YGate, ZGate, ) -from mindquantum.utils.type_value_check import _check_input_type +from quafu.utils.type_value_check import _check_input_type from ..dag import DAGCircuit from ..decompose import ( @@ -308,9 +308,9 @@ class BasicDecompose(BasicCompilerRule): prefer_u3 (bool): whether prefer to use :class:`~.core.gates.U3` gate to decompose gate. Default: ``False``. Examples: - >>> from mindquantum.algorithm.compiler import BasicDecompose, DAGCircuit - >>> from mindquantum.core import gates as G - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.algorithm.compiler import BasicDecompose, DAGCircuit + >>> from quafu.core import gates as G + >>> from quafu.core.circuit import Circuit >>> circ = Circuit([G.Rxx('a').on([0, 1]), G.X(0, [1, 2])]) >>> circ ┏━━━━━━━━┓ ┏━━━┓ diff --git a/mindquantum/algorithm/compiler/rules/basic_rule.py b/quafu/algorithm/compiler/rules/basic_rule.py similarity index 97% rename from mindquantum/algorithm/compiler/rules/basic_rule.py rename to quafu/algorithm/compiler/rules/basic_rule.py index 1b769b545..6b95ed584 100644 --- a/mindquantum/algorithm/compiler/rules/basic_rule.py +++ b/quafu/algorithm/compiler/rules/basic_rule.py @@ -16,7 +16,7 @@ import typing from abc import ABC, abstractmethod -from mindquantum.core.circuit import Circuit +from quafu.core.circuit import Circuit from ..dag import DAGCircuit from .compiler_logger import CompileLog as CLog @@ -191,9 +191,9 @@ def compile_circuit(compiler: BasicCompilerRule, circ: Circuit) -> Circuit: :class:`~.core.circuit.Circuit`, the final circuit compiled by given compiler. Examples: - >>> from mindquantum.algorithm.compiler import compile_circuit, BasicDecompose - >>> from mindquantum.core import gates as G - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.algorithm.compiler import compile_circuit, BasicDecompose + >>> from quafu.core import gates as G + >>> from quafu.core.circuit import Circuit >>> circ = Circuit([G.Rxx('a').on([0, 1]), G.X(0, [1, 2])]) >>> circ ┏━━━━━━━━┓ ┏━━━┓ diff --git a/mindquantum/algorithm/compiler/rules/compiler_logger.py b/quafu/algorithm/compiler/rules/compiler_logger.py similarity index 100% rename from mindquantum/algorithm/compiler/rules/compiler_logger.py rename to quafu/algorithm/compiler/rules/compiler_logger.py diff --git a/mindquantum/algorithm/compiler/rules/device_based.py b/quafu/algorithm/compiler/rules/device_based.py similarity index 100% rename from mindquantum/algorithm/compiler/rules/device_based.py rename to quafu/algorithm/compiler/rules/device_based.py diff --git a/mindquantum/algorithm/compiler/rules/gate_replacer.py b/quafu/algorithm/compiler/rules/gate_replacer.py similarity index 95% rename from mindquantum/algorithm/compiler/rules/gate_replacer.py rename to quafu/algorithm/compiler/rules/gate_replacer.py index 567a3335a..482702c17 100644 --- a/mindquantum/algorithm/compiler/rules/gate_replacer.py +++ b/quafu/algorithm/compiler/rules/gate_replacer.py @@ -13,8 +13,8 @@ # limitations under the License. # ============================================================================ """Convert cnot to cz.""" -from mindquantum.core.circuit import Circuit, apply -from mindquantum.core.gates import CNOT, BasicGate, X, Z +from quafu.core.circuit import Circuit, apply +from quafu.core.gates import CNOT, BasicGate, X, Z from ..dag import DAGCircuit from .basic_rule import BasicCompilerRule, SequentialCompiler @@ -33,9 +33,9 @@ class GateReplacer(BasicCompilerRule): wanted_example_circ (:class:`~.core.circuit.Circuit`): The quantum circuit you want. Examples: - >>> from mindquantum.algorithm.compiler import GateReplacer, compile_circuit - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import X + >>> from quafu.algorithm.compiler import GateReplacer, compile_circuit + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import X >>> circ = Circuit().x(1, 0).h(1).x(1, 2) >>> circ q0: ────■───────────────── diff --git a/mindquantum/algorithm/compiler/rules/neighbor_canceler.py b/quafu/algorithm/compiler/rules/neighbor_canceler.py similarity index 98% rename from mindquantum/algorithm/compiler/rules/neighbor_canceler.py rename to quafu/algorithm/compiler/rules/neighbor_canceler.py index 5fc9b9545..23367f0b1 100644 --- a/mindquantum/algorithm/compiler/rules/neighbor_canceler.py +++ b/quafu/algorithm/compiler/rules/neighbor_canceler.py @@ -13,7 +13,7 @@ # limitations under the License. # ============================================================================ """Neighbor canceler compiler rule.""" -from mindquantum.utils.type_value_check import _check_input_type +from quafu.utils.type_value_check import _check_input_type from ..dag import DAGCircuit, GateNode, try_merge from .basic_rule import BasicCompilerRule, KroneckerSeqCompiler diff --git a/mindquantum/algorithm/error_mitigation/__init__.py b/quafu/algorithm/error_mitigation/__init__.py similarity index 100% rename from mindquantum/algorithm/error_mitigation/__init__.py rename to quafu/algorithm/error_mitigation/__init__.py diff --git a/mindquantum/algorithm/error_mitigation/folding_circuit.py b/quafu/algorithm/error_mitigation/folding_circuit.py similarity index 95% rename from mindquantum/algorithm/error_mitigation/folding_circuit.py rename to quafu/algorithm/error_mitigation/folding_circuit.py index 2f3edfd0c..cb14daaa1 100644 --- a/mindquantum/algorithm/error_mitigation/folding_circuit.py +++ b/quafu/algorithm/error_mitigation/folding_circuit.py @@ -15,9 +15,9 @@ """Method to folding circuit.""" import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import NoiseGate, QuantumGate -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import Circuit +from quafu.core.gates import NoiseGate, QuantumGate +from quafu.utils.type_value_check import ( _check_input_type, _check_value_should_not_less, ) @@ -100,8 +100,8 @@ def fold_at_random(circ: Circuit, factor: float, method='locally') -> Circuit: means the identity part is randomly added after certain gate. Examples: - >>> from mindquantum.algorithm.error_mitigation import fold_at_random - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.algorithm.error_mitigation import fold_at_random + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().h(0).x(1, 0) >>> circ ┏━━━┓ diff --git a/mindquantum/algorithm/error_mitigation/mitigation.py b/quafu/algorithm/error_mitigation/mitigation.py similarity index 98% rename from mindquantum/algorithm/error_mitigation/mitigation.py rename to quafu/algorithm/error_mitigation/mitigation.py index 10971747c..9c140f964 100644 --- a/mindquantum/algorithm/error_mitigation/mitigation.py +++ b/quafu/algorithm/error_mitigation/mitigation.py @@ -17,7 +17,7 @@ import numpy as np -from mindquantum.core.circuit import Circuit +from quafu.core.circuit import Circuit from .folding_circuit import fold_at_random diff --git a/mindquantum/algorithm/error_mitigation/random_benchmarking.py b/quafu/algorithm/error_mitigation/random_benchmarking.py similarity index 88% rename from mindquantum/algorithm/error_mitigation/random_benchmarking.py rename to quafu/algorithm/error_mitigation/random_benchmarking.py index fb534cc12..e93ea6460 100644 --- a/mindquantum/algorithm/error_mitigation/random_benchmarking.py +++ b/quafu/algorithm/error_mitigation/random_benchmarking.py @@ -16,11 +16,11 @@ # pylint:disable=no-member import numpy as np -from mindquantum import _mq_vector -from mindquantum.core.circuit import Circuit -from mindquantum.simulator import Simulator, decompose_stabilizer -from mindquantum.simulator.stabilizer import Stabilizer -from mindquantum.utils.type_value_check import ( +from quafu import _quafu_vector +from quafu.core.circuit import Circuit +from quafu.simulator import Simulator, decompose_stabilizer +from quafu.simulator.stabilizer import Stabilizer +from quafu.utils.type_value_check import ( _check_int_type, _check_seed, _check_value_should_not_less, @@ -40,8 +40,8 @@ def query_single_qubit_clifford_elem(idx: int) -> Simulator: :class:`~.simulator.Simulator`, a stabilizer with tableau be the queried clifford element. Examples: - >>> from mindquantum.algorithm.error_mitigation import query_single_qubit_clifford_elem - >>> from mindquantum.simulator import decompose_stabilizer + >>> from quafu.algorithm.error_mitigation import query_single_qubit_clifford_elem + >>> from quafu.simulator import decompose_stabilizer >>> elem = query_single_qubit_clifford_elem(12) >>> decompose_stabilizer(elem) ┏━━━┓ ┏━━━┓ ┏━━━━┓ @@ -50,7 +50,7 @@ def query_single_qubit_clifford_elem(idx: int) -> Simulator: """ _check_int_type('idx', idx) _check_value_should_not_less("idx", 0, idx) - clifford = Stabilizer(_mq_vector.stabilizer.query_single_qubit_clifford_elem(idx), n_qubits=1, internal=True) + clifford = Stabilizer(_quafu_vector.stabilizer.query_single_qubit_clifford_elem(idx), n_qubits=1, internal=True) sim = Simulator('stabilizer', 1) sim.backend = clifford return sim @@ -69,8 +69,8 @@ def query_double_qubits_clifford_elem(idx: int) -> Simulator: :class:`~.simulator.Simulator`, a stabilizer with tableau be the queried clifford element. Examples: - >>> from mindquantum.algorithm.error_mitigation import query_double_qubits_clifford_elem - >>> from mindquantum.simulator import decompose_stabilizer + >>> from quafu.algorithm.error_mitigation import query_double_qubits_clifford_elem + >>> from quafu.simulator import decompose_stabilizer >>> elem = query_double_qubits_clifford_elem(11111) >>> decompose_stabilizer(elem) ┏━━━┓ ┏━━━━┓ ┏━━━┓ ┏━━━┓ @@ -82,7 +82,7 @@ def query_double_qubits_clifford_elem(idx: int) -> Simulator: """ _check_int_type('idx', idx) _check_value_should_not_less("idx", 0, idx) - clifford = Stabilizer(_mq_vector.stabilizer.query_double_qubits_clifford_elem(idx), n_qubits=2, internal=True) + clifford = Stabilizer(_quafu_vector.stabilizer.query_double_qubits_clifford_elem(idx), n_qubits=2, internal=True) sim = Simulator('stabilizer', 2) sim.backend = clifford return sim @@ -103,7 +103,7 @@ def generate_single_qubit_rb_circ(length: int, seed: int = None) -> Circuit: Examples: >>> import numpy as np - >>> from mindquantum.algorithm.error_mitigation import generate_single_qubit_rb_circ + >>> from quafu.algorithm.error_mitigation import generate_single_qubit_rb_circ >>> circ = generate_single_qubit_rb_circ(5, 42) >>> circ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ @@ -121,7 +121,7 @@ def generate_single_qubit_rb_circ(length: int, seed: int = None) -> Circuit: seed = int(np.random.randint(1, 2 << 20)) _check_seed(seed) - stabs = _mq_vector.stabilizer.generate_single_qubit_rb_circ(length, seed) + stabs = _quafu_vector.stabilizer.generate_single_qubit_rb_circ(length, seed) circ = Circuit() for stab in stabs: circ.barrier() @@ -144,7 +144,7 @@ def generate_double_qubits_rb_circ(length: int, seed: int = None) -> Circuit: Examples: >>> import numpy as np - >>> from mindquantum.algorithm.error_mitigation import generate_double_qubits_rb_circ + >>> from quafu.algorithm.error_mitigation import generate_double_qubits_rb_circ >>> circ = generate_double_qubits_rb_circ(3, 42) >>> circ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ @@ -174,7 +174,7 @@ def generate_double_qubits_rb_circ(length: int, seed: int = None) -> Circuit: seed = int(np.random.randint(1, 2 << 20)) _check_seed(seed) - stabs = _mq_vector.stabilizer.generate_double_qubits_rb_circ(length, seed) + stabs = _quafu_vector.stabilizer.generate_double_qubits_rb_circ(length, seed) circ = Circuit() for stab in stabs: circ.barrier() diff --git a/mindquantum/algorithm/error_mitigation/virtual_distillation.py b/quafu/algorithm/error_mitigation/virtual_distillation.py similarity index 96% rename from mindquantum/algorithm/error_mitigation/virtual_distillation.py rename to quafu/algorithm/error_mitigation/virtual_distillation.py index 250cc80c4..ad6d98945 100644 --- a/mindquantum/algorithm/error_mitigation/virtual_distillation.py +++ b/quafu/algorithm/error_mitigation/virtual_distillation.py @@ -15,8 +15,8 @@ """Virtual Distillation Algorithm for error mitigation.""" from typing import Callable, Dict -from mindquantum.core.circuit import Circuit, apply -from mindquantum.core.gates import Givens, SWAP +from quafu.core.circuit import Circuit, apply +from quafu.core.gates import Givens, SWAP import numpy as np @@ -49,7 +49,7 @@ def virtual_distillation( Examples: >>> circ = Circuit([X.on(0), RY(1).on(1)]) - >>> sim = Simulator('mqvector', 4) # Double number of qubits + >>> sim = Simulator('quafuvector', 4) # Double number of qubits >>> def executor(circ): ... res_dict = sim.sampling(circ, shots=10000).data ... return res_dict diff --git a/mindquantum/algorithm/library/__init__.py b/quafu/algorithm/library/__init__.py similarity index 100% rename from mindquantum/algorithm/library/__init__.py rename to quafu/algorithm/library/__init__.py diff --git a/mindquantum/algorithm/library/amplitude_encoder.py b/quafu/algorithm/library/amplitude_encoder.py similarity index 88% rename from mindquantum/algorithm/library/amplitude_encoder.py rename to quafu/algorithm/library/amplitude_encoder.py index 376f0508c..935614815 100644 --- a/mindquantum/algorithm/library/amplitude_encoder.py +++ b/quafu/algorithm/library/amplitude_encoder.py @@ -15,11 +15,11 @@ """Amplitude encoder for quantum machine learning.""" import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import RY, RZ, X -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.utils.type_value_check import _check_input_type -from mindquantum.utils import normalize +from quafu.core.circuit import Circuit +from quafu.core.gates import RY, RZ, X +from quafu.core.parameterresolver import ParameterResolver +from quafu.utils.type_value_check import _check_input_type +from quafu.utils import normalize def amp_circuit(n_qubits): @@ -65,9 +65,9 @@ def amplitude_encoder(x, n_qubits): amplitude encoder. Examples: - >>> from mindquantum.algorithm.library import amplitude_encoder - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 2) + >>> from quafu.algorithm.library import amplitude_encoder + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 2) >>> encoder, parameterResolver = amplitude_encoder([0.5, -0.5, -0.5j, -0.5j], 2) >>> sim.apply_circuit(encoder, parameterResolver) >>> print(sim.get_qs(True)) @@ -77,7 +77,7 @@ def amplitude_encoder(x, n_qubits): -1/2j¦11⟩ >>> sim.reset() >>> encoder, parameterResolver = amplitude_encoder([0, -0.5j, -0.5j, -0.5, 0.5], 3) - >>> sim = Simulator('mqvector', 3) + >>> sim = Simulator('quafuvector', 3) >>> sim.apply_circuit(encoder, parameterResolver) >>> print(sim.get_qs(True)) -1/2j¦001⟩ diff --git a/mindquantum/algorithm/library/bitphaseflip_operator.py b/quafu/algorithm/library/bitphaseflip_operator.py similarity index 88% rename from mindquantum/algorithm/library/bitphaseflip_operator.py rename to quafu/algorithm/library/bitphaseflip_operator.py index 7b051e54f..6f0c55630 100644 --- a/mindquantum/algorithm/library/bitphaseflip_operator.py +++ b/quafu/algorithm/library/bitphaseflip_operator.py @@ -17,9 +17,9 @@ """Bitphaseflip operator.""" -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import Z -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core.circuit import Circuit +from quafu.core.gates import Z +from quafu.utils.type_value_check import _check_input_type def bitphaseflip_operator(phase_inversion_index, n_qubits): # pylint: disable=too-many-branches @@ -31,9 +31,9 @@ def bitphaseflip_operator(phase_inversion_index, n_qubits): # pylint: disable=t n_qubits (int): Total number of qubits. Examples: - >>> from mindquantum.core.circuit import Circuit, UN - >>> from mindquantum.core.gates import H, Z - >>> from mindquantum.algorithm.library import bitphaseflip_operator + >>> from quafu.core.circuit import Circuit, UN + >>> from quafu.core.gates import H, Z + >>> from quafu.algorithm.library import bitphaseflip_operator >>> circuit = Circuit() >>> circuit += UN(H, 3) >>> circuit += bitphaseflip_operator([1, 3], 3) diff --git a/mindquantum/algorithm/library/general_ghz_state.py b/quafu/algorithm/library/general_ghz_state.py similarity index 88% rename from mindquantum/algorithm/library/general_ghz_state.py rename to quafu/algorithm/library/general_ghz_state.py index 9a9f5d1a9..e0573ab9b 100644 --- a/mindquantum/algorithm/library/general_ghz_state.py +++ b/quafu/algorithm/library/general_ghz_state.py @@ -14,9 +14,9 @@ # ============================================================================ """General GHZ State.""" -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import H, X -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core.circuit import Circuit +from quafu.core.gates import H, X +from quafu.utils.type_value_check import _check_input_type def general_ghz_state(qubits): @@ -40,7 +40,7 @@ def general_ghz_state(qubits): Circuit, circuit that can prepare ghz state. Examples: - >>> from mindquantum.algorithm.library import general_ghz_state + >>> from quafu.algorithm.library import general_ghz_state >>> print(general_ghz_state(range(3)).get_qs(ket=True)) √2/2¦000⟩ √2/2¦111⟩ diff --git a/mindquantum/algorithm/library/general_w_state.py b/quafu/algorithm/library/general_w_state.py similarity index 90% rename from mindquantum/algorithm/library/general_w_state.py rename to quafu/algorithm/library/general_w_state.py index 4ba8c6a94..439026a2b 100644 --- a/mindquantum/algorithm/library/general_w_state.py +++ b/quafu/algorithm/library/general_w_state.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import RY, X -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core.circuit import Circuit +from quafu.core.gates import RY, X +from quafu.utils.type_value_check import _check_input_type def general_w_state(qubits): @@ -41,7 +41,7 @@ def general_w_state(qubits): qubits (list[int]): Qubits you want to apply general W state. Examples: - >>> from mindquantum.algorithm.library import general_w_state + >>> from quafu.algorithm.library import general_w_state >>> print(general_w_state(range(3)).get_qs(ket=True)) 0.5773502691896257¦001⟩ 0.5773502691896258¦010⟩ diff --git a/mindquantum/algorithm/library/qjpeg.py b/quafu/algorithm/library/qjpeg.py similarity index 91% rename from mindquantum/algorithm/library/qjpeg.py rename to quafu/algorithm/library/qjpeg.py index 73235007c..741b982b5 100644 --- a/mindquantum/algorithm/library/qjpeg.py +++ b/quafu/algorithm/library/qjpeg.py @@ -15,9 +15,9 @@ """QJPEG algorithm for quantum figure compression.""" from typing import Tuple, List -from mindquantum.algorithm.library.quantum_fourier import qft -from mindquantum.core.circuit import Circuit, dagger -from mindquantum.utils.type_value_check import _check_int_type, _check_value_should_not_less +from quafu.algorithm.library.quantum_fourier import qft +from quafu.core.circuit import Circuit, dagger +from quafu.utils.type_value_check import _check_int_type, _check_value_should_not_less def qjpeg(n_qubits: int, m_qubits: int) -> Tuple[Circuit, List[int], List[int]]: @@ -38,7 +38,7 @@ def qjpeg(n_qubits: int, m_qubits: int) -> Tuple[Circuit, List[int], List[int]]: - List[int], List of indices for discarded qubits Examples: - >>> from mindquantum import Simulator, normalize + >>> from quafu import Simulator, normalize >>> import numpy as np >>> n_qubits = 4 >>> m_qubits = 2 @@ -47,7 +47,7 @@ def qjpeg(n_qubits: int, m_qubits: int) -> Tuple[Circuit, List[int], List[int]]: [0, 2] [1, 3] >>> data = np.array([[1,0,0,0], [1,1,0,0], [1,1,1,0], [1,1,1,1]]) >>> state = normalize(data.reshape(-1)) - >>> sim = Simulator('mqmatrix', n_qubits) + >>> sim = Simulator('quafumatrix', n_qubits) >>> sim.set_qs(state) >>> sim.apply_circuit(circ) >>> rho = sim.get_partial_trace(discard_qubits) diff --git a/mindquantum/algorithm/library/quantum_fourier.py b/quafu/algorithm/library/quantum_fourier.py similarity index 89% rename from mindquantum/algorithm/library/quantum_fourier.py rename to quafu/algorithm/library/quantum_fourier.py index 03c100def..1a25c3729 100644 --- a/mindquantum/algorithm/library/quantum_fourier.py +++ b/quafu/algorithm/library/quantum_fourier.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.core.circuit import Circuit, SwapParts -from mindquantum.core.gates import H, PhaseShift -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core.circuit import Circuit, SwapParts +from quafu.core.gates import H, PhaseShift +from quafu.utils.type_value_check import _check_input_type def _rn(k): @@ -45,7 +45,7 @@ def qft(qubits): qubits (list[int]): Qubits you want to apply quantum fourier transform. Examples: - >>> from mindquantum.algorithm.library import qft + >>> from quafu.algorithm.library import qft >>> print(qft([0, 1]).get_qs(ket=True)) 1/2¦00⟩ 1/2¦01⟩ diff --git a/mindquantum/algorithm/library/qudit_mapping.py b/quafu/algorithm/library/qudit_mapping.py similarity index 96% rename from mindquantum/algorithm/library/qudit_mapping.py rename to quafu/algorithm/library/qudit_mapping.py index cfcbe237f..f69060bd9 100644 --- a/mindquantum/algorithm/library/qudit_mapping.py +++ b/quafu/algorithm/library/qudit_mapping.py @@ -18,12 +18,12 @@ import numpy as np import scipy as sp from scipy.sparse import csr_matrix -from mindquantum.utils.f import is_power_of_two -from mindquantum.core import QubitOperator +from quafu.utils.f import is_power_of_two +from quafu.core import QubitOperator -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import X, RX, RY, RZ, U3, GlobalPhase, UnivMathGate -from mindquantum.utils.type_value_check import _check_input_type, _check_int_type, _check_value_should_not_less +from quafu.core.circuit import Circuit +from quafu.core.gates import X, RX, RY, RZ, U3, GlobalPhase, UnivMathGate +from quafu.utils.type_value_check import _check_input_type, _check_int_type, _check_value_should_not_less optional_basis = ["zyz", "u3"] @@ -41,7 +41,7 @@ def _symmetric_state_index(dim: int, n_qudits: int) -> dict: values are the corresponding index of qubit symmetric state or matrix. Examples: - >>> from mindquantum.algorithm.library.qudit_mapping import _symmetric_state_index + >>> from quafu.algorithm.library.qudit_mapping import _symmetric_state_index >>> _symmetric_state_index(dim=3, n_qudits=1) {0: [0], 1: [1, 2], 2: [3]} >>> _symmetric_state_index(dim=4, n_qudits=1) @@ -158,7 +158,7 @@ def qudit_symmetric_decoding(qubit: np.ndarray, n_qubits: int = 1) -> np.ndarray Examples: >>> import numpy as np - >>> from mindquantum.algorithm.library.qudit_mapping import qudit_symmetric_decoding + >>> from quafu.algorithm.library.qudit_mapping import qudit_symmetric_decoding >>> # A symmetric qubit state where amplitudes in |01⟩ and |10⟩ are equal >>> qubit = np.array([1., 2., 2., 3.]) >>> qubit /= np.linalg.norm(qubit) @@ -233,7 +233,7 @@ def qudit_symmetric_encoding(qudit: np.ndarray, n_qudits: int = 1, is_csr: bool Examples: >>> import numpy as np - >>> from mindquantum.algorithm.library.qudit_mapping import qudit_symmetric_encoding + >>> from quafu.algorithm.library.qudit_mapping import qudit_symmetric_encoding >>> qudit = np.array([1., 2., 3.]) >>> qudit /= np.linalg.norm(qudit) >>> print(qudit) @@ -509,9 +509,9 @@ def qutrit_symmetric_ansatz(gate: UnivMathGate, basis: str = "zyz", with_phase: Examples: >>> from scipy.stats import unitary_group - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import UnivMathGate - >>> from mindquantum.algorithm import qutrit_symmetric_ansatz, qudit_symmetric_encoding + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import UnivMathGate + >>> from quafu.algorithm import qutrit_symmetric_ansatz, qudit_symmetric_encoding >>> qutrit_unitary = unitary_group.rvs(3) >>> qubit_unitary = qudit_symmetric_encoding(qutrit_unitary) >>> qubit_gate = UnivMathGate('U', qubit_unitary).on([0, 1]) @@ -578,7 +578,7 @@ def mat_to_op(mat, little_endian: bool = True) -> QubitOperator: Examples: >>> import numpy as np - >>> from mindquantum.algorithm.library.qudit_mapping import mat_to_op + >>> from quafu.algorithm.library.qudit_mapping import mat_to_op >>> mat = np.array([[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]) >>> print(mat_to_op(mat, 2)) 1 [] + diff --git a/mindquantum/algorithm/mapping/__init__.py b/quafu/algorithm/mapping/__init__.py similarity index 91% rename from mindquantum/algorithm/mapping/__init__.py rename to quafu/algorithm/mapping/__init__.py index 6cddc3742..aaf994108 100644 --- a/mindquantum/algorithm/mapping/__init__.py +++ b/quafu/algorithm/mapping/__init__.py @@ -13,8 +13,8 @@ # limitations under the License. # ============================================================================ """Qubit mapping module.""" -from .mq_sabre import MQSABRE +from .quafu_sabre import QUAFUSABRE from .sabre import SABRE -__all__ = ["SABRE", "MQSABRE"] +__all__ = ["SABRE", "QUAFUSABRE"] __all__.sort() diff --git a/mindquantum/algorithm/mapping/mq_sabre.py b/quafu/algorithm/mapping/mq_sabre.py similarity index 90% rename from mindquantum/algorithm/mapping/mq_sabre.py rename to quafu/algorithm/mapping/mq_sabre.py index fe3b71b4d..b90e87aaf 100644 --- a/mindquantum/algorithm/mapping/mq_sabre.py +++ b/quafu/algorithm/mapping/mq_sabre.py @@ -13,20 +13,20 @@ # limitations under the License. # ============================================================================ -"""MQSABRE algorithm to implement qubit mapping.""" +"""QUAFUSABRE algorithm to implement qubit mapping.""" import typing from typing import List, Tuple from ...core.circuit import Circuit from ...core.gates import SWAP from ...device import QubitsTopology -from ...mqbackend.device import MQ_SABRE as MQ_SABRE_ # pylint: disable=import-error +from ...quafubackend.device import QUAFU_SABRE as QUAFU_SABRE_ # pylint: disable=import-error # pylint: disable=too-few-public-methods -class MQSABRE: +class QUAFUSABRE: """ - MQSABRE algorithm to implement qubit mapping. + QUAFUSABRE algorithm to implement qubit mapping. This mapping alrogrthm considered the cnot error and executing time in quantum chip. @@ -40,10 +40,10 @@ class MQSABRE: error of cnot and second one be the gate length. Examples: - >>> from mindquantum.algorithm.mapping import MQSABRE + >>> from quafu.algorithm.mapping import QUAFUSABRE >>> cnot=[((5, 6), [8.136e-4, 248.88]), ((6, 10), [9.136e-4, 248.88]), ((8, 9), [9.136e-4, 248.88])] >>> topology = GridQubits(6,6) - >>> mqsaber = MQSABRE(circuit, topology, cnot) + >>> quafusaber = QUAFUSABRE(circuit, topology, cnot) >>> new_circ, init_mapping, final_mapping = masaber.solve(1, 0.3, 0.2, 0.1) """ @@ -54,7 +54,7 @@ def __init__( self.circuit = circuit self.topology = topology self.cnoterrorandlength = cnoterrorandlength - self.cpp_solver = MQ_SABRE_( + self.cpp_solver = QUAFU_SABRE_( self.circuit.get_cpp_obj(), self.topology.__get_cpp_obj__(), self.cnoterrorandlength ) @@ -65,7 +65,7 @@ def check_connected(topology: QubitsTopology) -> bool: return False edges = topology.edges_with_id() graph = {qid: [] for qid in qids} - for (x, y) in edges: + for x, y in edges: graph[x].append(y) graph[y].append(x) @@ -90,7 +90,7 @@ def solve( self, w: float, alpha1: float, alpha2: float, alpha3: float ) -> typing.Union[Circuit, typing.List[int], typing.List[int]]: """ - Solve qubit mapping problem with MQSABRE algorithm. + Solve qubit mapping problem with QUAFUSABRE algorithm. Args: w (float): The w parameter. For more detail, please refers to the paper. diff --git a/mindquantum/algorithm/mapping/sabre.py b/quafu/algorithm/mapping/sabre.py similarity index 97% rename from mindquantum/algorithm/mapping/sabre.py rename to quafu/algorithm/mapping/sabre.py index 7ad65c292..42c6213b0 100644 --- a/mindquantum/algorithm/mapping/sabre.py +++ b/quafu/algorithm/mapping/sabre.py @@ -18,7 +18,7 @@ from ...core.circuit import Circuit from ...core.gates import SWAP from ...device import QubitsTopology -from ...mqbackend.device import SABRE as SABRE_ # pylint: disable=import-error +from ...quafubackend.device import SABRE as SABRE_ # pylint: disable=import-error # pylint: disable=too-few-public-methods @@ -49,7 +49,7 @@ def check_connected(topology: QubitsTopology) -> bool: return False edges = topology.edges_with_id() graph = {qid: [] for qid in qids} - for (x, y) in edges: + for x, y in edges: graph[x].append(y) graph[y].append(x) diff --git a/mindquantum/algorithm/nisq/__init__.py b/quafu/algorithm/nisq/__init__.py similarity index 100% rename from mindquantum/algorithm/nisq/__init__.py rename to quafu/algorithm/nisq/__init__.py diff --git a/mindquantum/algorithm/nisq/_ansatz.py b/quafu/algorithm/nisq/_ansatz.py similarity index 94% rename from mindquantum/algorithm/nisq/_ansatz.py rename to quafu/algorithm/nisq/_ansatz.py index 6c0c85451..8c464774a 100644 --- a/mindquantum/algorithm/nisq/_ansatz.py +++ b/quafu/algorithm/nisq/_ansatz.py @@ -18,10 +18,10 @@ import typing from abc import abstractmethod -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import NoneParameterGate, ParameterGate -from mindquantum.core.parameterresolver import PRGenerator -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import Circuit +from quafu.core.gates import NoneParameterGate, ParameterGate +from quafu.core.parameterresolver import PRGenerator +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, diff --git a/mindquantum/algorithm/nisq/barren_plateau.py b/quafu/algorithm/nisq/barren_plateau.py similarity index 88% rename from mindquantum/algorithm/nisq/barren_plateau.py rename to quafu/algorithm/nisq/barren_plateau.py index 175c4fae0..db0db6670 100644 --- a/mindquantum/algorithm/nisq/barren_plateau.py +++ b/quafu/algorithm/nisq/barren_plateau.py @@ -17,9 +17,9 @@ import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.operators import Hamiltonian -from mindquantum.simulator import Simulator +from quafu.core.circuit import Circuit +from quafu.core.operators import Hamiltonian +from quafu.simulator import Simulator # pylint: disable=too-many-arguments,too-many-locals @@ -31,7 +31,7 @@ def ansatz_variance( other_var: np.array = None, atol: float = 0.1, init_batch: int = 20, - sim: typing.Union[Simulator, str] = 'mqvector', + sim: typing.Union[Simulator, str] = 'quafuvector', ): r""" Calculate the variance of the gradient of certain parameters of parameterized quantum circuit. @@ -46,14 +46,14 @@ def ansatz_variance( it will be random number at every sampling. Default: ``None``. atol (float): Tolerance for variance when samping. Default: ``0.1``. init_batch (int): Initial sampling size. Default: ``20``. - sim (Union[:class:`~.simulator.Simulator`, str]): Simulator you want to use. Default: ``mqvector``. + sim (Union[:class:`~.simulator.Simulator`, str]): Simulator you want to use. Default: ``quafuvector``. Examples: >>> import numpy as np - >>> from mindquantum.algorithm.nisq import ansatz_variance - >>> from mindquantum.algorithm.nisq.chem import HardwareEfficientAnsatz - >>> from mindquantum.core.gates import RY, RZ, Z - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator + >>> from quafu.algorithm.nisq import ansatz_variance + >>> from quafu.algorithm.nisq.chem import HardwareEfficientAnsatz + >>> from quafu.core.gates import RY, RZ, Z + >>> from quafu.core.operators import Hamiltonian, QubitOperator >>> np.random.seed(42) >>> ham = Hamiltonian(QubitOperator('Z0 Z1')) >>> q_list = [4, 6, 8, 10] diff --git a/mindquantum/algorithm/nisq/chem/__init__.py b/quafu/algorithm/nisq/chem/__init__.py similarity index 97% rename from mindquantum/algorithm/nisq/chem/__init__.py rename to quafu/algorithm/nisq/chem/__init__.py index 9021e4268..3839c2256 100644 --- a/mindquantum/algorithm/nisq/chem/__init__.py +++ b/quafu/algorithm/nisq/chem/__init__.py @@ -15,7 +15,7 @@ """Algorithm for quantum chemistry.""" -from mindquantum.third_party.unitary_cc import ( +from quafu.third_party.unitary_cc import ( uccsd_singlet_generator, uccsd_singlet_get_packed_amplitudes, ) diff --git a/mindquantum/algorithm/nisq/chem/hardware_efficient_ansatz.py b/quafu/algorithm/nisq/chem/hardware_efficient_ansatz.py similarity index 96% rename from mindquantum/algorithm/nisq/chem/hardware_efficient_ansatz.py rename to quafu/algorithm/nisq/chem/hardware_efficient_ansatz.py index 4879d7e95..757b2c964 100644 --- a/mindquantum/algorithm/nisq/chem/hardware_efficient_ansatz.py +++ b/quafu/algorithm/nisq/chem/hardware_efficient_ansatz.py @@ -18,9 +18,9 @@ import numpy as np -from mindquantum.core.circuit import AP, A, Circuit, add_prefix, add_suffix -from mindquantum.core.gates import BasicGate, X -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import AP, A, Circuit, add_prefix, add_suffix +from quafu.core.gates import BasicGate, X +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -69,8 +69,8 @@ class HardwareEfficientAnsatz(Ansatz): suffix (str): The suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import HardwareEfficientAnsatz - >>> from mindquantum.core.gates import RY, RZ, Z + >>> from quafu.algorithm.nisq import HardwareEfficientAnsatz + >>> from quafu.core.gates import RY, RZ, Z >>> hea = HardwareEfficientAnsatz(3, [RY, RZ], Z, [(0, 1), (0, 2)]) >>> hea.circuit ┏━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━┓ diff --git a/mindquantum/algorithm/nisq/chem/more_hardware_efficient_ansatz.py b/quafu/algorithm/nisq/chem/more_hardware_efficient_ansatz.py similarity index 98% rename from mindquantum/algorithm/nisq/chem/more_hardware_efficient_ansatz.py rename to quafu/algorithm/nisq/chem/more_hardware_efficient_ansatz.py index fc32a18b4..024079108 100644 --- a/mindquantum/algorithm/nisq/chem/more_hardware_efficient_ansatz.py +++ b/quafu/algorithm/nisq/chem/more_hardware_efficient_ansatz.py @@ -20,13 +20,13 @@ # pylint: disable=arguments-differ,too-few-public-methods import numpy as np -from mindquantum.algorithm.nisq._ansatz import ( +from quafu.algorithm.nisq._ansatz import ( Ansatz, Initializer, single_qubit_gate_layer, ) -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import RX, RY, RZ, FSim, X +from quafu.core.circuit import Circuit +from quafu.core.gates import RX, RY, RZ, FSim, X class RYLinear(Ansatz, Initializer): @@ -46,7 +46,7 @@ class RYLinear(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import RYLinear + >>> from quafu.algorithm.nisq import RYLinear >>> RYLinear(3, 2, prefix='a').circuit ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ q0: ──┨ RY(a_p0) ┠───■─────────┨ RY(a_p3) ┠───■─────────┨ RY(a_p6) ┠─── @@ -94,7 +94,7 @@ class RYFull(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import RYFull + >>> from quafu.algorithm.nisq import RYFull >>> RYFull(3, 2, prefix='a').circuit ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ q0: ──┨ RY(a_p0) ┠───■─────■─────────┨ RY(a_p3) ┠───■─────■─────────┨ RY(a_p6) ┠─── @@ -139,7 +139,7 @@ class RYRZFull(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import RYRZFull + >>> from quafu.algorithm.nisq import RYRZFull >>> RYRZFull(3, 1, prefix='a').circuit ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ q0: ──┨ RY(a_p0) ┠─┨ RZ(a_p3) ┠───■─────■─────────┨ RY(a_p6) ┠─┨ RZ(a_p9) ┠──── @@ -190,7 +190,7 @@ class RYCascade(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import RYCascade + >>> from quafu.algorithm.nisq import RYCascade >>> RYCascade(3, 1, prefix='a').circuit ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━━┓ q0: ──┨ RY(a_p0) ┠───■─────────┨ RY(a_p3) ┠─────────■───┨ RY(a_p6) ┠─── @@ -242,7 +242,7 @@ class ASWAP(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import ASWAP + >>> from quafu.algorithm.nisq import ASWAP >>> ASWAP(3, 1, prefix='a').circuit ┏━━━┓ q0: ──┨╺╋╸┠───────────────────────────────────────────────────■──────────────────────────────↯─ @@ -317,7 +317,7 @@ class PCHeaXYZ1F(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import PCHeaXYZ1F + >>> from quafu.algorithm.nisq import PCHeaXYZ1F >>> PCHeaXYZ1F(3, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RY(p3) ┠─────────────────┨ ┠────────────────────────────────↯─ @@ -399,7 +399,7 @@ class PCHeaXYZ2F(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import PCHeaXYZ2F + >>> from quafu.algorithm.nisq import PCHeaXYZ2F >>> PCHeaXYZ2F(3, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RY(p3) ┠─────────────────┨ ┠────────────────────────────────↯─ diff --git a/mindquantum/algorithm/nisq/chem/qubit_hamiltonian.py b/quafu/algorithm/nisq/chem/qubit_hamiltonian.py similarity index 93% rename from mindquantum/algorithm/nisq/chem/qubit_hamiltonian.py rename to quafu/algorithm/nisq/chem/qubit_hamiltonian.py index 2b86ae33c..40bbfa422 100644 --- a/mindquantum/algorithm/nisq/chem/qubit_hamiltonian.py +++ b/quafu/algorithm/nisq/chem/qubit_hamiltonian.py @@ -14,7 +14,7 @@ # ============================================================================ """Get qubit hamiltonian.""" -from mindquantum.core.operators import FermionOperator, InteractionOperator +from quafu.core.operators import FermionOperator, InteractionOperator from .transform import Transform diff --git a/mindquantum/algorithm/nisq/chem/qubit_ucc_ansatz.py b/quafu/algorithm/nisq/chem/qubit_ucc_ansatz.py similarity index 97% rename from mindquantum/algorithm/nisq/chem/qubit_ucc_ansatz.py rename to quafu/algorithm/nisq/chem/qubit_ucc_ansatz.py index 37f741cbe..f037be1f4 100644 --- a/mindquantum/algorithm/nisq/chem/qubit_ucc_ansatz.py +++ b/quafu/algorithm/nisq/chem/qubit_ucc_ansatz.py @@ -22,10 +22,10 @@ import numpy -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import CNOT, RY, X -from mindquantum.core.operators import QubitExcitationOperator, hermitian_conjugated -from mindquantum.core.parameterresolver import ParameterResolver +from quafu.core.circuit import Circuit +from quafu.core.gates import CNOT, RY, X +from quafu.core.operators import QubitExcitationOperator, hermitian_conjugated +from quafu.core.parameterresolver import ParameterResolver from .._ansatz import Ansatz @@ -75,7 +75,7 @@ class QubitUCCAnsatz(Ansatz): good accuracy. Default: ``1``. Examples: - >>> from mindquantum.algorithm.nisq import QubitUCCAnsatz + >>> from quafu.algorithm.nisq import QubitUCCAnsatz >>> QubitUCCAnsatz().n_qubits 0 >>> qucc = QubitUCCAnsatz(4, 2, trotter_step=2) @@ -249,7 +249,7 @@ def _implement( for trotter_idx in range(trotter_step): singles_counter = 0 # pylint: disable=invalid-name - for (p, q) in itertools.product(vir_indices_spin, occ_indices_spin): + for p, q in itertools.product(vir_indices_spin, occ_indices_spin): coeff_s = ParameterResolver({f't_{trotter_idx}_q_s_{singles_counter}': 1}) q_pq = QubitExcitationOperator(((p, 1), (q, 0)), 1.0) q_pq = q_pq - hermitian_conjugated(q_pq) diff --git a/mindquantum/algorithm/nisq/chem/quccsd.py b/quafu/algorithm/nisq/chem/quccsd.py similarity index 96% rename from mindquantum/algorithm/nisq/chem/quccsd.py rename to quafu/algorithm/nisq/chem/quccsd.py index 8d54ee406..3d0cfb49b 100644 --- a/mindquantum/algorithm/nisq/chem/quccsd.py +++ b/quafu/algorithm/nisq/chem/quccsd.py @@ -22,8 +22,8 @@ import numpy -from mindquantum.core.operators import QubitExcitationOperator, hermitian_conjugated -from mindquantum.core.parameterresolver import ParameterResolver +from quafu.core.operators import QubitExcitationOperator, hermitian_conjugated +from quafu.core.parameterresolver import ParameterResolver def _check_int_list(input_list, name): @@ -62,7 +62,7 @@ def quccsd_generator( QubitExcitationOperator, Generator of the qUCCSD operators. Examples: - >>> from mindquantum.algorithm.nisq import quccsd_generator + >>> from quafu.algorithm.nisq import quccsd_generator >>> quccsd_generator() 0 >>> quccsd_generator(4, 2) @@ -174,7 +174,7 @@ def quccsd_generator( singles_counter = 0 # pylint: disable=invalid-name - for (p, q) in itertools.product(vir_indices_spin, occ_indices_spin): + for p, q in itertools.product(vir_indices_spin, occ_indices_spin): coeff_s = ParameterResolver({f'q_s_{singles_counter}': 1}) q_pq = QubitExcitationOperator(((p, 1), (q, 0)), 1.0) if anti_hermitian: diff --git a/mindquantum/algorithm/nisq/chem/reference_state.py b/quafu/algorithm/nisq/chem/reference_state.py similarity index 96% rename from mindquantum/algorithm/nisq/chem/reference_state.py rename to quafu/algorithm/nisq/chem/reference_state.py index 26b1f35c5..325880606 100644 --- a/mindquantum/algorithm/nisq/chem/reference_state.py +++ b/quafu/algorithm/nisq/chem/reference_state.py @@ -29,9 +29,9 @@ import numpy as np -from mindquantum.core.circuit import UN, Circuit -from mindquantum.core.gates import BarrierGate, H, X -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import UN, Circuit +from quafu.core.gates import BarrierGate, H, X +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -75,7 +75,7 @@ def get_reference_circuit( of int, and we place a :class:`~.core.gates.RX` gate on each qubit. Default: ``'AllH'``. Examples: - >>> from mindquantum.algorithm.nisq import get_reference_circuit + >>> from quafu.algorithm.nisq import get_reference_circuit >>> get_reference_circuit(4, 1, 1, 'HF') ┏━━━┓ q0: ──┨╺╋╸┠─▓─── diff --git a/mindquantum/algorithm/nisq/chem/transform.py b/quafu/algorithm/nisq/chem/transform.py similarity index 97% rename from mindquantum/algorithm/nisq/chem/transform.py rename to quafu/algorithm/nisq/chem/transform.py index 6ccc1511a..edbdb8c6f 100644 --- a/mindquantum/algorithm/nisq/chem/transform.py +++ b/quafu/algorithm/nisq/chem/transform.py @@ -17,10 +17,10 @@ Thus can be simulated in quantum computer. """ -from mindquantum import _math +from quafu import _math # pylint: disable=no-member,protected-access -from mindquantum.core.operators.utils import ( +from quafu.core.operators.utils import ( FermionOperator, QubitOperator, count_qubits, @@ -43,12 +43,12 @@ class Transform: Default: ``None``. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> op1 = FermionOperator('1^') >>> op1 1.0 [1^] >>> op_transform = Transform(op1) - >>> from mindquantum.algorithm.nisq import Transform + >>> from quafu.algorithm.nisq import Transform >>> op_transform.jordan_wigner() 0.5 [Z0 X1] + -0.5j [Z0 Y1] diff --git a/mindquantum/algorithm/nisq/chem/uccsd.py b/quafu/algorithm/nisq/chem/uccsd.py similarity index 96% rename from mindquantum/algorithm/nisq/chem/uccsd.py rename to quafu/algorithm/nisq/chem/uccsd.py index 7b599c35c..0853bcd12 100644 --- a/mindquantum/algorithm/nisq/chem/uccsd.py +++ b/quafu/algorithm/nisq/chem/uccsd.py @@ -19,10 +19,10 @@ import numpy as np -from mindquantum.core.circuit import Circuit, decompose_single_term_time_evolution -from mindquantum.core.operators import FermionOperator, down_index, up_index -from mindquantum.third_party.interaction_operator import InteractionOperator -from mindquantum.utils.type_value_check import _require_package +from quafu.core.circuit import Circuit, decompose_single_term_time_evolution +from quafu.core.operators import FermionOperator, down_index, up_index +from quafu.third_party.interaction_operator import InteractionOperator +from quafu.utils.type_value_check import _require_package from .transform import Transform @@ -120,7 +120,7 @@ def _para_uccsd_singlet_generator(mol, threshold=0): # pylint: disable=too-many double2_amps_name = 'p' + str(i + 2 * n_single_amplitudes) # Generate double excitations - for (spin_a, spin_b) in itertools.product(range(2), repeat=2): + for spin_a, spin_b in itertools.product(range(2), repeat=2): # Get the functions which map a spatial orbital index to a # spin orbital index index_a = spin_index_functions[spin_a] diff --git a/mindquantum/algorithm/nisq/chem/uccsd0.py b/quafu/algorithm/nisq/chem/uccsd0.py similarity index 93% rename from mindquantum/algorithm/nisq/chem/uccsd0.py rename to quafu/algorithm/nisq/chem/uccsd0.py index 0e7b7c229..bfe43776b 100644 --- a/mindquantum/algorithm/nisq/chem/uccsd0.py +++ b/quafu/algorithm/nisq/chem/uccsd0.py @@ -21,13 +21,13 @@ import numpy -from mindquantum.core.operators import ( +from quafu.core.operators import ( FermionOperator, TermValue, hermitian_conjugated, normal_ordered, ) -from mindquantum.core.parameterresolver import ParameterResolver +from quafu.core.parameterresolver import ParameterResolver def _check_int_list(input_list, name): @@ -42,7 +42,7 @@ def _pij(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ # pylint: disable=invalid-name ia = i * 2 + 0 @@ -58,7 +58,7 @@ def _pij_dagger(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ return hermitian_conjugated(_pij(i, j)) @@ -67,7 +67,7 @@ def _qij_plus(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ # pylint: disable=invalid-name ia = i * 2 + 0 @@ -79,7 +79,7 @@ def _qij_minus(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ # pylint: disable=invalid-name ib = i * 2 + 1 @@ -91,7 +91,7 @@ def _qij_0(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ # pylint: disable=invalid-name ia = i * 2 + 0 @@ -107,7 +107,7 @@ def _qij_vec(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ return [_qij_plus(i, j), _qij_minus(i, j), _qij_0(i, j)] @@ -116,7 +116,7 @@ def _qij_vec_dagger(i: int, j: int): r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ return [hermitian_conjugated(i) for i in _qij_vec(i, j)] @@ -125,7 +125,7 @@ def _qij_vec_inner(a: int, b: int, i: int, j: int): # pylint: disable=invalid-n r""" CCD0 ansatz helper function. - See :class: `mindquantum.third_party.unitary_cc.spin_adapted_t2`. + See :class: `quafu.third_party.unitary_cc.spin_adapted_t2`. """ vec_dagger = _qij_vec_dagger(a, b) vec = _qij_vec(i, j) @@ -149,7 +149,7 @@ def spin_adapted_t1(i, j): tpq_list (list): Spin-adapted single excitation operators. Examples: - >>> from mindquantum.algorithm.nisq.chem.uccsd0 import spin_adapted_t1 + >>> from quafu.algorithm.nisq.chem.uccsd0 import spin_adapted_t1 >>> spin_adapted_t1(2, 3) [1.0 [4^ 6] + 1.0 [5^ 7] ] @@ -188,7 +188,7 @@ def spin_adapted_t2(creation_list, annihilation_list): tpqrs_list(list): Spin-adapted double excitation operators. Examples: - >>> from mindquantum.algorithm.nisq.chem.uccsd0 import spin_adapted_t2 + >>> from quafu.algorithm.nisq.chem.uccsd0 import spin_adapted_t2 >>> spin_adapted_t2([0, 1], [2, 3]) [0.5000000000000001 [1^ 2^ 4 7] + 0.5000000000000001 [1^ 2^ 6 5] + @@ -261,7 +261,7 @@ def uccsd0_singlet_generator( FermionOperator, Generator of the UCCSD operators that uses CCD0 ansatz. Examples: - >>> from mindquantum.algorithm.nisq import uccsd0_singlet_generator + >>> from quafu.algorithm.nisq import uccsd0_singlet_generator >>> uccsd0_singlet_generator(4, 2) -1.0*d0_s_0 [0^ 2] + 2.0*d0_d_0 [1^ 0^ 3 2] + diff --git a/mindquantum/algorithm/nisq/chem/unitary_cc.py b/quafu/algorithm/nisq/chem/unitary_cc.py similarity index 97% rename from mindquantum/algorithm/nisq/chem/unitary_cc.py rename to quafu/algorithm/nisq/chem/unitary_cc.py index 2f3aed0dc..66936e157 100644 --- a/mindquantum/algorithm/nisq/chem/unitary_cc.py +++ b/quafu/algorithm/nisq/chem/unitary_cc.py @@ -17,8 +17,8 @@ """Unitary coupled-cluster ansatz.""" -from mindquantum.core.circuit import Circuit, add_prefix -from mindquantum.core.operators import TimeEvolution +from quafu.core.circuit import Circuit, add_prefix +from quafu.core.operators import TimeEvolution from .._ansatz import Ansatz from .transform import Transform @@ -62,7 +62,7 @@ class UCCAnsatz(Ansatz): trotter_step(int): The order of Trotterization step. Default: ``1``. Examples: - >>> from mindquantum.algorithm.nisq import UCCAnsatz + >>> from quafu.algorithm.nisq import UCCAnsatz >>> ucc = UCCAnsatz(12, 4, occ_orb=[1], ... vir_orb=[2, 3], ... generalized=True, diff --git a/mindquantum/algorithm/nisq/qaoa/__init__.py b/quafu/algorithm/nisq/qaoa/__init__.py similarity index 100% rename from mindquantum/algorithm/nisq/qaoa/__init__.py rename to quafu/algorithm/nisq/qaoa/__init__.py diff --git a/mindquantum/algorithm/nisq/qaoa/max_2_sat_ansatz.py b/quafu/algorithm/nisq/qaoa/max_2_sat_ansatz.py similarity index 95% rename from mindquantum/algorithm/nisq/qaoa/max_2_sat_ansatz.py rename to quafu/algorithm/nisq/qaoa/max_2_sat_ansatz.py index bf9b81296..6f371c4af 100644 --- a/mindquantum/algorithm/nisq/qaoa/max_2_sat_ansatz.py +++ b/quafu/algorithm/nisq/qaoa/max_2_sat_ansatz.py @@ -19,11 +19,11 @@ import numpy as np -from mindquantum.core.circuit import CPN, UN, Circuit -from mindquantum.core.gates import RX, H -from mindquantum.core.operators import QubitOperator, TimeEvolution -from mindquantum.simulator import Simulator -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import CPN, UN, Circuit +from quafu.core.gates import RX, H +from quafu.core.operators import QubitOperator, TimeEvolution +from quafu.simulator import Simulator +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_between_close_set, @@ -91,7 +91,7 @@ class Max2SATAnsatz(Ansatz): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.nisq import Max2SATAnsatz + >>> from quafu.algorithm.nisq import Max2SATAnsatz >>> clauses = [(2, -3)] >>> max2sat = Max2SATAnsatz(clauses, 1) >>> max2sat.circuit @@ -181,7 +181,7 @@ def get_sat(self, max_n, weight): """ _check_int_type('max_n', max_n) _check_value_should_between_close_set('max_n', 1, 1 << self._circuit.n_qubits, max_n) - sim = Simulator('mqvector', self._circuit.n_qubits) + sim = Simulator('quafuvector', self._circuit.n_qubits) sim.apply_circuit(self._circuit, weight) state = sim.get_qs() idxs = np.argpartition(np.abs(state), -max_n)[-max_n:] diff --git a/mindquantum/algorithm/nisq/qaoa/max_cut_ansatz.py b/quafu/algorithm/nisq/qaoa/max_cut_ansatz.py similarity index 96% rename from mindquantum/algorithm/nisq/qaoa/max_cut_ansatz.py rename to quafu/algorithm/nisq/qaoa/max_cut_ansatz.py index 1f73d6011..24f571b44 100644 --- a/mindquantum/algorithm/nisq/qaoa/max_cut_ansatz.py +++ b/quafu/algorithm/nisq/qaoa/max_cut_ansatz.py @@ -19,11 +19,11 @@ import numpy as np -from mindquantum.core.circuit import CPN, UN, Circuit -from mindquantum.core.gates import RX, H, Rzz -from mindquantum.core.operators import QubitOperator -from mindquantum.simulator import Simulator -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import CPN, UN, Circuit +from quafu.core.gates import RX, H, Rzz +from quafu.core.operators import QubitOperator +from quafu.simulator import Simulator +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_between_close_set, @@ -87,7 +87,7 @@ class MaxCutAnsatz(Ansatz): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.nisq import MaxCutAnsatz + >>> from quafu.algorithm.nisq import MaxCutAnsatz >>> graph = [(0, 1), (1, 2), (0, 2)] >>> maxcut = MaxCutAnsatz(graph, 1) >>> maxcut.circuit @@ -167,7 +167,7 @@ def get_partition(self, max_n, weight): """ _check_int_type('max_n', max_n) _check_value_should_between_close_set('max_n', 1, 1 << self._circuit.n_qubits, max_n) - sim = Simulator('mqvector', self._circuit.n_qubits) + sim = Simulator('quafuvector', self._circuit.n_qubits) sim.apply_circuit(self._circuit, weight) state = sim.get_qs() idxs = np.argpartition(np.abs(state), -max_n)[-max_n:] diff --git a/mindquantum/algorithm/nisq/qaoa/max_cut_rqaoa_ansatz.py b/quafu/algorithm/nisq/qaoa/max_cut_rqaoa_ansatz.py similarity index 93% rename from mindquantum/algorithm/nisq/qaoa/max_cut_rqaoa_ansatz.py rename to quafu/algorithm/nisq/qaoa/max_cut_rqaoa_ansatz.py index a9e80af34..3cd2c69ef 100644 --- a/mindquantum/algorithm/nisq/qaoa/max_cut_rqaoa_ansatz.py +++ b/quafu/algorithm/nisq/qaoa/max_cut_rqaoa_ansatz.py @@ -17,8 +17,8 @@ """MaxCutRQAOA ansatz.""" -from mindquantum.core.operators import QubitOperator -from mindquantum.utils.type_value_check import ( +from quafu.core.operators import QubitOperator +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -163,17 +163,17 @@ class MaxCutRQAOAAnsatz(RQAOAAnsatz, MaxCut): (4, [2, 0]) >>> mcra.get_cut_value(graph, [2, 0]) # calculate max-cut value of the graph 4 - >>> from mindquantum.framework import MQAnsatzOnlyLayer - >>> from mindquantum.simulator import Simulator + >>> from quafu.framework import QUAFUAnsatzOnlyLayer + >>> from quafu.simulator import Simulator >>> import mindspore.nn as nn >>> import mindspore as ms >>> import numpy as np >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = mcra.circuit # QAOA circuit for the Hamiltonian >>> ham = mcra.hamiltonian # the Hamiltonian - >>> sim = Simulator('mqvector', circ.n_qubits) # create simulator with 'mqvector' backend + >>> sim = Simulator('quafuvector', circ.n_qubits) # create simulator with 'quafuvector' backend >>> grad_ops = sim.get_expectation_with_grad(ham, circ) # get expectation and gradient operators for the variational quantum circuit - >>> net = MQAnsatzOnlyLayer(grad_ops) # generate ansatz to train + >>> net = QUAFUAnsatzOnlyLayer(grad_ops) # generate ansatz to train >>> opti = nn.Adam(net.trainable_params(), learning_rate=0.05) # decide all trainable parameters in the model, and use Adam optimizer with learning rate 0.05 >>> train_net = nn.TrainOneStepCell(net, opti) # train the model one step >>> e = [train_net() for i in range(30)] # train 30 steps diff --git a/mindquantum/algorithm/nisq/qaoa/qaoa_ansatz.py b/quafu/algorithm/nisq/qaoa/qaoa_ansatz.py similarity index 89% rename from mindquantum/algorithm/nisq/qaoa/qaoa_ansatz.py rename to quafu/algorithm/nisq/qaoa/qaoa_ansatz.py index ee7f3f9c9..a7465ac0c 100644 --- a/mindquantum/algorithm/nisq/qaoa/qaoa_ansatz.py +++ b/quafu/algorithm/nisq/qaoa/qaoa_ansatz.py @@ -17,15 +17,15 @@ """QAOA ansatz.""" -from mindquantum.core.circuit import ( +from quafu.core.circuit import ( CPN, UN, Circuit, decompose_single_term_time_evolution, ) -from mindquantum.core.gates import RX, H -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.utils.type_value_check import ( +from quafu.core.gates import RX, H +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -51,8 +51,8 @@ class QAOAAnsatz(Ansatz): depth (int): The depth of QAOA ansatz. Default: ``1``. Examples: - >>> from mindquantum.algorithm.nisq import QAOAAnsatz - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.algorithm.nisq import QAOAAnsatz + >>> from quafu.core.operators import QubitOperator >>> ham = QubitOperator('Z0 Z1', 2) + QubitOperator('Z2 Z1', 1) + QubitOperator('Z0 Y2', 0.5) >>> qaoa = QAOAAnsatz(ham, 1) >>> qaoa.circuit[:11] diff --git a/mindquantum/algorithm/nisq/qaoa/rqaoa_ansatz.py b/quafu/algorithm/nisq/qaoa/rqaoa_ansatz.py similarity index 93% rename from mindquantum/algorithm/nisq/qaoa/rqaoa_ansatz.py rename to quafu/algorithm/nisq/qaoa/rqaoa_ansatz.py index 235df17f9..3d5494bed 100644 --- a/mindquantum/algorithm/nisq/qaoa/rqaoa_ansatz.py +++ b/quafu/algorithm/nisq/qaoa/rqaoa_ansatz.py @@ -19,9 +19,9 @@ import numpy as np -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.simulator import Simulator -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.simulator import Simulator +from quafu.utils.type_value_check import _check_input_type from .qaoa_ansatz import QAOAAnsatz @@ -69,8 +69,8 @@ class RQAOAAnsatz(QAOAAnsatz): p (int): The depth of QAOA ansatz. Default: ``1``. Examples: - >>> from mindquantum.algorithm.nisq import RQAOAAnsatz - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.algorithm.nisq import RQAOAAnsatz + >>> from quafu.core.operators import QubitOperator >>> ham = QubitOperator('Z0 Z1', 2) + QubitOperator('Z2 Z1', 1) + QubitOperator('Z0 Z2', 0.5) >>> ra = RQAOAAnsatz(ham, 1) >>> ra.all_variables # All parameters(as Pauli Operators) @@ -266,7 +266,7 @@ def eliminate_variable(self, weight, show_process=False): """ _check_input_type('The flag of showing process', (bool, int), show_process) hams = self.m_hamiltonians - sim = Simulator('mqvector', self._circuit.n_qubits) + sim = Simulator('quafuvector', self._circuit.n_qubits) sim.apply_circuit(self._circuit, pr=weight) m = list(map(sim.get_expectation, hams)) i = np.abs(m).argmax() diff --git a/mindquantum/algorithm/nisq/qnn/__init__.py b/quafu/algorithm/nisq/qnn/__init__.py similarity index 100% rename from mindquantum/algorithm/nisq/qnn/__init__.py rename to quafu/algorithm/nisq/qnn/__init__.py diff --git a/mindquantum/algorithm/nisq/qnn/arxiv_1905_10876.py b/quafu/algorithm/nisq/qnn/arxiv_1905_10876.py similarity index 98% rename from mindquantum/algorithm/nisq/qnn/arxiv_1905_10876.py rename to quafu/algorithm/nisq/qnn/arxiv_1905_10876.py index 93c231a00..ec6e40151 100644 --- a/mindquantum/algorithm/nisq/qnn/arxiv_1905_10876.py +++ b/quafu/algorithm/nisq/qnn/arxiv_1905_10876.py @@ -14,13 +14,13 @@ # ============================================================================ """These ansatz are adpot from arxiv 1906 10876.""" # pylint: disable=too-few-public-methods,too-many-lines -from mindquantum.algorithm.nisq._ansatz import ( +from quafu.algorithm.nisq._ansatz import ( Ansatz, Initializer, single_qubit_gate_layer, ) -from mindquantum.core.circuit import UN -from mindquantum.core.gates import BARRIER, RX, RY, RZ, H, X, Z +from quafu.core.circuit import UN +from quafu.core.gates import BARRIER, RX, RY, RZ, H, X, Z class Ansatz1(Ansatz, Initializer): @@ -40,7 +40,7 @@ class Ansatz1(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz1 + >>> from quafu.algorithm.nisq import Ansatz1 >>> Ansatz1(3, 2).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p3) ┠─┨ RX(p6) ┠─┨ RZ(p9) ┠──── @@ -83,7 +83,7 @@ class Ansatz2(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz2 + >>> from quafu.algorithm.nisq import Ansatz2 >>> Ansatz2(3, 2).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p3) ┠───────┨╺╋╸┠─┨ RX(p6) ┠─┨ RZ(p9) ┠────────┨╺╋╸┠─── @@ -128,7 +128,7 @@ class Ansatz3(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz3 + >>> from quafu.algorithm.nisq import Ansatz3 >>> Ansatz3(3, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p3) ┠────────────┨ RZ(p7) ┠─── @@ -173,7 +173,7 @@ class Ansatz4(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz4 + >>> from quafu.algorithm.nisq import Ansatz4 >>> Ansatz4(3, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p3) ┠────────────┨ RX(p7) ┠─── @@ -218,7 +218,7 @@ class Ansatz5(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz5 + >>> from quafu.algorithm.nisq import Ansatz5 >>> Ansatz5(3, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p3) ┠────────────┨ RZ(p7) ┠────────────┨ RZ(p9) ┠──────■──────↯─ @@ -277,7 +277,7 @@ class Ansatz6(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz6 + >>> from quafu.algorithm.nisq import Ansatz6 >>> Ansatz6(3, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p3) ┠────────────┨ RX(p7) ┠────────────┨ RX(p9) ┠──────■──────↯─ @@ -336,7 +336,7 @@ class Ansatz7(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz7 + >>> from quafu.algorithm.nisq import Ansatz7 >>> Ansatz7(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p4) ┠─┨ RZ(p8) ┠─┨ RX(p10) ┠─┨ RZ(p14) ┠─────────────── @@ -399,7 +399,7 @@ class Ansatz8(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz8 + >>> from quafu.algorithm.nisq import Ansatz8 >>> Ansatz8(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p4) ┠─┨ RX(p8) ┠─┨ RX(p10) ┠─┨ RZ(p14) ┠─────────────── @@ -462,7 +462,7 @@ class Ansatz9(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz9 + >>> from quafu.algorithm.nisq import Ansatz9 >>> Ansatz9(4, 2).circuit ┏━━━┓ ┏━━━┓ ┏━━━━━━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━━━━━━┓ q0: ──┨ H ┠─────────────┨ Z ┠─┨ RX(p0) ┠─┨ H ┠─────────────┨ Z ┠─┨ RX(p4) ┠─── @@ -511,7 +511,7 @@ class Ansatz10(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz10 + >>> from quafu.algorithm.nisq import Ansatz10 >>> Ansatz10(4, 2).circuit ┏━━━━━━━━┓ ┏━━━┓ ┏━━━━━━━━┓ ┏━━━┓ ┏━━━━━━━━┓ q0: ──┨ RY(p0) ┠───────────────■───┨ Z ┠─┨ RY(p4) ┠───────────────■───┨ Z ┠─┨ RY(p8) ┠──── @@ -561,7 +561,7 @@ class Ansatz11(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz11 + >>> from quafu.algorithm.nisq import Ansatz11 >>> Ansatz11(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━┓ q0: ──┨ RY(p0) ┠─┨ RZ(p4) ┠─┨╺╋╸┠──────────────────────────────── @@ -624,7 +624,7 @@ class Ansatz12(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz12 + >>> from quafu.algorithm.nisq import Ansatz12 >>> Ansatz12(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━┓ q0: ──┨ RY(p0) ┠─┨ RZ(p4) ┠─┨ Z ┠──────────────────────────────── @@ -687,7 +687,7 @@ class Ansatz13(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz13 + >>> from quafu.algorithm.nisq import Ansatz13 >>> Ansatz13(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RY(p0) ┠─┨ RZ(p4) ┠────────────────────────────■─────┨ RY(p8) ┠──────────────↯─ @@ -755,7 +755,7 @@ class Ansatz14(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz14 + >>> from quafu.algorithm.nisq import Ansatz14 >>> Ansatz14(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RY(p0) ┠─┨ RX(p4) ┠────────────────────────────■─────┨ RY(p8) ┠──────────────↯─ @@ -823,7 +823,7 @@ class Ansatz15(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz15 + >>> from quafu.algorithm.nisq import Ansatz15 >>> Ansatz15(4, 1).circuit ┏━━━━━━━━┓ ┏━━━┓ ┏━━━━━━━━┓ ┏━━━┓ q0: ──┨ RY(p0) ┠─┨╺╋╸┠───────────────■───┨ RY(p4) ┠─────────■───┨╺╋╸┠───────── @@ -879,7 +879,7 @@ class Ansatz16(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz16 + >>> from quafu.algorithm.nisq import Ansatz16 >>> Ansatz16(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p4) ┠─┨ RZ(p8) ┠─────────────── @@ -940,7 +940,7 @@ class Ansatz17(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz17 + >>> from quafu.algorithm.nisq import Ansatz17 >>> Ansatz17(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p4) ┠─┨ RX(p8) ┠─────────────── @@ -1001,7 +1001,7 @@ class Ansatz18(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz18 + >>> from quafu.algorithm.nisq import Ansatz18 >>> Ansatz18(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p4) ┠─┨ RZ(p8) ┠─────────────────────────────■──────── @@ -1051,7 +1051,7 @@ class Ansatz19(Ansatz, Initializer): suffix (str): suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.algorithm.nisq import Ansatz19 + >>> from quafu.algorithm.nisq import Ansatz19 >>> Ansatz19(4, 1).circuit ┏━━━━━━━━┓ ┏━━━━━━━━┓ ┏━━━━━━━━┓ q0: ──┨ RX(p0) ┠─┨ RZ(p4) ┠─┨ RX(p8) ┠─────────────────────────────■──────── diff --git a/mindquantum/algorithm/nisq/qnn/iqp_encoding.py b/quafu/algorithm/nisq/qnn/iqp_encoding.py similarity index 96% rename from mindquantum/algorithm/nisq/qnn/iqp_encoding.py rename to quafu/algorithm/nisq/qnn/iqp_encoding.py index 16d43e2a9..4aa7f4b12 100644 --- a/mindquantum/algorithm/nisq/qnn/iqp_encoding.py +++ b/quafu/algorithm/nisq/qnn/iqp_encoding.py @@ -16,10 +16,10 @@ import numpy as np -from mindquantum.algorithm.nisq._ansatz import Ansatz -from mindquantum.core.circuit import UN, Circuit, add_prefix, add_suffix -from mindquantum.core.gates import BARRIER, RZ, H, ParameterGate, X -from mindquantum.utils.type_value_check import ( +from quafu.algorithm.nisq._ansatz import Ansatz +from quafu.core.circuit import UN, Circuit, add_prefix, add_suffix +from quafu.core.gates import BARRIER, RZ, H, ParameterGate, X +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -48,7 +48,7 @@ class IQPEncoding(Ansatz): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.nisq import IQPEncoding + >>> from quafu.algorithm.nisq import IQPEncoding >>> iqp = IQPEncoding(3) >>> iqp.circuit ┏━━━┓ ┏━━━━━━━━━━━━┓ diff --git a/mindquantum/algorithm/nisq/qnn/quantum_neuron.py b/quafu/algorithm/nisq/qnn/quantum_neuron.py similarity index 96% rename from mindquantum/algorithm/nisq/qnn/quantum_neuron.py rename to quafu/algorithm/nisq/qnn/quantum_neuron.py index 5d1d883c2..cd7a04eca 100644 --- a/mindquantum/algorithm/nisq/qnn/quantum_neuron.py +++ b/quafu/algorithm/nisq/qnn/quantum_neuron.py @@ -15,8 +15,8 @@ """Quantum Neuron.""" import numpy as np -from mindquantum.core.gates import RY, Y, RZ, Measure -from mindquantum.core.circuit import dagger, Circuit +from quafu.core.gates import RY, Y, RZ, Measure +from quafu.core.circuit import dagger, Circuit class QuantumNeuron: @@ -52,13 +52,13 @@ class QuantumNeuron: will be set to len(input_qubits) + 1. Default: None Examples: - >>> from mindquantum.simulator import Simulator - >>> from mindquantum import Circuit, H,X + >>> from quafu.simulator import Simulator + >>> from quafu import Circuit, H,X >>> # Create 2-qubit input state >>> circ = Circuit() >>> circ += H.on(0) >>> circ += H.on(1) - >>> sim = Simulator('mqvector', 4) + >>> sim = Simulator('quafuvector', 4) >>> sim.apply_circuit(circ) >>> qn = QuantumNeuron(weight=[1, 1], input_qubits=[0, 1], output_qubit=3, ancilla_qubit=2) >>> # Repeat quantum neuron circuit until success diff --git a/mindquantum/algorithm/nisq/qnn/strongly_entangling.py b/quafu/algorithm/nisq/qnn/strongly_entangling.py similarity index 94% rename from mindquantum/algorithm/nisq/qnn/strongly_entangling.py rename to quafu/algorithm/nisq/qnn/strongly_entangling.py index c8270267a..ccc0e2968 100644 --- a/mindquantum/algorithm/nisq/qnn/strongly_entangling.py +++ b/quafu/algorithm/nisq/qnn/strongly_entangling.py @@ -14,10 +14,10 @@ # ============================================================================ """Strongly entangling ansatz.""" -from mindquantum.core.circuit import Circuit, add_prefix, add_suffix -from mindquantum.core.gates import BasicGate -from mindquantum.core.gates.basicgate import U3 -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import Circuit, add_prefix, add_suffix +from quafu.core.gates import BasicGate +from quafu.core.gates.basicgate import U3 +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -42,8 +42,8 @@ class StronglyEntangling(Ansatz): # pylint: disable=too-few-public-methods suffix (str): The suffix of parameters. Default: ``''``. Examples: - >>> from mindquantum.core.gates import X - >>> from mindquantum.algorithm.nisq import StronglyEntangling + >>> from quafu.core.gates import X + >>> from quafu.algorithm.nisq import StronglyEntangling >>> ansatz = StronglyEntangling(3, 2, X) >>> ansatz.circuit ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━━━┓ diff --git a/mindquantum/algorithm/qaia/CAC.py b/quafu/algorithm/qaia/CAC.py similarity index 94% rename from mindquantum/algorithm/qaia/CAC.py rename to quafu/algorithm/qaia/CAC.py index 029e8d125..b95a6b615 100644 --- a/mindquantum/algorithm/qaia/CAC.py +++ b/quafu/algorithm/qaia/CAC.py @@ -17,7 +17,7 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import _check_number_type, _check_value_should_not_less +from quafu.utils.type_value_check import _check_number_type, _check_value_should_not_less from .QAIA import QAIA @@ -45,7 +45,7 @@ class CAC(QAIA): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import CAC + >>> from quafu.algorithm.qaia import CAC >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = CAC(J, batch_size=5) >>> solver.update() diff --git a/mindquantum/algorithm/qaia/CFC.py b/quafu/algorithm/qaia/CFC.py similarity index 94% rename from mindquantum/algorithm/qaia/CFC.py rename to quafu/algorithm/qaia/CFC.py index 5586090eb..ec245c857 100644 --- a/mindquantum/algorithm/qaia/CFC.py +++ b/quafu/algorithm/qaia/CFC.py @@ -17,7 +17,7 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import _check_number_type, _check_value_should_not_less +from quafu.utils.type_value_check import _check_number_type, _check_value_should_not_less from .QAIA import QAIA @@ -45,7 +45,7 @@ class CFC(QAIA): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import CFC + >>> from quafu.algorithm.qaia import CFC >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = CFC(J, batch_size=5) >>> solver.update() diff --git a/mindquantum/algorithm/qaia/LQA.py b/quafu/algorithm/qaia/LQA.py similarity index 95% rename from mindquantum/algorithm/qaia/LQA.py rename to quafu/algorithm/qaia/LQA.py index 7cc229105..b30fa9fc9 100644 --- a/mindquantum/algorithm/qaia/LQA.py +++ b/quafu/algorithm/qaia/LQA.py @@ -17,7 +17,7 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import ( +from quafu.utils.type_value_check import ( _check_number_type, _check_value_should_not_less, _check_value_should_between_close_set, @@ -51,7 +51,7 @@ class LQA(QAIA): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import LQA + >>> from quafu.algorithm.qaia import LQA >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = LQA(J, batch_size=5) >>> solver.update() diff --git a/mindquantum/algorithm/qaia/NMFA.py b/quafu/algorithm/qaia/NMFA.py similarity index 94% rename from mindquantum/algorithm/qaia/NMFA.py rename to quafu/algorithm/qaia/NMFA.py index cb59ad938..517d3f811 100644 --- a/mindquantum/algorithm/qaia/NMFA.py +++ b/quafu/algorithm/qaia/NMFA.py @@ -17,7 +17,7 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import ( +from quafu.utils.type_value_check import ( _check_number_type, _check_value_should_between_close_set, _check_value_should_not_less, @@ -50,7 +50,7 @@ class NMFA(QAIA): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import NMFA + >>> from quafu.algorithm.qaia import NMFA >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = NMFA(J, batch_size=5) >>> solver.update() diff --git a/mindquantum/algorithm/qaia/QAIA.py b/quafu/algorithm/qaia/QAIA.py similarity index 95% rename from mindquantum/algorithm/qaia/QAIA.py rename to quafu/algorithm/qaia/QAIA.py index 693726e2b..455d9b83f 100644 --- a/mindquantum/algorithm/qaia/QAIA.py +++ b/quafu/algorithm/qaia/QAIA.py @@ -16,7 +16,7 @@ # pylint: disable=invalid-name import numpy as np from scipy import sparse as sp -from mindquantum.utils.type_value_check import _check_int_type, _check_value_should_not_less +from quafu.utils.type_value_check import _check_int_type, _check_value_should_not_less class QAIA: diff --git a/mindquantum/algorithm/qaia/SB.py b/quafu/algorithm/qaia/SB.py similarity index 95% rename from mindquantum/algorithm/qaia/SB.py rename to quafu/algorithm/qaia/SB.py index 47500489d..1c3c5ad85 100644 --- a/mindquantum/algorithm/qaia/SB.py +++ b/quafu/algorithm/qaia/SB.py @@ -17,11 +17,11 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import _check_number_type, _check_value_should_not_less, _check_int_type +from quafu.utils.type_value_check import _check_number_type, _check_value_should_not_less, _check_int_type from .QAIA import QAIA, OverflowException try: - from mindquantum import _qaia_sb + from quafu import _qaia_sb GPU_AVAILABLE = True except ImportError as err: @@ -126,7 +126,7 @@ class ASB(SB): # noqa: N801 Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import ASB + >>> from quafu.algorithm.qaia import ASB >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = ASB(J, batch_size=5) >>> solver.update() @@ -201,7 +201,7 @@ class BSB(SB): # noqa: N801 Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import BSB + >>> from quafu.algorithm.qaia import BSB >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = BSB(J, batch_size=5, backend='cpu-float32') >>> solver.update() @@ -317,7 +317,7 @@ class DSB(SB): # noqa: N801 Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import DSB + >>> from quafu.algorithm.qaia import DSB >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = DSB(J, batch_size=5, backend='cpu-float32') >>> solver.update() diff --git a/mindquantum/algorithm/qaia/SFC.py b/quafu/algorithm/qaia/SFC.py similarity index 94% rename from mindquantum/algorithm/qaia/SFC.py rename to quafu/algorithm/qaia/SFC.py index fda5b8d7b..70a3d1a8b 100644 --- a/mindquantum/algorithm/qaia/SFC.py +++ b/quafu/algorithm/qaia/SFC.py @@ -17,7 +17,7 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import _check_number_type, _check_value_should_not_less +from quafu.utils.type_value_check import _check_number_type, _check_value_should_not_less from .QAIA import QAIA, OverflowException @@ -46,7 +46,7 @@ class SFC(QAIA): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import SFC + >>> from quafu.algorithm.qaia import SFC >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = SFC(J, batch_size=5) >>> solver.update() diff --git a/mindquantum/algorithm/qaia/SimCIM.py b/quafu/algorithm/qaia/SimCIM.py similarity index 95% rename from mindquantum/algorithm/qaia/SimCIM.py rename to quafu/algorithm/qaia/SimCIM.py index d3818090d..de6dca646 100644 --- a/mindquantum/algorithm/qaia/SimCIM.py +++ b/quafu/algorithm/qaia/SimCIM.py @@ -17,7 +17,7 @@ import numpy as np from scipy.sparse import csr_matrix -from mindquantum.utils.type_value_check import ( +from quafu.utils.type_value_check import ( _check_number_type, _check_value_should_not_less, _check_value_should_between_close_set, @@ -52,7 +52,7 @@ class SimCIM(QAIA): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.qaia import SimCIM + >>> from quafu.algorithm.qaia import SimCIM >>> J = np.array([[0, -1], [-1, 0]]) >>> solver = SimCIM(J, batch_size=5) >>> solver.update() diff --git a/mindquantum/algorithm/qaia/__init__.py b/quafu/algorithm/qaia/__init__.py similarity index 100% rename from mindquantum/algorithm/qaia/__init__.py rename to quafu/algorithm/qaia/__init__.py diff --git a/mindquantum/config/__init__.py b/quafu/config/__init__.py similarity index 95% rename from mindquantum/config/__init__.py rename to quafu/config/__init__.py index 35485d13c..5bf7cdda5 100644 --- a/mindquantum/config/__init__.py +++ b/quafu/config/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Global config for mindquantum.""" +"""Global config for quafu.""" from .config import context __all__ = [] diff --git a/mindquantum/config/config.py b/quafu/config/config.py similarity index 92% rename from mindquantum/config/config.py rename to quafu/config/config.py index c9d517114..3d2e5c568 100644 --- a/mindquantum/config/config.py +++ b/quafu/config/config.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Global config for mindquantum.""" +"""Global config for quafu.""" import numbers import numpy as np -from mindquantum.utils.type_value_check import _check_input_type +from quafu.utils.type_value_check import _check_input_type __all__ = ['context'] @@ -59,13 +59,13 @@ class context: # pylint: disable=invalid-name # noqa: N801 @staticmethod def set_precision(atol): """ - Set the number precision for mindquantum. + Set the number precision for quafu. For example, `is_two_number_close` will use this precision to determine whether two number is close to each other. Examples: - >>> from mindquantum import context + >>> from quafu import context >>> context.set_precision(1e-3) >>> context.get_precision() 0.001 diff --git a/mindquantum/core/__init__.py b/quafu/core/__init__.py similarity index 96% rename from mindquantum/core/__init__.py rename to quafu/core/__init__.py index e11d6886c..6c7741b90 100644 --- a/mindquantum/core/__init__.py +++ b/quafu/core/__init__.py @@ -13,7 +13,7 @@ # limitations under the License. # ============================================================================ -"""MindQuantum core features (eDSL).""" +"""quafu core features (eDSL).""" # Provide alias for convenience diff --git a/mindquantum/core/circuit/__init__.py b/quafu/core/circuit/__init__.py similarity index 100% rename from mindquantum/core/circuit/__init__.py rename to quafu/core/circuit/__init__.py diff --git a/mindquantum/core/circuit/channel_adder.py b/quafu/core/circuit/channel_adder.py similarity index 94% rename from mindquantum/core/circuit/channel_adder.py rename to quafu/core/circuit/channel_adder.py index f70e44af7..4b2b2ec53 100644 --- a/mindquantum/core/circuit/channel_adder.py +++ b/quafu/core/circuit/channel_adder.py @@ -17,7 +17,7 @@ import warnings from types import FunctionType, MethodType -from mindquantum.utils.type_value_check import ( +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -90,8 +90,8 @@ class ReverseAdder(ChannelAdderBase): adder (:class:`~.core.circuit.ChannelAdderBase`): A channel adder. Examples: - >>> from mindquantum.core.circuit import ReverseAdder, MeasureAccepter, BitFlipAdder, MixerAdder - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import ReverseAdder, MeasureAccepter, BitFlipAdder, MixerAdder + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().rx('a', 0).measure_all() >>> only_measure = MixerAdder([BitFlipAdder(0.1), MeasureAccepter()]) >>> only_measure(circ) @@ -139,8 +139,8 @@ class MeasureAccepter(ChannelAdderBase): Select measurement gate. Examples: - >>> from mindquantum.core.circuit import MeasureAccepter, BitFlipAdder, MixerAdder - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import MeasureAccepter, BitFlipAdder, MixerAdder + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().rx('a', 0).h(0).measure_all() >>> only_measure = MixerAdder([BitFlipAdder(0.1), MeasureAccepter()], add_after=False) >>> only_measure(circ) @@ -166,8 +166,8 @@ class NoiseExcluder(ChannelAdderBase): add_after (bool): Whether add channel after gate or before gate. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import Circuit, NoiseExcluder, BitFlipAdder, MixerAdder - >>> from mindquantum.core.gates import DepolarizingChannel + >>> from quafu.core.circuit import Circuit, NoiseExcluder, BitFlipAdder, MixerAdder + >>> from quafu.core.gates import DepolarizingChannel >>> circ = Circuit().x(0) >>> circ += DepolarizingChannel(0.1).on(0) >>> circ @@ -204,8 +204,8 @@ class BitFlipAdder(ChannelAdderBase): channel will add before quantum gate. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import BitFlipAdder - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import BitFlipAdder + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().h(0).x(1, 0) >>> adder1 = BitFlipAdder(0.1, with_ctrl=False) >>> adder1(circ) @@ -264,8 +264,8 @@ class NoiseChannelAdder(ChannelAdderBase): channel will add before quantum gate. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import NoiseChannelAdder, Circuit - >>> from mindquantum.core.gates import AmplitudeDampingChannel + >>> from quafu.core.circuit import NoiseChannelAdder, Circuit + >>> from quafu.core.gates import AmplitudeDampingChannel >>> circ = Circuit().h(0).x(1, 0) >>> channel = AmplitudeDampingChannel(0.3) >>> adder1 = NoiseChannelAdder(channel, with_ctrl=True, add_after=True) @@ -333,8 +333,8 @@ class DepolarizingChannelAdder(ChannelAdderBase): channel will add before quantum gate. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import MixerAdder, DepolarizingChannelAdder, GateSelector - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import MixerAdder, DepolarizingChannelAdder, GateSelector + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().h(0).x(1, 0) >>> adder = MixerAdder([GateSelector('cx'), DepolarizingChannelAdder(0.1, 2)]) >>> adder(circ) @@ -377,7 +377,7 @@ class QubitNumberConstrain(ChannelAdderBase): add_after (bool): Whether add channel after gate or before gate. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import QubitNumberConstrain, Circuit, BitFlipAdder, MixerAdder + >>> from quafu.core.circuit import QubitNumberConstrain, Circuit, BitFlipAdder, MixerAdder >>> circ = Circuit().h(0).x(1, 0) >>> circ ┏━━━┓ @@ -425,7 +425,7 @@ class QubitIDConstrain(ChannelAdderBase): add_after (bool): Whether add channel after gate or before gate. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import MixerAdder, BitFlipAdder, QubitIDConstrain, Circuit + >>> from quafu.core.circuit import MixerAdder, BitFlipAdder, QubitIDConstrain, Circuit >>> circ = Circuit().h(0).h(1).h(2).x(1, 0).x(2, 1) >>> circ ┏━━━┓ @@ -482,8 +482,8 @@ class MixerAdder(ChannelAdderBase): of sub adder. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import MeasureAccepter, BitFlipAdder, MixerAdder - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import MeasureAccepter, BitFlipAdder, MixerAdder + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().rx('a', 0).h(0).measure_all() >>> only_measure = MixerAdder([BitFlipAdder(0.1), MeasureAccepter()], add_after=False) >>> only_measure(circ) @@ -533,10 +533,10 @@ class SequentialAdder(ChannelAdderBase): adders (List[:class:`~.core.circuit.ChannelAdderBase`]): The adder you want to apply. Examples: - >>> from mindquantum.core.circuit import SequentialAdder, MixerAdder, BitFlipAdder, NoiseChannelAdder - >>> from mindquantum.core.circuit import MeasureAccepter, ReverseAdder, NoiseChannelAdder, Circuit - >>> from mindquantum.core.circuit import NoiseExcluder - >>> from mindquantum.core.gates import DepolarizingChannel + >>> from quafu.core.circuit import SequentialAdder, MixerAdder, BitFlipAdder, NoiseChannelAdder + >>> from quafu.core.circuit import MeasureAccepter, ReverseAdder, NoiseChannelAdder, Circuit + >>> from quafu.core.circuit import NoiseExcluder + >>> from quafu.core.gates import DepolarizingChannel >>> circ = Circuit().h(0).x(1, 0).measure_all() >>> circ ┏━━━┓ ┍━━━━━━┑ @@ -601,7 +601,7 @@ class GateSelector(ChannelAdderBase): 'CX', 'CZ', 'SWAP'. Examples: - >>> from mindquantum.core.circuit import BitFlipAdder, GateSelector, Circuit, MixerAdder + >>> from quafu.core.circuit import BitFlipAdder, GateSelector, Circuit, MixerAdder >>> circ = Circuit().h(0).x(1, 0) >>> circ ┏━━━┓ diff --git a/mindquantum/core/circuit/circuit.py b/quafu/core/circuit/circuit.py similarity index 89% rename from mindquantum/core/circuit/circuit.py rename to quafu/core/circuit/circuit.py index 869781d0b..bf0a17e9c 100644 --- a/mindquantum/core/circuit/circuit.py +++ b/quafu/core/circuit/circuit.py @@ -28,15 +28,15 @@ from rich.table import Table from rich.text import Text -from mindquantum.utils.quantifiers import quantifier_selector -from mindquantum.utils.type_value_check import ( +from quafu.utils.quantifiers import quantifier_selector +from quafu.utils.type_value_check import ( _check_and_generate_pr_type, _check_gate_has_obj, _check_gate_type, _check_input_type, ) -from .. import gates as mq_gates +from .. import gates as quafu_gates from ..gates.basic import BasicGate, ParameterGate from ..parameterresolver import ParameterResolver @@ -79,8 +79,8 @@ def apply(circuit_fn, qubits): TypeError: If `circuit_fn` is not Circuit or can not return a Circuit. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import apply + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import apply >>> u1 = qft([0, 1]) >>> u2 = apply(u1, [1, 0]) >>> u3 = apply(qft, [1, 0]) @@ -120,7 +120,7 @@ def wrapper(*arg, **keywords): raise TypeError("circuit_fn need a circuit or a function that can generate a circuit.") -GateSeq = List[mq_gates.BasicGate] +GateSeq = List[quafu_gates.BasicGate] def _two_dim_array_to_list(data): @@ -254,8 +254,8 @@ class Circuit(list): # pylint: disable=too-many-instance-attributes,too-many-pu Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RX, X + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RX, X >>> circuit1 = Circuit() >>> circuit1 += RX('a').on(0) >>> circuit1 *= 2 @@ -341,9 +341,9 @@ def append(self, gate): """ _check_gate_type(gate) _check_gate_has_obj(gate) - if isinstance(gate, mq_gates.Measure): + if isinstance(gate, quafu_gates.Measure): self.all_measures.collect_only_one(gate, f'measure key {gate.key} already exist.') - if isinstance(gate, mq_gates.NoiseGate): + if isinstance(gate, quafu_gates.NoiseGate): self.all_noises.collect(gate.name) self.all_qubits.collect(gate.obj_qubits) self.all_qubits.collect(gate.ctrl_qubits) @@ -390,7 +390,7 @@ def copy(self): def __eq__(self, other: "Circuit"): """Whether equal to the other Circuit.""" - from mindquantum.core.gates import BarrierGate + from quafu.core.gates import BarrierGate _check_input_type("other", Circuit, other) if len(self) != len(other): @@ -419,7 +419,7 @@ def __add__(self, gates): """Addition operator.""" out = Circuit() out.extend(self) - if isinstance(gates, mq_gates.BasicGate): + if isinstance(gates, quafu_gates.BasicGate): out.append(gates) else: out.extend(gates) @@ -433,7 +433,7 @@ def __radd__(self, gates): def __iadd__(self, gates): """In-place addition operator.""" - if isinstance(gates, mq_gates.BasicGate): + if isinstance(gates, quafu_gates.BasicGate): self.append(gates) elif isinstance(gates, Circuit): self.extend(gates) @@ -480,18 +480,18 @@ def __setitem__(self, k, v): self.all_paras.delete(list(coeff.keys())) self.all_ansatz.delete(list(coeff.ansatz_parameters)) self.all_encoder.delete(list(coeff.encoder_parameters)) - if isinstance(old_v, mq_gates.Measure): + if isinstance(old_v, quafu_gates.Measure): self.all_measures.delete(old_v) - if isinstance(old_v, mq_gates.NoiseGate): + if isinstance(old_v, quafu_gates.NoiseGate): self.all_noises.delete(old_v.name) super().__setitem__(k, v) self.all_qubits.collect(v.obj_qubits) self.all_qubits.collect(v.ctrl_qubits) if v.parameterized: self._collect_parameterized_gate(v) - if isinstance(v, mq_gates.Measure): + if isinstance(v, quafu_gates.Measure): self.all_measures.collect_only_one(v, f'measure key {v.key} already exist.') - if isinstance(v, mq_gates.NoiseGate): + if isinstance(v, quafu_gates.NoiseGate): self.all_noises.collect(v.name) self.has_cpp_obj = False self.has_herm_cpp_obj = False @@ -548,7 +548,7 @@ def insert(self, index, gates): index (int): Index to set gate. gates (Union[BasicGate, list[BasicGate]]): Gates you need to insert. """ - if isinstance(gates, mq_gates.BasicGate): + if isinstance(gates, quafu_gates.BasicGate): _check_gate_has_obj(gates) _check_gate_type(gates) super().insert(index, gates) @@ -556,7 +556,7 @@ def insert(self, index, gates): self.all_qubits.collect(gates.ctrl_qubits) if gates.parameterized: self._collect_parameterized_gate(gates) - if isinstance(gates, mq_gates.Measure): + if isinstance(gates, quafu_gates.Measure): self.all_measures.collect_only_one(gates, f'measure key {gates.key} already exist.') elif isinstance(gates, Iterable): for gate in gates[::-1] if index > 0 else gates: @@ -565,7 +565,7 @@ def insert(self, index, gates): self.all_qubits.collect(gate.ctrl_qubits) if gate.parameterized: self._collect_parameterized_gate(gate) - if isinstance(gate, mq_gates.Measure): + if isinstance(gate, quafu_gates.Measure): self.all_measures.collect_only_one(gate, f'measure key {gate.key} already exist.') else: raise TypeError(f"Unsupported type for quantum gate: {type(gates)}") @@ -593,7 +593,7 @@ def compress(self): Remove all unused qubits, and map qubits to `range(n_qubits)`. Examples: - >>> from mindquantum.algorithm.library import qft + >>> from quafu.algorithm.library import qft >>> qft([0, 2, 4]) ┏━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ q0: ──┨ H ┠─┨ PS(π/2) ┠─┨ PS(π/4) ┠─────────────────────────╳─── @@ -624,9 +624,9 @@ def __str__(self): def __repr__(self): """Return a string representation of the object.""" # pylint: disable=import-outside-toplevel - from mindquantum.io.display._config import _text_circ_config - from mindquantum.io.display.circuit_text_drawer import rich_circuit - from mindquantum.io.display.circuit_text_drawer_helper import Monitor + from quafu.io.display._config import _text_circ_config + from quafu.io.display.circuit_text_drawer import rich_circuit + from quafu.io.display.circuit_text_drawer_helper import Monitor if not self: return "" @@ -650,12 +650,12 @@ def __repr__(self): def _repr_html_(self): """Repr for jupyter notebook.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display._config import ( + from quafu.io.display._config import ( CIRCUIT_HTML_FORMAT, _text_circ_config, ) - from mindquantum.io.display.circuit_text_drawer import rich_circuit - from mindquantum.io.display.circuit_text_drawer_helper import Monitor + from quafu.io.display.circuit_text_drawer import rich_circuit + from quafu.io.display.circuit_text_drawer_helper import Monitor if not self: return "" @@ -712,7 +712,7 @@ def depth(self, with_single: bool = True, with_barrier: bool = False) -> int: >>> circ.depth(with_single=False, with_barrier=False) 2 """ - from mindquantum.core.gates import NoiseGate, BarrierGate, Measure + from quafu.core.gates import NoiseGate, BarrierGate, Measure depth_stack = {i: 0 for i in range(self.n_qubits)} if not depth_stack: @@ -758,8 +758,8 @@ def summary(self, show=True): show (bool): whether to show the information. Default: ``True``. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RX, H + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RX, H >>> circuit = Circuit([RX('a').on(1), H.on(1), RX('b').on(0)]) >>> circuit.summary() Circuit Summary @@ -784,13 +784,13 @@ def summary(self, show=True): noise_channel = 0 measure_gate = 0 for gate in self: - if isinstance(gate, mq_gates.BarrierGate): + if isinstance(gate, quafu_gates.BarrierGate): barrier += 1 continue - if isinstance(gate, mq_gates.NoiseGate): + if isinstance(gate, quafu_gates.NoiseGate): noise_channel += 1 continue - if isinstance(gate, mq_gates.Measure): + if isinstance(gate, quafu_gates.Measure): measure_gate += 1 continue if gate.parameterized: @@ -832,8 +832,8 @@ def hermitian(self): Get the hermitian of this quantum circuit. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import RX + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import RX >>> circ = Circuit(RX({'a': 0.2}).on(0)) >>> herm_circ = circ.hermitian() >>> print(herm_circ) @@ -871,8 +871,8 @@ def params_name(self): list, a list that contains the parameter name. Examples: - >>> from mindquantum.core.gates import RX - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import RX + >>> from quafu.core.circuit import Circuit >>> circuit = Circuit(RX({'a': 1, 'b': 2}).on(0)) >>> circuit.params_name ['a', 'b'] @@ -888,8 +888,8 @@ def encoder_params_name(self): list, a list that contains the parameter name that works as encoder. Examples: - >>> from mindquantum.core.gates import RX, RY - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import RX, RY + >>> from quafu.core.circuit import Circuit >>> circuit = Circuit(RX({'a': 1, 'b': 2}).on(0)).as_encoder() >>> circuit += Circuit(RY('c').on(0)).as_ansatz() >>> circuit.encoder_params_name @@ -906,8 +906,8 @@ def ansatz_params_name(self): list, a list that contains the parameter name that works as ansatz. Examples: - >>> from mindquantum.core.gates import RX, RY - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import RX, RY + >>> from quafu.core.circuit import Circuit >>> circuit = Circuit(RX({'a': 1, 'b': 2}).on(0)).as_encoder() >>> circuit += Circuit(RY('c').on(0)).as_ansatz() >>> circuit.ansatz_params_name @@ -933,14 +933,14 @@ def is_measure_end(self): for gate in circ: for idx in set(gate.obj_qubits + gate.ctrl_qubits): high[idx] += 1 - if isinstance(gate, mq_gates.Measure): + if isinstance(gate, quafu_gates.Measure): m_idx = gate.obj_qubits[0] measure_num[m_idx] += 1 if high[m_idx] != circ.all_qubits.map[m_idx]: return False return all(x == 1 for x in measure_num) - def matrix(self, pr=None, big_end=False, backend='mqvector', seed=None, dtype=None): + def matrix(self, pr=None, big_end=False, backend='quafuvector', seed=None, dtype=None): """ Get the matrix of this circuit. @@ -948,15 +948,15 @@ def matrix(self, pr=None, big_end=False, backend='mqvector', seed=None, dtype=No pr (ParameterResolver, dict, numpy.ndarray, list, numbers.Number): The parameter resolver for parameterized quantum circuit. Default: None. big_end (bool): The low index qubit is place in the end or not. Default: False. - backend (str): The backend to do simulation. Default: 'mqvector'. + backend (str): The backend to do simulation. Default: 'quafuvector'. seed (int): The random to generate circuit matrix, if the circuit has noise channel. - dtype (mindquantum.dtype): data type of simulator. Default: 'None'. + dtype (quafu.dtype): data type of simulator. Default: 'None'. Returns: numpy.ndarray, two dimensional complex matrix of this circuit. Examples: - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import Circuit >>> circuit = Circuit().rx('a',0).h(0) >>> circuit.matrix({'a': 1.0}) array([[ 0.62054458-0.33900505j, 0.62054458-0.33900505j], @@ -974,10 +974,10 @@ def matrix(self, pr=None, big_end=False, backend='mqvector', seed=None, dtype=No raise ValueError("This circuit cannot have measurement gate.") if self.is_noise_circuit: raise ValueError("This circuit cannot have noise channel.") - if backend.startswith('mqmatrix'): - raise ValueError("mqmatrix backend not support to get circuit matrix.") + if backend.startswith('quafumatrix'): + raise ValueError("quafumatrix backend not support to get circuit matrix.") # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.simulator import Simulator + from quafu.simulator import Simulator sim = Simulator(backend, self.n_qubits, seed=seed, dtype=dtype) return np.array(sim.backend.get_circuit_matrix(circ, pr)).T @@ -993,8 +993,8 @@ def apply_value(self, pr): Circuit, a non parameterized circuit. Examples: - >>> from mindquantum.core.gates import X, RX - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import X, RX + >>> from quafu.core.circuit import Circuit >>> circuit = Circuit() >>> circuit += X.on(0) >>> circuit += RX({'a': 2}).on(0) @@ -1029,7 +1029,7 @@ def display_detail(state: bool): state (bool): The state of whether to display the detail of circuit. Examples: - >>> from mindquantum import Circuit + >>> from quafu import Circuit >>> circ = Circuit().rx('a', 0).ry(1.2, 0) >>> circ ┏━━━━━━━┓ ┏━━━━━━━━━┓ @@ -1042,7 +1042,7 @@ def display_detail(state: bool): ┗━━━━┛┗━━━━┛ """ # pylint: disable=import-outside-toplevel - from mindquantum.io.display._config import _text_circ_config + from quafu.io.display._config import _text_circ_config _text_circ_config.simple_mode = not state @@ -1050,7 +1050,7 @@ def remove_barrier(self): """Remove all barrier gates.""" circ = Circuit() for gate in self: - if not isinstance(gate, mq_gates.BarrierGate): + if not isinstance(gate, quafu_gates.BarrierGate): circ += gate return circ @@ -1058,7 +1058,7 @@ def remove_measure(self): """Remove all measure gate.""" circ = Circuit() for gate in self: - if not isinstance(gate, mq_gates.Measure): + if not isinstance(gate, quafu_gates.Measure): circ += gate return circ @@ -1070,8 +1070,8 @@ def remove_measure_on_qubits(self, qubits): qubit (Union[int, list[int]]): The qubits you want to remove measure. Examples: - >>> from mindquantum.core.circuit import UN - >>> from mindquantum.core.gates import H, Measure + >>> from quafu.core.circuit import UN + >>> from quafu.core.gates import H, Measure >>> circ = UN(H, 3).x(0, 1).x(1, 2).measure_all() >>> circ += H.on(0) >>> circ += Measure('q0_1').on(0) @@ -1091,7 +1091,7 @@ def remove_measure_on_qubits(self, qubits): qubits = [qubits] circ = Circuit() for gate in self: - if isinstance(gate, mq_gates.Measure) and gate.obj_qubits[0] in qubits: + if isinstance(gate, quafu_gates.Measure) and gate.obj_qubits[0] in qubits: continue circ += gate return circ @@ -1107,7 +1107,7 @@ def get_cpp_obj(self, hermitian=False): if not self.has_herm_cpp_obj: self.has_herm_cpp_obj = True self.herm_cpp_obj = [ - i.get_cpp_obj() for i in self.hermitian() if not isinstance(i, mq_gates.BarrierGate) + i.get_cpp_obj() for i in self.hermitian() if not isinstance(i, quafu_gates.BarrierGate) ] if hasattr(self, 'herm_cpp_obj'): return self.herm_cpp_obj @@ -1115,7 +1115,7 @@ def get_cpp_obj(self, hermitian=False): if not self.has_cpp_obj: self.has_cpp_obj = True - self.cpp_obj = [i.get_cpp_obj() for i in self if not isinstance(i, mq_gates.BarrierGate)] + self.cpp_obj = [i.get_cpp_obj() for i in self if not isinstance(i, quafu_gates.BarrierGate)] if hasattr(self, 'cpp_obj'): return self.cpp_obj raise ValueError("Circuit does not generate cpp obj yet.") @@ -1128,7 +1128,7 @@ def h(self, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `H` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `H` gate. Default: ``None``. """ - self.append(mq_gates.H.on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.H.on(obj_qubits, ctrl_qubits)) return self def x(self, obj_qubits, ctrl_qubits=None): @@ -1139,7 +1139,7 @@ def x(self, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `X` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `X` gate. Default: ``None``. """ - self.append(mq_gates.X.on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.X.on(obj_qubits, ctrl_qubits)) return self def y(self, obj_qubits, ctrl_qubits=None): @@ -1150,7 +1150,7 @@ def y(self, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Y` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Y` gate. Default: ``None``. """ - self.append(mq_gates.Y.on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Y.on(obj_qubits, ctrl_qubits)) return self def z(self, obj_qubits, ctrl_qubits=None): @@ -1161,7 +1161,7 @@ def z(self, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Z` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Z` gate. Default: ``None``. """ - self.append(mq_gates.Z.on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Z.on(obj_qubits, ctrl_qubits)) return self def s(self, obj_qubits, ctrl_qubits=None, hermitian=False): @@ -1173,7 +1173,7 @@ def s(self, obj_qubits, ctrl_qubits=None, hermitian=False): ctrl_qubits (Union[int, list[int]]): the control qubits of `S` gate. Default: ``None``. hermitian (bool): Whether use the hermitian conjugated version. Default: ``False``. """ - gate = mq_gates.S.on(obj_qubits, ctrl_qubits) + gate = quafu_gates.S.on(obj_qubits, ctrl_qubits) if hermitian: gate = gate.hermitian() self.append(gate) @@ -1188,7 +1188,7 @@ def t(self, obj_qubits, ctrl_qubits=None, hermitian=False): ctrl_qubits (Union[int, list[int]]): the control qubits of `T` gate. Default: ``None``. hermitian (bool): Whether use the hermitian conjugated version. Default: ``False``. """ - gate = mq_gates.T.on(obj_qubits, ctrl_qubits) + gate = quafu_gates.T.on(obj_qubits, ctrl_qubits) if hermitian: gate = gate.hermitian() self.append(gate) @@ -1196,7 +1196,7 @@ def t(self, obj_qubits, ctrl_qubits=None, hermitian=False): def to_openqasm(self, file_name: Optional[str] = None, version: str = '2.0') -> str: """ - Convert a MindQuantum circuit to OpenQASM format string and optionally save to a file. + Convert a quafu circuit to OpenQASM format string and optionally save to a file. Args: file_name (str): File name if you want to save OpenQASM. Default: ``None``. @@ -1206,7 +1206,7 @@ def to_openqasm(self, file_name: Optional[str] = None, version: str = '2.0') -> str, The OpenQASM format string representation of the circuit. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.qasm import OpenQASM + from quafu.io.qasm import OpenQASM qasm_str = OpenQASM().to_string(self, version=version) if file_name is not None: @@ -1215,7 +1215,7 @@ def to_openqasm(self, file_name: Optional[str] = None, version: str = '2.0') -> def to_hiqasm(self, file_name: Optional[str] = None, version: str = '0.1') -> str: """ - Convert a MindQuantum circuit to HiQASM format string and optionally save to a file. + Convert a quafu circuit to HiQASM format string and optionally save to a file. Args: file_name (str): File name if you want to save HiQASM. Default: ``None``. @@ -1225,7 +1225,7 @@ def to_hiqasm(self, file_name: Optional[str] = None, version: str = '0.1') -> st str, The HiQASM format string representation of the circuit. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.qasm import HiQASM + from quafu.io.qasm import HiQASM hiqasm_str = HiQASM().to_string(self, version=version) if file_name is not None: @@ -1234,7 +1234,7 @@ def to_hiqasm(self, file_name: Optional[str] = None, version: str = '0.1') -> st def to_qcis(self, file_name: Optional[str] = None, parametric: bool = True) -> str: """ - Convert a MindQuantum circuit to QCIS format string and optionally save to a file. + Convert a quafu circuit to QCIS format string and optionally save to a file. Args: file_name (str): File name if you want to save QCIS. Default: ``None``. @@ -1247,7 +1247,7 @@ def to_qcis(self, file_name: Optional[str] = None, parametric: bool = True) -> s str, The QCIS format string representation of the circuit. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.qasm import QCIS + from quafu.io.qasm import QCIS qcis_str = QCIS().to_string(self, parametric) if file_name is not None: @@ -1263,7 +1263,7 @@ def sx(self, obj_qubits, ctrl_qubits=None, hermitian=False): ctrl_qubits (Union[int, list[int]]): the control qubits of `SX` gate. Default: ``None``. hermitian (bool): Whether use the hermitian conjugated version. Default: ``False``. """ - gate = mq_gates.SX.on(obj_qubits, ctrl_qubits) + gate = quafu_gates.SX.on(obj_qubits, ctrl_qubits) if hermitian: gate = gate.hermitian() self.append(gate) @@ -1277,7 +1277,7 @@ def swap(self, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `SWAP` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `SWAP` gate. Default: ``None``. """ - self.append(mq_gates.SWAP.on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.SWAP.on(obj_qubits, ctrl_qubits)) return self def iswap(self, obj_qubits, ctrl_qubits=None): @@ -1288,7 +1288,7 @@ def iswap(self, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `ISWAP` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `ISWAP` gate. Default: ``None``. """ - self.append(mq_gates.ISWAP.on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.ISWAP.on(obj_qubits, ctrl_qubits)) return self def swap_alpha(self, para, obj_qubits, ctrl_qubits=None): @@ -1300,7 +1300,7 @@ def swap_alpha(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `SWAPalpha` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `SWAPalpha` gate. Default: ``None``. """ - self.append(mq_gates.SWAPalpha(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.SWAPalpha(para).on(obj_qubits, ctrl_qubits)) return self def rx(self, para, obj_qubits, ctrl_qubits=None): @@ -1312,7 +1312,7 @@ def rx(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `RX` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `RX` gate. Default: ``None``. """ - self.append(mq_gates.RX(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.RX(para).on(obj_qubits, ctrl_qubits)) return self def ry(self, para, obj_qubits, ctrl_qubits=None): @@ -1324,7 +1324,7 @@ def ry(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `RY` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `RY` gate. Default: ``None``. """ - self.append(mq_gates.RY(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.RY(para).on(obj_qubits, ctrl_qubits)) return self def rz(self, para, obj_qubits, ctrl_qubits=None): @@ -1336,7 +1336,7 @@ def rz(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `RZ` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `RZ` gate. Default: ``None``. """ - self.append(mq_gates.RZ(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.RZ(para).on(obj_qubits, ctrl_qubits)) return self def phase_shift(self, para, obj_qubits, ctrl_qubits=None): @@ -1348,7 +1348,7 @@ def phase_shift(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `PhaseShift` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `PhaseShift` gate. Default: ``None``. """ - self.append(mq_gates.PhaseShift(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.PhaseShift(para).on(obj_qubits, ctrl_qubits)) return self def global_phase(self, para, obj_qubits, ctrl_qubits=None): @@ -1360,7 +1360,7 @@ def global_phase(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `GlobalPhase` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `GlobalPhase` gate. Default: ``None``. """ - self.append(mq_gates.GlobalPhase(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.GlobalPhase(para).on(obj_qubits, ctrl_qubits)) return self def givens(self, para, obj_qubits, ctrl_qubits=None): @@ -1372,7 +1372,7 @@ def givens(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Givens` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Givens` gate. Default: ``None``. """ - self.append(mq_gates.Givens(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Givens(para).on(obj_qubits, ctrl_qubits)) return self def u3(self, theta, phi, lamda, obj_qubits, ctrl_qubits=None): @@ -1386,7 +1386,7 @@ def u3(self, theta, phi, lamda, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `U3` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `U3` gate. Default: ``None``. """ - self.append(mq_gates.U3(theta, phi, lamda).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.U3(theta, phi, lamda).on(obj_qubits, ctrl_qubits)) return self def rxx(self, para, obj_qubits, ctrl_qubits=None): @@ -1398,7 +1398,7 @@ def rxx(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Rxx` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Rxx` gate. Default: ``None``. """ - self.append(mq_gates.Rxx(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Rxx(para).on(obj_qubits, ctrl_qubits)) return self def rxy(self, para, obj_qubits, ctrl_qubits=None): @@ -1410,7 +1410,7 @@ def rxy(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Rxy` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Rxy` gate. Default: ``None``. """ - self.append(mq_gates.Rxy(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Rxy(para).on(obj_qubits, ctrl_qubits)) return self def rxz(self, para, obj_qubits, ctrl_qubits=None): @@ -1422,7 +1422,7 @@ def rxz(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Rxz` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Rxz` gate. Default: ``None``. """ - self.append(mq_gates.Rxz(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Rxz(para).on(obj_qubits, ctrl_qubits)) return self def ryy(self, para, obj_qubits, ctrl_qubits=None): @@ -1434,7 +1434,7 @@ def ryy(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Ryy` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Ryy` gate. Default: ``None``. """ - self.append(mq_gates.Ryy(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Ryy(para).on(obj_qubits, ctrl_qubits)) return self def ryz(self, para, obj_qubits, ctrl_qubits=None): @@ -1446,7 +1446,7 @@ def ryz(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Ryz` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Ryz` gate. Default: ``None``. """ - self.append(mq_gates.Ryz(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Ryz(para).on(obj_qubits, ctrl_qubits)) return self def rzz(self, para, obj_qubits, ctrl_qubits=None): @@ -1458,22 +1458,22 @@ def rzz(self, para, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `Rzz` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `Rzz` gate. Default: ``None``. """ - self.append(mq_gates.Rzz(para).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.Rzz(para).on(obj_qubits, ctrl_qubits)) return self @staticmethod def from_openqasm(openqasm_str: str): """ - Convert an OpenQASM string or an OpenQASM file to MindQuantum circuit. + Convert an OpenQASM string or an OpenQASM file to quafu circuit. Args: openqasm_str (str): String format of OpenQASM or an OpenQASM file name. Returns: - :class:`~.core.circuit.Circuit`, The MindQuantum circuit converted from OpenQASM. + :class:`~.core.circuit.Circuit`, The quafu circuit converted from OpenQASM. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.qasm import OpenQASM + from quafu.io.qasm import OpenQASM if os.path.exists(openqasm_str): return OpenQASM().from_file(openqasm_str) @@ -1482,16 +1482,16 @@ def from_openqasm(openqasm_str: str): @staticmethod def from_hiqasm(hiqasm_str: str): """ - Convert a HiQASM string or a HiQASM file to MindQuantum circuit. + Convert a HiQASM string or a HiQASM file to quafu circuit. Args: hiqasm_str (str): String format of HiQASM or a HiQASM file name. Returns: - :class:`~.core.circuit.Circuit`, The MindQuantum circuit converted from HiQASM. + :class:`~.core.circuit.Circuit`, The quafu circuit converted from HiQASM. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.qasm import HiQASM + from quafu.io.qasm import HiQASM if os.path.exists(hiqasm_str): return HiQASM().from_file(hiqasm_str) @@ -1500,16 +1500,16 @@ def from_hiqasm(hiqasm_str: str): @staticmethod def from_qcis(qcis_str: str): """ - Convert an QCIS string or an QCIS file to MindQuantum circuit. + Convert an QCIS string or an QCIS file to quafu circuit. Args: qcis_str (str): String format of QCIS or an QCIS file name. Returns: - :class:`~.core.circuit.Circuit`, The MindQuantum circuit converted from QCIS. + :class:`~.core.circuit.Circuit`, The quafu circuit converted from QCIS. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.qasm import QCIS + from quafu.io.qasm import QCIS if os.path.exists(qcis_str): return QCIS().from_file(qcis_str) @@ -1525,7 +1525,7 @@ def fsim(self, theta, phi, obj_qubits, ctrl_qubits=None): obj_qubits (Union[int, list[int]]): The object qubits of `FSim` gate. ctrl_qubits (Union[int, list[int]]): the control qubits of `FSim` gate. Default: ``None``. """ - self.append(mq_gates.FSim(theta, phi).on(obj_qubits, ctrl_qubits)) + self.append(quafu_gates.FSim(theta, phi).on(obj_qubits, ctrl_qubits)) return self def measure(self, key, obj_qubit=None, reset_to=None): @@ -1540,9 +1540,9 @@ def measure(self, key, obj_qubit=None, reset_to=None): Default: ``None``. """ if obj_qubit is None: - self.append(mq_gates.Measure(reset_to=reset_to).on(key)) + self.append(quafu_gates.Measure(reset_to=reset_to).on(key)) else: - self.append(mq_gates.Measure(key, reset_to=reset_to).on(obj_qubit)) + self.append(quafu_gates.Measure(key, reset_to=reset_to).on(obj_qubit)) return self def measure_all(self, suffix=None, up_to: int = -1): @@ -1556,7 +1556,7 @@ def measure_all(self, suffix=None, up_to: int = -1): """ for i in range(max(self.n_qubits, up_to)): string = f"q{i}" if suffix is None else f"q{i}_{suffix}" - self += mq_gates.Measure(string).on(i) + self += quafu_gates.Measure(string).on(i) return self def barrier(self, show=True): @@ -1567,7 +1567,7 @@ def barrier(self, show=True): show (bool): Whether show barrier or not. Default: True. """ _check_input_type('show', bool, show) - self.append(mq_gates.BarrierGate(show)) + self.append(quafu_gates.BarrierGate(show)) return self def un(self, gate, maps_obj, maps_ctrl=None): @@ -1581,24 +1581,24 @@ def un(self, gate, maps_obj, maps_ctrl=None): maps_obj (Union[int, list[int]]): object qubits. maps_ctrl (Union[int, list[int]]): control qubits. Default: ``None``. """ - from mindquantum import UN # pylint: disable=import-outside-toplevel + from quafu import UN # pylint: disable=import-outside-toplevel self += UN(gate, maps_obj, maps_ctrl) return self - def get_qs(self, backend='mqvector', pr=None, ket=False, seed=None, dtype=None): + def get_qs(self, backend='quafuvector', pr=None, ket=False, seed=None, dtype=None): """ Get the final quantum state of this circuit. Args: - backend (str): Which backend you want to use. Default: ``'mqvector'``. + backend (str): Which backend you want to use. Default: ``'quafuvector'``. pr (Union[numbers.Number, ParameterResolver, dict, numpy.ndarray]): The parameter of this circuit, if this circuit is parameterized. Default: ``None``. ket (str): Whether to return the quantum state in ket format. Default: ``False``. seed (int): The random seed of simulator. Default: ``None`` - dtype (mindquantum.dtype): The data type of simulator. + dtype (quafu.dtype): The data type of simulator. """ - from mindquantum import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu import ( # pylint: disable=import-outside-toplevel,cyclic-import Simulator, ) @@ -1615,7 +1615,7 @@ def reverse_qubits(self): which may cause the measurement keys to no longer correspond to the actual measured qubits. Examples: - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().h(0).x(2, 0).y(3).x(3, 2) >>> circ ┏━━━┓ @@ -1655,12 +1655,12 @@ def svg(self, style=None, width=None, scale=None): not scale. Default: ``None``. """ # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display._config import ( + from quafu.io.display._config import ( _svg_config_dark, _svg_config_light, _svg_config_official, ) - from mindquantum.io.display.circuit_svg_drawer import SVGCircuit + from quafu.io.display.circuit_svg_drawer import SVGCircuit if width is None: width = np.inf @@ -1689,11 +1689,11 @@ def remove_noise(self): """Remove all noise gate.""" circ = Circuit() for gate in self: - if not isinstance(gate, mq_gates.NoiseGate): + if not isinstance(gate, quafu_gates.NoiseGate): circ += gate return circ - def with_noise(self, noise_gate=mq_gates.AmplitudeDampingChannel(0.001), also_ctrl=False): + def with_noise(self, noise_gate=quafu_gates.AmplitudeDampingChannel(0.001), also_ctrl=False): """ Apply noises on each gate. @@ -1704,7 +1704,7 @@ def with_noise(self, noise_gate=mq_gates.AmplitudeDampingChannel(0.001), also_ct circ = Circuit() for gate in self: circ += gate - if not isinstance(gate, (mq_gates.Measure, mq_gates.NoiseGate)): + if not isinstance(gate, (quafu_gates.Measure, quafu_gates.NoiseGate)): for i in gate.obj_qubits: circ += noise_gate.on(i) if also_ctrl: diff --git a/mindquantum/core/circuit/module_circuit.py b/quafu/core/circuit/module_circuit.py similarity index 92% rename from mindquantum/core/circuit/module_circuit.py rename to quafu/core/circuit/module_circuit.py index 673795d9f..c07b63c15 100644 --- a/mindquantum/core/circuit/module_circuit.py +++ b/quafu/core/circuit/module_circuit.py @@ -17,8 +17,8 @@ from collections.abc import Iterable -from mindquantum.core.gates import SWAP, BasicGate -from mindquantum.core.gates.basic import _check_gate_type +from quafu.core.gates import SWAP, BasicGate +from quafu.core.gates.basic import _check_gate_type from .circuit import Circuit @@ -36,8 +36,8 @@ class UN(Circuit): Circuit, Return a quantum circuit. Examples: - >>> from mindquantum.core.circuit import UN - >>> from mindquantum.core.gates import X + >>> from quafu.core.circuit import UN + >>> from quafu.core.gates import X >>> circuit1 = UN(X, maps_obj = [0, 1], maps_ctrl = [2, 3]) >>> print(circuit1) ┏━━━┓ @@ -51,7 +51,7 @@ class UN(Circuit): ┃ ┃ q3: ──────────■───── - >>> from mindquantum.core.gates import SWAP + >>> from quafu.core.gates import SWAP >>> circuit2 = UN(SWAP, maps_obj =[[0, 1], [2, 3]]).x(2, 1) >>> print(circuit2) q0: ──╳───────── @@ -100,7 +100,7 @@ class SwapParts(Circuit): different qubits or just no control qubit. Default: ``None``. Examples: - >>> from mindquantum.core.circuit import SwapParts + >>> from quafu.core.circuit import SwapParts >>> SwapParts([1, 2], [3, 4], 0) q0: ──■─■─── ┃ ┃ diff --git a/mindquantum/core/circuit/qfi.py b/quafu/core/circuit/qfi.py similarity index 93% rename from mindquantum/core/circuit/qfi.py rename to quafu/core/circuit/qfi.py index f12c7344c..a0ff0f3d5 100644 --- a/mindquantum/core/circuit/qfi.py +++ b/quafu/core/circuit/qfi.py @@ -16,7 +16,7 @@ import numpy as np -from mindquantum.core.gates.basicgate import MultiParamsGate +from quafu.core.gates.basicgate import MultiParamsGate from ...utils.type_value_check import _check_and_generate_pr_type, _check_input_type from ..parameterresolver import ParameterResolver @@ -40,7 +40,7 @@ def apply_gate(sim, gate, g_cpp, pr_cpp, diff): # pylint: disable=too-many-statements,too-many-locals -def _qfi_matrix_base(circuit: Circuit, which_part='both', backend='mqvector'): +def _qfi_matrix_base(circuit: Circuit, which_part='both', backend='quafuvector'): """Calculate Quantum Fisher Information (QFI).""" from ...simulator import ( # pylint: disable=import-outside-toplevel,cyclic-import Simulator, @@ -141,7 +141,7 @@ def qfi_ops(pr: ParameterResolver): return qfi_ops -def qfi(circuit: Circuit, backend='mqvector'): +def qfi(circuit: Circuit, backend='quafuvector'): r""" Calculate the quantum fisher information of the given parameterized circuit with given parameters. @@ -168,14 +168,14 @@ def qfi(circuit: Circuit, backend='mqvector'): Args: circuit (Circuit): A parameterized quantum circuit. backend (str): A supported simulator backend. Please refer description - of :class:`~.simulator.Simulator`. Default: ``'mqvector'``. + of :class:`~.simulator.Simulator`. Default: ``'quafuvector'``. Returns: Function, a function that can calculate quantum fisher information. Examples: >>> import numpy as np - >>> from mindquantum.core.circuit import qfi, Circuit + >>> from quafucircuit import qfi, Circuit >>> circ = Circuit().rx('a', 0).ry('b', 0).rz('c', 0) >>> qfi_ops = qfi(circ) >>> qfi_ops(np.array([1, 2, 3])) @@ -194,7 +194,7 @@ def qfi_ops(pr): return qfi_ops -def partial_psi_partial_psi(circuit: Circuit, backend='mqvector'): +def partial_psi_partial_psi(circuit: Circuit, backend='quafuvector'): r""" Calculate the following value of the given parameterized quantum circuit. @@ -206,14 +206,14 @@ def partial_psi_partial_psi(circuit: Circuit, backend='mqvector'): Args: circuit (Circuit): A parameterized quantum circuit. backend (str): A supported simulator backend. Please refer description - of :class:`~.simulator.Simulator`. Default: ``'mqvector'``. + of :class:`~.simulator.Simulator`. Default: ``'quafuvector'``. Returns: Function, a function that can calculate inner product of partial psi and partial psi. Examples: >>> import numpy as np - >>> from mindquantum.core.circuit import partial_psi_partial_psi, Circuit + >>> from quafucircuit import partial_psi_partial_psi, Circuit >>> circ = Circuit().rx('a', 0).ry('b', 0).rz('c', 0) >>> pppp_ops = partial_psi_partial_psi(circ) >>> pppp_ops(np.array([1, 2, 3])) @@ -227,7 +227,7 @@ def partial_psi_partial_psi(circuit: Circuit, backend='mqvector'): return _qfi_matrix_base(circuit, 'A', backend=backend) -def partial_psi_psi(circuit: Circuit, backend='mqvector'): +def partial_psi_psi(circuit: Circuit, backend='quafuvector'): r""" Calculate the following value of the given parameterized quantum circuit. @@ -238,14 +238,14 @@ def partial_psi_psi(circuit: Circuit, backend='mqvector'): Args: circuit (Circuit): A parameterized quantum circuit. backend (str): A supported simulator backend. Please refer description - of :class:`~.simulator.Simulator`. Default: ``'mqvector'``. + of :class:`~.simulator.Simulator`. Default: ``'quafuvector'``. Returns: Function, a function that can calculate inner product of partial psi and psi. Examples: >>> import numpy as np - >>> from mindquantum.core.circuit import partial_psi_psi, Circuit + >>> from quafucircuit import partial_psi_psi, Circuit >>> circ = Circuit().rx('a', 0).ry('b', 0).rz('c', 0) >>> ppp = partial_psi_psi(circ) >>> ppp(np.array([1, 2, 3])) diff --git a/mindquantum/core/circuit/utils.py b/quafu/core/circuit/utils.py similarity index 93% rename from mindquantum/core/circuit/utils.py rename to quafu/core/circuit/utils.py index 460b443c1..c0005b983 100644 --- a/mindquantum/core/circuit/utils.py +++ b/quafu/core/circuit/utils.py @@ -12,15 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Tools for MindQuantum eDSL.""" +"""Tools for quafu eDSL.""" import copy from types import FunctionType, MethodType import numpy as np -from mindquantum.core.gates.basic import ParameterGate -from mindquantum.utils.type_value_check import _check_input_type +from quafu.core.gates.basic import ParameterGate +from quafu.utils.type_value_check import _check_input_type from ..parameterresolver.parameterresolver import ParameterResolver from .circuit import Circuit, apply @@ -49,8 +49,8 @@ def decompose_single_term_time_evolution(term, para): # pylint: disable=too-man TypeError: If `term` is not map. Examples: - >>> from mindquantum.core.operators import QubitOperator - >>> from mindquantum.core.circuit import decompose_single_term_time_evolution + >>> from quafu.core.operators import QubitOperator + >>> from quafu.core.circuit import decompose_single_term_time_evolution >>> ham = QubitOperator('X0 Y1') >>> circuit = decompose_single_term_time_evolution(ham, {'a':1}) >>> print(circuit) @@ -62,8 +62,8 @@ def decompose_single_term_time_evolution(term, para): # pylint: disable=too-man ┗━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━┛ """ # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.core import gates - from mindquantum.utils.type_value_check import _num_type + from quafu.core import gates + from quafu.utils.type_value_check import _num_type if not isinstance(term, tuple): try: @@ -126,9 +126,9 @@ def pauli_word_to_circuits(qubitops): ValueError: If qubitops has more than one pauli words. Examples: - >>> from mindquantum.core import X - >>> from mindquantum.core.operators import QubitOperator - >>> from mindquantum.core.circuit import pauli_word_to_circuits + >>> from quafu.core import X + >>> from quafu.core.operators import QubitOperator + >>> from quafu.core.circuit import pauli_word_to_circuits >>> qubitops = QubitOperator('X0 Y1') >>> pauli_word_to_circuits(qubitops) + X(1, 0) ┏━━━┓ @@ -139,8 +139,8 @@ def pauli_word_to_circuits(qubitops): ┗━━━┛ ┗━━━┛ """ # pylint: disable=import-outside-toplevel - from mindquantum import operators as ops - from mindquantum.core import gates + from quafu import operators as ops + from quafu.core import gates allow_ops = (ops.QubitOperator, ops.Hamiltonian) if not isinstance(qubitops, allow_ops): @@ -165,7 +165,7 @@ def pauli_word_to_circuits(qubitops): def _add_ctrl_qubits(circ, ctrl_qubits): """Add control qubits on a circuit.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.core import gates + from quafu.core import gates if not isinstance(ctrl_qubits, (int, list)): raise TypeError(f"Require a int or a list of int for ctrl_qubits, but get {type(ctrl_qubits)}!") @@ -209,8 +209,8 @@ def controlled(circuit_fn): TypeError: `circuit_fn` is not a Circuit or can not return a Circuit. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import controlled + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import controlled >>> u1 = qft([0, 1]) >>> u2 = controlled(u1) >>> u3 = controlled(qft) @@ -265,8 +265,8 @@ def dagger(circuit_fn): TypeError: If `circuit_fn` is not a Circuit or can not return a Circuit. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import dagger + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import dagger >>> u1 = qft([0, 1]) >>> u2 = dagger(u1) >>> u3 = dagger(qft) @@ -366,9 +366,9 @@ def add_prefix(circuit_fn, prefix: str): TypeError: `circuit_fn` is not a Circuit or can not return a Circuit. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import add_prefix - >>> from mindquantum import RX, H, Circuit + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import add_prefix + >>> from quafu import RX, H, Circuit >>> u = lambda qubit: Circuit([H.on(0), RX('a').on(qubit)]) >>> u1 = u(0) >>> u2 = add_prefix(u1, 'ansatz') @@ -405,9 +405,9 @@ def add_suffix(circuit_fn, suffix: str): TypeError: circuit_fn is not a Circuit or can not return a Circuit. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import add_suffix - >>> from mindquantum import RX, H, Circuit + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import add_suffix + >>> from quafu import RX, H, Circuit >>> u = lambda qubit: Circuit([H.on(0), RX('a').on(qubit)]) >>> u1 = u(0) >>> u2 = add_suffix(u1, '1') @@ -434,7 +434,7 @@ def shift(circ, inc): inc (int): The qubit distance you want to shift. Examples: - >>> from mindquantum.core.circuit import shift, Circuit + >>> from quafu.core.circuit import shift, Circuit >>> circ = Circuit().x(1, 0) >>> circ q0: ────■───── @@ -504,9 +504,9 @@ def change_param_name(circuit_fn, name_map): TypeError: If `circuit_fn` is not a Circuit or can not return a Circuit. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import change_param_name, Circuit - >>> from mindquantum.core.gates import RX, H + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import change_param_name, Circuit + >>> from quafu.core.gates import RX, H >>> u = lambda qubit: Circuit([H.on(0), RX('a').on(qubit)]) >>> u1 = u(0) >>> u2 = change_param_name(u1, {'a': 'b'}) @@ -555,8 +555,8 @@ def as_encoder(circuit_fn): Circuit, if `circuit_fn` is already a Circuit. Examples: - >>> from mindquantum.core.circuit import as_encoder, Circuit - >>> from mindquantum.core.gates import RX + >>> from quafu.core.circuit import as_encoder, Circuit + >>> from quafu.core.gates import RX >>> @as_encoder ... def create_circuit(): ... circ = Circuit() @@ -602,8 +602,8 @@ def as_ansatz(circuit_fn): Circuit, if `circuit_fn` is already a Circuit. Examples: - >>> from mindquantum.core.circuit import as_ansatz, Circuit - >>> from mindquantum.core.gates import RX + >>> from quafu.core.circuit import as_ansatz, Circuit + >>> from quafu.core.gates import RX >>> @as_ansatz ... def create_circuit(): ... circ = Circuit() diff --git a/mindquantum/core/gates/__init__.py b/quafu/core/gates/__init__.py similarity index 100% rename from mindquantum/core/gates/__init__.py rename to quafu/core/gates/__init__.py diff --git a/mindquantum/core/gates/basic.py b/quafu/core/gates/basic.py similarity index 97% rename from mindquantum/core/gates/basic.py rename to quafu/core/gates/basic.py index 66780987e..2245cf909 100644 --- a/mindquantum/core/gates/basic.py +++ b/quafu/core/gates/basic.py @@ -23,10 +23,10 @@ import numpy as np import scipy -from mindquantum.utils.f import pauli_string_matrix -from mindquantum.utils.quantifiers import s_quantifier -from mindquantum.utils.string_utils import join_without_empty -from mindquantum.utils.type_value_check import ( +from quafu.utils.f import pauli_string_matrix +from quafu.utils.quantifiers import s_quantifier +from quafu.utils.string_utils import join_without_empty +from quafu.utils.type_value_check import ( _check_gate_type, _check_input_type, _check_qubit_id, @@ -165,7 +165,7 @@ def on(self, obj_qubits, ctrl_qubits=None): # pylint: disable=invalid-name Gate, Return a new gate. Examples: - >>> from mindquantum.core.gates import X + >>> from quafu.core.gates import X >>> x = X.on(1) >>> x.obj_qubits [1] @@ -273,7 +273,7 @@ class QuantumGate(BasicGate): def __commutate__(self, other: BasicGate): """Indicate whether a gate commutes.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.core.circuit import UN, Circuit + from quafu.core.circuit import UN, Circuit from .basicgate import I @@ -328,7 +328,7 @@ def hermitian(self): def __type_specific_str__(self): """Return a string representation of the object.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display._config import _DAGGER_MASK + from quafu.io.display._config import _DAGGER_MASK return _DAGGER_MASK if self.hermitianed else '' @@ -345,7 +345,7 @@ def __str_in_circ__(self): def __str_in_svg__(self): """Return a string representation of the object.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display._config import _DAGGER_MASK + from quafu.io.display._config import _DAGGER_MASK string = super().__str_in_svg__() if self.hermitianed: @@ -376,7 +376,7 @@ def matrix(self, full=False): # pylint: disable=arguments-differ _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix() return self.matrix_value @@ -549,7 +549,7 @@ def matrix(self, full=False): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix() @@ -650,7 +650,7 @@ def matrix(self, pr=None, frac=0.5, full=False): # pylint: disable=arguments-di _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) @@ -721,7 +721,7 @@ def matrix(self, pr=None, full=False): # pylint: disable=arguments-differ numpy.ndarray, Return the numpy array of the matrix. Examples: - >>> from mindquantum.core.gates import RX + >>> from quafu.core.gates import RX >>> rx1 = RX(0) >>> rx1.matrix() array([[1.+0.j, 0.-0.j], @@ -734,7 +734,7 @@ def matrix(self, pr=None, full=False): # pylint: disable=arguments-differ _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) @@ -761,7 +761,7 @@ def diff_matrix(self, pr=None, about_what=None): numpy.ndarray, Return the numpy array of the differential matrix. Examples: - >>> from mindquantum import RX + >>> from quafu import RX >>> rx = RX('a') >>> np.round(rx.diff_matrix({'a' : 2}), 2) array([[-0.42+0.j , 0. -0.27j], diff --git a/mindquantum/core/gates/basicgate.py b/quafu/core/gates/basicgate.py similarity index 97% rename from mindquantum/core/gates/basicgate.py rename to quafu/core/gates/basicgate.py index db08d7bfe..a92f58b74 100644 --- a/mindquantum/core/gates/basicgate.py +++ b/quafu/core/gates/basicgate.py @@ -28,11 +28,11 @@ import scipy from scipy.linalg import fractional_matrix_power -from mindquantum import _math -from mindquantum import mqbackend as mb -from mindquantum.config.config import _GLOBAL_MAT_VALUE -from mindquantum.utils.f import is_power_of_two -from mindquantum.utils.type_value_check import _check_gate_type, _check_input_type, _check_numba_validation +from quafu import _math +from quafu import quafubackend as mb +from quafu.config.config import _GLOBAL_MAT_VALUE +from quafu.utils.f import is_power_of_two +from quafu.utils.type_value_check import _check_gate_type, _check_input_type, _check_numba_validation from ..parameterresolver import ParameterResolver from .basic import ( @@ -62,7 +62,7 @@ class UnivMathGate(NoneParamNonHermMat): mat (np.ndarray): the matrix value of this gate. Examples: - >>> from mindquantum.core.gates import UnivMathGate + >>> from quafu.core.gates import UnivMathGate >>> x_mat=np.array([[0,1],[1,0]]) >>> X_gate=UnivMathGate('X',x_mat) >>> x1=X_gate.on(0,1) @@ -139,8 +139,8 @@ class GroupedPauli(NoneParameterGate, SelfHermitianGate): Examples: >>> import numpy as np - >>> from mindquantum.core.gates import GroupedPauli - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import GroupedPauli + >>> from quafu.core.circuit import Circuit >>> circ1 = Circuit([GroupedPauli('XY').on([0, 1])]) >>> circ2 = Circuit().x(0).y(1) >>> np.allclose(circ1.matrix(), circ2.matrix()) @@ -192,10 +192,10 @@ def matrix(self, full=False): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix() - from mindquantum.core.operators import QubitOperator + from quafu.core.operators import QubitOperator pauli = QubitOperator(' '.join(f'{p}{i}' for i, p in enumerate(self.pauli_string))) return pauli.matrix().toarray() @@ -223,7 +223,7 @@ class XGate(PauliGate): X^\theta = RX(\theta\pi) Examples: - >>> from mindquantum.core.gates import X + >>> from quafu.core.gates import X >>> x1 = X.on(0) >>> cnot = X.on(0, 1) >>> print(x1) @@ -655,7 +655,7 @@ def matrix(self, pr=None, full=False): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix() @@ -734,7 +734,7 @@ class RX(RotSelfHermMat): parameterized gate, see above for detail explanation. Examples: - >>> from mindquantum.core.gates import RX + >>> from quafu.core.gates import RX >>> import numpy as np >>> rx1 = RX(0.5) >>> np.round(rx1.matrix(), 2) @@ -888,7 +888,7 @@ def matrix(self, pr=None, full=False): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix() @@ -994,7 +994,7 @@ def matrix(self, pr=None, full=False, **kwargs): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return super().matrix(pr, 0.5) @@ -1084,7 +1084,7 @@ def matrix(self, pr=None, full=False, **kwargs): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return super().matrix(pr, 0.5) @@ -1174,7 +1174,7 @@ def matrix(self, pr=None, full=False, **kwargs): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return super().matrix(pr, 0.5) @@ -1256,7 +1256,7 @@ def matrix(self, pr=None, full=False, **kwargs): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return super().matrix(pr, 0.5) @@ -1336,7 +1336,7 @@ def matrix(self, pr=None, full=False, **kwargs): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return super().matrix(pr, 0.5) @@ -1416,7 +1416,7 @@ def matrix(self, pr=None, full=False, **kwargs): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return super().matrix(pr, 0.5) @@ -1466,7 +1466,7 @@ def on(self, obj_qubits, ctrl_qubits=None): Returns: Gate, Return a new gate. """ - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit new = super().on(obj_qubits, ctrl_qubits) if new.ctrl_qubits: @@ -1536,7 +1536,7 @@ def matrix(self, pr=None, full=False, **kwargs): # pylint: disable=arguments-di _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) return RotSelfHermMat.matrix(self, pr, 1) @@ -1577,9 +1577,9 @@ class RotPauliString(ParameterOppsGate): Examples: >>> import numpy as np - >>> from mindquantum.core.gates import RotPauliString - >>> from mindquantum.core.operators import TimeEvolution, QubitOperator - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import RotPauliString + >>> from quafu.core.operators import TimeEvolution, QubitOperator + >>> from quafu.core.circuit import Circuit >>> g = RotPauliString('XYZ', 1.0).on([0, 1, 2]) >>> circ1 = Circuit() + g >>> circ2 = TimeEvolution(QubitOperator('X0 Y1 Z2'), 0.5).circuit @@ -1599,8 +1599,8 @@ def __init__(self, pauli_string: str, pr): def __decompose__(self): """Gate decomposition method.""" # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit, controlled - from mindquantum.core.operators import QubitOperator, TimeEvolution + from quafu.core.circuit import Circuit, controlled + from quafu.core.operators import QubitOperator, TimeEvolution if not self.acted: raise ValueError("RotPauliString gate should act to qubit first.") @@ -1626,7 +1626,7 @@ def matrix(self, pr=None, full=False): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) val = 0 @@ -1710,7 +1710,7 @@ def matrix(self, pr=None, full=False): _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) val = 0 @@ -1761,7 +1761,7 @@ class Power(NoneParamNonHermMat): exponent (int, float): The exponent. Default: ``0.5``. Examples: - >>> from mindquantum.core.gates import Power + >>> from quafu.core.gates import Power >>> import numpy as np >>> rx1 = RX(0.5) >>> rx2 = RX(1) @@ -1844,9 +1844,9 @@ def gene_univ_parameterized_gate(name, matrix_generator, diff_matrix_generator): Examples: >>> import numpy as np - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import gene_univ_parameterized_gate - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import gene_univ_parameterized_gate + >>> from quafu.simulator import Simulator >>> def matrix(alpha): ... ep = 0.5 * (1 + np.exp(1j * np.pi * alpha)) ... em = 0.5 * (1 - np.exp(1j * np.pi * alpha)) @@ -2053,8 +2053,8 @@ def gene_univ_two_params_gate(name, matrix_generator, diff_matrix_generator_1, d Examples: >>> import numpy as np - >>> from mindquantum.core.gates import gene_univ_two_params_gate - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import gene_univ_two_params_gate + >>> from quafu.core.circuit import Circuit >>> def matrix(a, b): ... ep = 0.5 * (1 + np.exp(1j * a * b)) ... em = 0.5 * (1 - np.exp(1j * a * b)) @@ -2181,7 +2181,7 @@ def matrix(self, pr: ParameterResolver = None, full=False) -> np.ndarray: """Get the matrix of this gate.""" _check_input_type('full', bool, full) if full: - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) @@ -2246,8 +2246,8 @@ class Rn(MultiParamsGate): Examples: >>> import numpy as np - >>> from mindquantum.core.parameterresolver import ParameterResolver - >>> from mindquantum.core.gates import Rn + >>> from quafu.core.parameterresolver import ParameterResolver + >>> from quafu.core.gates import Rn >>> theta = ParameterResolver('theta')/np.sqrt(3) >>> Rn(theta, theta, theta).on(0, 1) Rn(α=0.5774*theta, β=0.5774*theta, γ=0.5774*theta|0 <-: 1) @@ -2305,7 +2305,7 @@ def hermitian(self) -> "Rn": Get hermitian form of Rn gate. Examples: - >>> from mindquantum.core.gates import Rn + >>> from quafu.core.gates import Rn >>> rn = Rn('a', 'b', 0.5).on(0) >>> rn.hermitian() Rn(α=-a, β=-b, γ=-1/2|0) @@ -2328,7 +2328,7 @@ def matrix(self, pr: ParameterResolver = None, full=False) -> np.ndarray: _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) alpha = self.alpha @@ -2385,7 +2385,7 @@ class U3(MultiParamsGate): lamda (Union[numbers.Number, dict, ParameterResolver]): Third parameter for U3 gate. Examples: - >>> from mindquantum.core.gates import U3 + >>> from quafu.core.gates import U3 >>> U3('theta','phi','lambda').on(0, 1) U3(θ=theta, φ=phi, λ=lambda|0 <-: 1) """ @@ -2442,7 +2442,7 @@ def hermitian(self) -> "U3": Get hermitian form of U3 gate. Examples: - >>> from mindquantum.core.gates import U3 + >>> from quafu.core.gates import U3 >>> u3 = U3('a', 'b', 0.5).on(0) >>> u3.hermitian() U3(θ=-a, φ=-1/2, λ=-b|0) @@ -2465,7 +2465,7 @@ def matrix(self, pr: ParameterResolver = None, full=False) -> np.ndarray: _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) theta = self.theta @@ -2525,7 +2525,7 @@ class FSim(MultiParamsGate): phi (Union[numbers.Number, dict, ParameterResolver]): Second parameter for FSim gate. Examples: - >>> from mindquantum.core.gates import FSim + >>> from quafu.core.gates import FSim >>> fsim = FSim('a', 'b').on([0, 1]) >>> fsim FSim(θ=a, φ=b|0 1) @@ -2584,7 +2584,7 @@ def hermitian(self) -> "FSim": Get the hermitian gate of FSim. Examples: - >>> from mindquantum.core.gates import FSim + >>> from quafu.core.gates import FSim >>> fsim = FSim('a', 'b').on([0, 1]) >>> fsim.hermitian() FSim(θ=-a, φ=-b|0 1) @@ -2607,7 +2607,7 @@ def matrix(self, pr: ParameterResolver = None, full=False) -> np.ndarray: _check_input_type('full', bool, full) if full: # pylint: disable=import-outside-toplevel - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit return Circuit([self]).matrix(pr=pr) theta = self.theta diff --git a/mindquantum/core/gates/channel.py b/quafu/core/gates/channel.py similarity index 95% rename from mindquantum/core/gates/channel.py rename to quafu/core/gates/channel.py index 4ba5d1870..5d2e19f9b 100644 --- a/mindquantum/core/gates/channel.py +++ b/quafu/core/gates/channel.py @@ -22,9 +22,9 @@ import numpy as np import numpy.typing as npt -from mindquantum import mqbackend as mb -from mindquantum.utils.f import _check_input_type, _check_num_array -from mindquantum.utils.string_utils import string_expression +from quafu import quafubackend as mb +from quafu.utils.f import _check_input_type, _check_num_array +from quafu.utils.string_utils import string_expression from .basic import BasicGate, NoiseGate, NonHermitianGate, SelfHermitianGate @@ -49,9 +49,9 @@ class GroupedPauliChannel(NoiseGate, SelfHermitianGate): Examples: >>> import numpy as np - >>> from mindquantum.core.gates import GroupedPauliChannel - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.gates import GroupedPauliChannel + >>> from quafu.core.circuit import Circuit + >>> from quafu.simulator import Simulator >>> probs = np.array([[1.0, 0.0, 0.0], [0.0, 0.3, 0.0]]) >>> circ = Circuit([GroupedPauliChannel(probs).on([0, 1])]).measure_all() >>> circ @@ -61,7 +61,7 @@ class GroupedPauliChannel(NoiseGate, SelfHermitianGate): │ ╔═════════════════════════╗ │ ┍━━━━━━┑ q1: ──┤─╢ PC(px=0, py=3/10, pz=0) ╟───├─┤ M q1 ├─── ╰ ╚═════════════════════════╝ ╯ ┕━━━━━━┙ - >>> Simulator('mqvector', circ.n_qubits).sampling(circ, shots=1000, seed=42) + >>> Simulator('quafuvector', circ.n_qubits).sampling(circ, shots=1000, seed=42) shots: 1000 Keys: q1 q0│0.00 0.177 0.355 0.532 0.71 0.887 ───────────┼───────────┴───────────┴───────────┴───────────┴───────────┴ @@ -146,8 +146,8 @@ class PauliChannel(NoiseGate, SelfHermitianGate): pz (int, float): probability of applying Z gate. Examples: - >>> from mindquantum.core.gates import PauliChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import PauliChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += PauliChannel(0.8, 0.1, 0.1).on(0) >>> circ.measure_all() @@ -155,8 +155,8 @@ class PauliChannel(NoiseGate, SelfHermitianGate): ╔══════════════════════════════╗ ┍━━━━━━┑ q0: ──╢ PC(px=4/5, py=1/10, pz=1/10) ╟─┤ M q0 ├─── ╚══════════════════════════════╝ ┕━━━━━━┙ - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 1) + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 1) >>> sim.sampling(circ, shots=1000, seed=42) shots: 1000 Keys: q0│0.00 0.2 0.4 0.6 0.8 1.0 @@ -249,8 +249,8 @@ class BitFlipChannel(PauliChannel): p (int, float): probability of occurred error. Examples: - >>> from mindquantum.core.gates import BitFlipChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import BitFlipChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += BitFlipChannel(0.02).on(0) >>> print(circ) @@ -313,8 +313,8 @@ class PhaseFlipChannel(PauliChannel): p (int, float): probability of occurred error. Examples: - >>> from mindquantum.core.gates import PhaseFlipChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import PhaseFlipChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += PhaseFlipChannel(0.02).on(0) >>> print(circ) @@ -378,8 +378,8 @@ class BitPhaseFlipChannel(PauliChannel): p (int, float): probability of occurred error. Examples: - >>> from mindquantum.core.gates import BitPhaseFlipChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import BitPhaseFlipChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += BitPhaseFlipChannel(0.02).on(0) >>> print(circ) @@ -459,8 +459,8 @@ class DepolarizingChannel(NoiseGate, SelfHermitianGate): n_qubits (int): qubit number of this depolarizing channel. Default: ``1``. Examples: - >>> from mindquantum.core.gates import DepolarizingChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import DepolarizingChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += DepolarizingChannel(0.02).on(0) >>> circ += DepolarizingChannel(0.01, 2).on([0, 1]) @@ -515,7 +515,7 @@ def matrix(self): # pylint: disable=arguments-differ order of :math:`\left\{ I, X, Y, Z \right\} ^{\otimes N}`. """ # pylint: disable=import-outside-toplevel - from mindquantum.core.operators import QubitOperator + from quafu.core.operators import QubitOperator p = np.ones(4**self.n_qubits) * sqrt(self.p) / 2**self.n_qubits p[0] = sqrt(1 - self.p + self.p / 4**self.n_qubits) @@ -551,8 +551,8 @@ class AmplitudeDampingChannel(NoiseGate, NonHermitianGate): gamma (int, float): damping coefficient. Examples: - >>> from mindquantum.core.gates import AmplitudeDampingChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import AmplitudeDampingChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += AmplitudeDampingChannel(0.02).on(0) >>> print(circ) @@ -631,8 +631,8 @@ class PhaseDampingChannel(NoiseGate, NonHermitianGate): gamma (int, float): damping coefficient. Examples: - >>> from mindquantum.core.gates import PhaseDampingChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import PhaseDampingChannel + >>> from quafu.core.circuit import Circuit >>> circ = Circuit() >>> circ += PhaseDampingChannel(0.02).on(0) >>> print(circ) @@ -704,8 +704,8 @@ class KrausChannel(NoiseGate, NonHermitianGate): kraus_op (list, np.ndarray): Kraus operator, with two or more 2x2 matrices packaged as a list. Examples: - >>> from mindquantum.core.gates import KrausChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import KrausChannel + >>> from quafu.core.circuit import Circuit >>> from cmath import sqrt >>> gamma = 0.5 >>> kmat0 = [[1, 0], [0, sqrt(1 - gamma)]] @@ -798,8 +798,8 @@ class ThermalRelaxationChannel(NoiseGate, NonHermitianGate): gate_time (int, float): time of the quantum gate. Examples: - >>> from mindquantum.core.gates import ThermalRelaxationChannel - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.core.gates import ThermalRelaxationChannel + >>> from quafu.core.circuit import Circuit >>> t1 = 100000 >>> t2 = 50000 >>> gate_time = 35 diff --git a/mindquantum/core/gates/measurement.py b/quafu/core/gates/measurement.py similarity index 91% rename from mindquantum/core/gates/measurement.py rename to quafu/core/gates/measurement.py index 82069f5dc..7c2db02bd 100644 --- a/mindquantum/core/gates/measurement.py +++ b/quafu/core/gates/measurement.py @@ -23,9 +23,9 @@ import numpy as np from rich.console import Console -from mindquantum import mqbackend as mb -from mindquantum.utils.string_utils import join_without_empty -from mindquantum.utils.type_value_check import _check_input_type, _check_int_type +from quafu import quafubackend as mb +from quafu.utils.string_utils import join_without_empty +from quafu.utils.type_value_check import _check_input_type, _check_int_type from .basic import FunctionalGate @@ -42,10 +42,10 @@ class Measure(FunctionalGate): Examples: >>> import numpy as np - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Measure - >>> from mindquantum.simulator import Simulator + >>> from quafu.algorithm.library import qft + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Measure + >>> from quafu.simulator import Simulator >>> circ = qft(range(2)) >>> circ += Measure('q0').on(0) >>> circ += Measure().on(1) @@ -56,10 +56,10 @@ class Measure(FunctionalGate): ┃ ┏━━━┓ ┃ ┍━━━━━━┑ q1: ─────────────■──────┨ H ┠─╳─┤ M q1 ├─── ┗━━━┛ ┕━━━━━━┙ - >>> sim = Simulator('mqvector', circ.n_qubits) + >>> sim = Simulator('quafuvector', circ.n_qubits) >>> sim.apply_circuit(Circuit().h(0).x(1, 0)) >>> sim - mqvector simulator with 2 qubits (little endian). + quafuvector simulator with 2 qubits (little endian). Current quantum state: √2/2¦00⟩ √2/2¦11⟩ @@ -76,13 +76,13 @@ class Measure(FunctionalGate): │ {'00': 993, '10': 506, '11': 501} >>> sim - mqvector simulator with 2 qubits (little endian). + quafuvector simulator with 2 qubits (little endian). Current quantum state: √2/2¦00⟩ √2/2¦11⟩ >>> sim.apply_circuit(circ[:-2]) >>> sim - mqvector simulator with 2 qubits (little endian). + quafuvector simulator with 2 qubits (little endian). Current quantum state: √2/2¦00⟩ (√2/4-√2/4j)¦10⟩ @@ -171,9 +171,9 @@ class MeasureResult: Measurement result container. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 2) + >>> from quafu.algorithm.library import qft + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 2) >>> res = sim.sampling(qft(range(2)).measure_all(), shots=1000, seed=42) >>> res shots: 1000 @@ -254,9 +254,9 @@ def select_keys(self, *keys): keys (tuple[str]): The key you want to select. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.core.gates import H - >>> from mindquantum.simulator import Simulator + >>> from quafu.algorithm.library import qft + >>> from quafu.core.gates import H + >>> from quafu.simulator import Simulator >>> circ = qft(range(2)).measure('q0_0', 0).measure('q1_0', 1) >>> circ.h(0).measure('q0_1', 0) >>> circ @@ -266,7 +266,7 @@ def select_keys(self, *keys): ┃ ┏━━━┓ ┃ ┍━━━━━━━━┑ q1: ─────────────■──────┨ H ┠─╳─┤ M q1_0 ├──────────────────── ┗━━━┛ ┕━━━━━━━━┙ - >>> sim = Simulator('mqvector', circ.n_qubits) + >>> sim = Simulator('quafuvector', circ.n_qubits) >>> res = sim.sampling(circ, shots=500, seed=42) >>> new_res = res.select_keys('q0_1', 'q1_0') >>> new_res @@ -311,8 +311,8 @@ def __str__(self): def __repr__(self): """Return a string representation of the object.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display import measure_text_drawer - from mindquantum.io.display._config import _MEA_RES_STYLE + from quafu.io.display import measure_text_drawer + from quafu.io.display._config import _MEA_RES_STYLE res = measure_text_drawer(self) res.append(self.data.__str__()) @@ -327,8 +327,8 @@ def __repr__(self): def _repr_html_(self): """Repr for jupyter notebook.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display import measure_text_drawer - from mindquantum.io.display._config import _MEA_RES_STYLE, MEA_HTML_FORMAT + from quafu.io.display import measure_text_drawer + from quafu.io.display._config import _MEA_RES_STYLE, MEA_HTML_FORMAT res = measure_text_drawer(self) res.append(str(self.data)) @@ -348,8 +348,8 @@ def svg(self, style=None): ``'official'``. Default: ``None``. """ # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.io.display._config import _svg_measure_config_official - from mindquantum.io.display.measure_res_svg_drawer import SVGMeasure + from quafu.io.display._config import _svg_measure_config_official + from quafu.io.display.measure_res_svg_drawer import SVGMeasure supported_style = { 'official': _svg_measure_config_official, diff --git a/mindquantum/core/operators/__init__.py b/quafu/core/operators/__init__.py similarity index 91% rename from mindquantum/core/operators/__init__.py rename to quafu/core/operators/__init__.py index fbbea538b..ede9d1655 100644 --- a/mindquantum/core/operators/__init__.py +++ b/quafu/core/operators/__init__.py @@ -13,7 +13,7 @@ # limitations under the License. # ============================================================================ """ -MindQuantum operators library. An operator is composed of a combination of one or more basic gates. +quafu operators library. An operator is composed of a combination of one or more basic gates. Contains classes representing: @@ -25,7 +25,7 @@ """ -from mindquantum.third_party.interaction_operator import InteractionOperator +from quafu.third_party.interaction_operator import InteractionOperator from ._term_value import TermValue from .fermion_operator import FermionOperator diff --git a/mindquantum/core/operators/_base_operator.py b/quafu/core/operators/_base_operator.py similarity index 98% rename from mindquantum/core/operators/_base_operator.py rename to quafu/core/operators/_base_operator.py index ce69a6b25..6b26c994b 100644 --- a/mindquantum/core/operators/_base_operator.py +++ b/quafu/core/operators/_base_operator.py @@ -337,7 +337,7 @@ def compress(self, abs_tol=EQ_TOLERANCE) -> "_Operator": the compressed operator Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ham_compress = QubitOperator('X0 Y3', 0.5) + QubitOperator('X0 Y2', 1e-7) >>> ham_compress 1/10000000 [X0 Y2] + @@ -414,7 +414,7 @@ def singlet(self): list(_Operator): The split word of the string. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ops = QubitOperator("X0 Y1", 1) >>> print(ops.singlet()) [1 [X0] , 1 [Y1] ] @@ -438,7 +438,7 @@ def singlet_coeff(self): ParameterResolver: the coefficient of this single string operator. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ops = QubitOperator("X0 Y1", "a") >>> print(ops.singlet_coeff()) {'a': 1}, const: 0 diff --git a/mindquantum/core/operators/_term_value.py b/quafu/core/operators/_term_value.py similarity index 97% rename from mindquantum/core/operators/_term_value.py rename to quafu/core/operators/_term_value.py index 4fa17d83f..9a1e3bc7b 100644 --- a/mindquantum/core/operators/_term_value.py +++ b/quafu/core/operators/_term_value.py @@ -14,7 +14,7 @@ # ============================================================================ """MindSpore Quantum dtype module.""" # pylint: disable=import-error,invalid-name -from mindquantum._math.ops import f_term_value, p_term_value +from quafu._math.ops import f_term_value, p_term_value term_map = { 0: f_term_value.a, diff --git a/mindquantum/core/operators/fermion_operator.py b/quafu/core/operators/fermion_operator.py similarity index 91% rename from mindquantum/core/operators/fermion_operator.py rename to quafu/core/operators/fermion_operator.py index d1ea5fac6..1a3378692 100644 --- a/mindquantum/core/operators/fermion_operator.py +++ b/quafu/core/operators/fermion_operator.py @@ -23,15 +23,15 @@ import numpy as np from scipy.sparse import csr_matrix, kron -import mindquantum as mq -from mindquantum._math.ops import FermionOperator as FermionOperator_ -from mindquantum._math.ops import f_term_value -from mindquantum.core.operators._term_value import TermValue -from mindquantum.core.parameterresolver import ParameterResolver, PRConvertible -from mindquantum.dtype.dtype import str_dtype_map -from mindquantum.mqbackend import EQ_TOLERANCE -from mindquantum.third_party.interaction_operator import InteractionOperator -from mindquantum.utils.type_value_check import ( +import quafu +from quafu._math.ops import FermionOperator as FermionOperator_ +from quafu._math.ops import f_term_value +from quafu.core.operators._term_value import TermValue +from quafu.core.parameterresolver import ParameterResolver, PRConvertible +from quafu.dtype.dtype import str_dtype_map +from quafu.quafubackend import EQ_TOLERANCE +from quafu.third_party.interaction_operator import InteractionOperator +from quafu.utils.type_value_check import ( _check_and_generate_pr_type, _check_int_type, _require_package, @@ -94,7 +94,7 @@ class FermionOperator(FermionOperator_): FermionOperator or not. Default: ``False``. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> a_p_dagger = FermionOperator('1^') >>> a_p_dagger 1 [1^] @@ -288,7 +288,7 @@ def imag(self) -> "FermionOperator": Fermion, the imag part of this FermionOperator. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> f = FermionOperator('0', 1 + 2j) + FermionOperator('0^', 'a') >>> f.imag 2 [0] @@ -298,7 +298,7 @@ def imag(self) -> "FermionOperator": @property def is_complex(self) -> bool: """Return whether the FermionOperator instance is currently using complex coefficients.""" - return self.dtype in (mq.complex128, mq.complex64) + return self.dtype in (quafu.complex128, quafu.complex64) @property def is_singlet(self) -> bool: @@ -324,7 +324,7 @@ def real(self) -> "FermionOperator": FermionOperator, the real part of this FermionOperator. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> f = FermionOperator('0', 1 + 2j) + FermionOperator('0^', 'a') >>> f.real 1 [0] + @@ -352,13 +352,13 @@ def terms(self) -> typing.Dict[typing.Tuple[int, int], ParameterResolver]: @staticmethod def from_openfermion(of_ops) -> "FermionOperator": """ - Convert openfermion fermion operator to mindquantum format. + Convert openfermion fermion operator to quafu format. Args: of_ops (openfermion.FermionOperator): fermion operator from openfermion. Returns: - FermionOperator, fermion operator from mindquantum. + FermionOperator, fermion operator from quafu. """ # pylint: disable=import-outside-toplevel try: @@ -386,7 +386,7 @@ def loads(strs: str) -> "FermionOperator": FermionOperator, the FermionOperator loaded from JSON-formatted strings Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> f = FermionOperator('0', 1 + 2j) + FermionOperator('0^', 'a') >>> obj = FermionOperator.loads(f.dumps()) >>> obj == f @@ -406,18 +406,18 @@ def astype(self, dtype) -> "FermionOperator": Converting a complex type FermionOperator to real type will ignore the image part of coefficient. Args: - dtype (mindquantum.dtype): new data type of fermion operator. + dtype (quafu.dtype): new data type of fermion operator. Returns: FermionOperator, new fermion operator with given data type. Examples: - >>> from mindquantum.core.operators import FermionOperator - >>> import mindquantum as mq + >>> from quafu.core.operators import FermionOperator + >>> import quafu >>> f = FermionOperator('0^', 2 + 3j) >>> f.dtype - mindquantum.complex128 - >>> f.astype(mq.float64) + quafu.complex128 + >>> f.astype(quafu.float64) 2 [0^] """ return FermionOperator(FermionOperator_.astype(self, dtype)) @@ -425,10 +425,10 @@ def astype(self, dtype) -> "FermionOperator": def cast_complex(self) -> "FermionOperator": """Cast a FermionOperator into its complex equivalent.""" new_type = self.dtype - if new_type == mq.float32: - new_type = mq.complex64 - elif new_type == mq.float64: - new_type = mq.complex128 + if new_type == quafu.float32: + new_type = quafu.complex64 + elif new_type == quafu.float64: + new_type = quafu.complex128 return self.astype(new_type) def compress(self, abs_tol=EQ_TOLERANCE) -> "FermionOperator": @@ -442,7 +442,7 @@ def compress(self, abs_tol=EQ_TOLERANCE) -> "FermionOperator": FermionOperator, the compressed operator. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> ham_compress = FermionOperator('0^ 1', 0.5) + FermionOperator('2^ 3', 1e-7) >>> ham_compress 1/2 [0^ 1] + @@ -476,7 +476,7 @@ def count_qubits(self) -> int: int, the qubits number before remove unused qubit. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> a = FermionOperator("0^ 3") >>> a.count_qubits() 4 @@ -495,7 +495,7 @@ def dumps(self, indent: int = 4) -> str: JSON (str), the JSON strings of this FermionOperator Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> f = FermionOperator('0', 1 + 2j) + FermionOperator('0^', 'a') >>> len(f.dumps()) 581 @@ -517,7 +517,7 @@ def get_coeff(self, term) -> ParameterResolver: term (List[Tuple[int, Union[int, str]]]): the term you want get coefficient. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> f = FermionOperator('0^ 1', 1.2) >>> f.get_coeff([(1, ''), (0, '^')]) ParameterResolver(dtype: float64, const: -1.200000) @@ -534,7 +534,7 @@ def hermitian(self) -> "FermionOperator": FermionOperator, The hermitian of this FermionOperator. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> a = FermionOperator("0^ 1", {"a": 1 + 2j}) >>> a.hermitian() (1 - 2j)*a [1^ 0] @@ -554,7 +554,7 @@ def matrix(self, n_qubits: int = None, pr=None): # pylint: disable=too-many-bra if pr is None: pr = ParameterResolver() pr = _check_and_generate_pr_type(pr, self.params_name) - np_type = mq.to_np_type(self.dtype) + np_type = quafu.to_np_type(self.dtype) ops = self if self.parameterized: ops = copy.copy(self) @@ -610,7 +610,7 @@ def normal_ordered(self) -> "FermionOperator": FermionOperator, the normal ordered FermionOperator. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> origin = FermionOperator('0 1^') >>> origin 1.0 [0 1^] @@ -628,7 +628,7 @@ def relabel(self, logic_qubits: typing.List[int]) -> "FermionOperator": logic_qubits is `[2, 0, 1]`, original qubit `0` will label as `2`. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> o = FermionOperator('3^ 2 1 0') >>> o 1 [3^ 2 1 0] @@ -649,7 +649,7 @@ def singlet_coeff(self) -> ParameterResolver: RuntimeError: if the size of terms is not equal to 1. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> ops = FermionOperator("1^ 2", "a") >>> print(ops) -a [2 1^] @@ -669,7 +669,7 @@ def singlet(self) -> typing.List["FermionOperator"]: RuntimeError: if the size of terms is not equal to 1. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> ops = FermionOperator("1^ 2", 1) >>> print(ops.singlet()) [1 [2], 1 [1^]] @@ -684,7 +684,7 @@ def split(self) -> typing.Generator[ParameterResolver, "FermionOperator", None]: List[List[ParameterResolver, FermionOperator]], the split result. Examples: - >>> from mindquantum.core.operators import FermionOperator + >>> from quafu.core.operators import FermionOperator >>> a = FermionOperator('0', 'a') + FermionOperator('1^', 1.2) >>> for i, j in a.split(): ... print(i, j) @@ -702,8 +702,8 @@ def subs(self, params_value: PRConvertible) -> "FermionOperator": params_value (Union[Dict[str, numbers.Number], ParameterResolver]): the value of variable in coefficient. Examples: - >>> from mindquantum.core.operators import FermionOperator - >>> from mindquantum.core.parameterresolver import ParameterResolver + >>> from quafu.core.operators import FermionOperator + >>> from quafu.core.parameterresolver import ParameterResolver >>> f = FermionOperator('0^', ParameterResolver({'a': 2.0}, 3.0)) >>> f 2*a + 3 [0^] diff --git a/mindquantum/core/operators/hamiltonian.py b/quafu/core/operators/hamiltonian.py similarity index 94% rename from mindquantum/core/operators/hamiltonian.py rename to quafu/core/operators/hamiltonian.py index b56021630..f32df1669 100644 --- a/mindquantum/core/operators/hamiltonian.py +++ b/quafu/core/operators/hamiltonian.py @@ -20,8 +20,8 @@ import numpy as np import scipy.sparse as sp -import mindquantum as mq -from mindquantum import mqbackend as mb +import quafu +from quafu import quafubackend as mb class HowTo(Enum): @@ -38,10 +38,10 @@ class Hamiltonian: Args: hamiltonian (Union[QubitOperator, scipy.sparse]): The pauli qubit operator or a sparse matrix. - dtype (mindquantum.dtype): data type of hamiltonian. Default: ``None``. + dtype (quafu.dtype): data type of hamiltonian. Default: ``None``. Examples: - >>> from mindquantum.core.operators import QubitOperator, Hamiltonian + >>> from quafu.core.operators import QubitOperator, Hamiltonian >>> ham = Hamiltonian(QubitOperator('Z0 Y1', 0.3)) >>> ham 3/10 [Z0 Y1] @@ -58,10 +58,10 @@ def __init__(self, hamiltonian, dtype=None): raise TypeError(f"Require a QubitOperator or a csr_matrix, but get {type(hamiltonian)}!") if isinstance(hamiltonian, sp.csr_matrix): if dtype is None: - dtype = mq.to_mq_type(hamiltonian.dtype) + dtype = quafu.to_quafu_type(hamiltonian.dtype) else: - if dtype != mq.to_mq_type(hamiltonian.dtype): - hamiltonian = hamiltonian.astype(mq.to_np_type(dtype)) + if dtype != quafu.to_quafu_type(hamiltonian.dtype): + hamiltonian = hamiltonian.astype(quafu.to_np_type(dtype)) self.ham_dtype = dtype if len(hamiltonian.shape) != 2 or hamiltonian.shape[0] != hamiltonian.shape[1]: raise ValueError( @@ -190,7 +190,7 @@ def astype(self, dtype): Convert hamiltonian to other type. Args: - dtype (mindquantum.dtype): the new type of hamiltonian. + dtype (quafu.dtype): the new type of hamiltonian. """ if self.how_to == HowTo.FRONTEND: return Hamiltonian(self._sparse_matrix, dtype) @@ -203,7 +203,7 @@ def get_cpp_obj(self, hermitian=False): Args: hermitian (bool): Whether to get the cpp object of this hamiltonian in hermitian version. """ - if mq.is_double_precision(self.dtype): + if quafu.is_double_precision(self.dtype): backend_module = mb.double else: backend_module = mb.float diff --git a/mindquantum/core/operators/polynomial_tensor.py b/quafu/core/operators/polynomial_tensor.py similarity index 99% rename from mindquantum/core/operators/polynomial_tensor.py rename to quafu/core/operators/polynomial_tensor.py index 8c006f6c8..32bd1a4cd 100644 --- a/mindquantum/core/operators/polynomial_tensor.py +++ b/quafu/core/operators/polynomial_tensor.py @@ -66,7 +66,7 @@ class PolynomialTensor: Examples: >>> import numpy as np - >>> from mindquantum.core.operators import PolynomialTensor + >>> from quafu.core.operators import PolynomialTensor >>> constant = 1 >>> one_body_term = np.array([[1,0],[0,1]]) >>> two_body_term = two_body_term = np.array([[[[1,0],[0,1]],[[1,0],[0,1]]],[[[1,0],[0,1]],[[1,0],[0,1]]]]) diff --git a/mindquantum/core/operators/projector.py b/quafu/core/operators/projector.py similarity index 97% rename from mindquantum/core/operators/projector.py rename to quafu/core/operators/projector.py index c99349c92..ea41f8b1b 100644 --- a/mindquantum/core/operators/projector.py +++ b/quafu/core/operators/projector.py @@ -44,7 +44,7 @@ class Projector: proj (str): The string format of the projector. Examples: - >>> from mindquantum.core.operators import Projector + >>> from quafu.core.operators import Projector >>> p = Projector('II010') >>> p I2 ⊗ ¦010⟩⟨010¦ diff --git a/mindquantum/core/operators/qubit_excitation_operator.py b/quafu/core/operators/qubit_excitation_operator.py similarity index 96% rename from mindquantum/core/operators/qubit_excitation_operator.py rename to quafu/core/operators/qubit_excitation_operator.py index 616f08e8e..4e3bb6192 100644 --- a/mindquantum/core/operators/qubit_excitation_operator.py +++ b/quafu/core/operators/qubit_excitation_operator.py @@ -16,7 +16,7 @@ # pylint: disable=duplicate-code """This module implements qubit-excitation operators.""" -from mindquantum.core.parameterresolver import ParameterResolver +from quafu.core.parameterresolver import ParameterResolver from ._base_operator import _Operator from ._term_value import TermValue @@ -67,8 +67,8 @@ class QubitExcitationOperator(_Operator): coefficient for the corresponding single operators Default: ``1.0``. Examples: - >>> from mindquantum.algorithm.nisq import Transform - >>> from mindquantum.core.operators import QubitExcitationOperator + >>> from quafu.algorithm.nisq import Transform + >>> from quafu.core.operators import QubitExcitationOperator >>> op = QubitExcitationOperator(((4, 1), (1, 0), (0, 0)), 2.5) >>> op 5/2 [Q4^ Q1 Q0] @@ -129,7 +129,7 @@ def to_qubit_operator(self): according to the definition of Qubit excitation operators. Examples: - >>> from mindquantum.core.operators import QubitExcitationOperator + >>> from quafu.core.operators import QubitExcitationOperator >>> op = QubitExcitationOperator("7^ 1") >>> op.to_qubit_operator() 1/4 [X1 X7] + @@ -140,7 +140,7 @@ def to_qubit_operator(self): qubit_operator = QubitOperator() for term_i, coeff_i in self.terms.items(): qubit_operator_i = QubitOperator((), 1) - for (idx, excite) in term_i: + for idx, excite in term_i: qubit_op_ = None if excite == TermValue[0]: qubit_op_ = QubitOperator(((idx, TermValue["X"]),), 1) + QubitOperator(((idx, TermValue["Y"]),), 1j) @@ -263,7 +263,7 @@ def imag(self): QubitExcitationOperator, the image part of this qubit excitation operator. Examples: - >>> from mindquantum.core.operators import QubitExcitationOperator + >>> from quafu.core.operators import QubitExcitationOperator >>> f = QubitExcitationOperator(((1, 0),), 1 + 2j) >>> f += QubitExcitationOperator(((1, 1),), 'a') >>> f.imag.compress() @@ -284,7 +284,7 @@ def real(self): QubitExcitationOperator, the real part of this qubit excitation operator. Examples: - >>> from mindquantum.core.operators import QubitExcitationOperator + >>> from quafu.core.operators import QubitExcitationOperator >>> f = QubitExcitationOperator(((1, 0),), 1 + 2j) >>> f += QubitExcitationOperator(((1, 1),), 'a') >>> f.real.compress() @@ -309,7 +309,7 @@ def normal_ordered(self): QubitExcitationOperator, the normal ordered operator. Examples: - >>> from mindquantum.core.operators import QubitExcitationOperator + >>> from quafu.core.operators import QubitExcitationOperator >>> op = QubitExcitationOperator("7 1^") >>> op 1 [Q7 Q1^] diff --git a/mindquantum/core/operators/qubit_operator.py b/quafu/core/operators/qubit_operator.py similarity index 91% rename from mindquantum/core/operators/qubit_operator.py rename to quafu/core/operators/qubit_operator.py index 8adb3f27c..334e0933c 100644 --- a/mindquantum/core/operators/qubit_operator.py +++ b/quafu/core/operators/qubit_operator.py @@ -22,13 +22,13 @@ import numpy as np from scipy.sparse import csr_matrix -import mindquantum as mq -from mindquantum._math.ops import QubitOperator as QubitOperator_ -from mindquantum.core.operators._term_value import TermValue -from mindquantum.core.parameterresolver import ParameterResolver, PRConvertible -from mindquantum.dtype.dtype import str_dtype_map -from mindquantum.mqbackend import EQ_TOLERANCE -from mindquantum.utils.type_value_check import ( +import quafu +from quafu._math.ops import QubitOperator as QubitOperator_ +from quafu.core.operators._term_value import TermValue +from quafu.core.parameterresolver import ParameterResolver, PRConvertible +from quafu.dtype.dtype import str_dtype_map +from quafu.quafubackend import EQ_TOLERANCE +from quafu.utils.type_value_check import ( _check_and_generate_pr_type, _check_int_type, _require_package, @@ -62,7 +62,7 @@ class QubitOperator(QubitOperator_): QubitOperator or not. Default: ``False``. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ham = ((QubitOperator('X0 Y3', 0.5) ... + 0.6 * QubitOperator('X0 Y3'))) >>> ham2 = QubitOperator('X0 Y3', 0.5) @@ -238,7 +238,7 @@ def imag(self): QubitOperator, the imag part of this qubit operator. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> f = QubitOperator('X0', 1 + 2j) + QubitOperator('Y0', 'a') >>> f.imag.compress() 2 [X0] @@ -248,7 +248,7 @@ def imag(self): @property def is_complex(self) -> bool: """Return whether the QubitOperator instance is currently using complex coefficients.""" - return self.dtype in (mq.complex128, mq.complex64) + return self.dtype in (quafu.complex128, quafu.complex64) @property def is_singlet(self) -> bool: @@ -274,7 +274,7 @@ def real(self): QubitOperator, the real part of this qubit operator. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> f = QubitOperator('X0', 1 + 2j) + QubitOperator('Y0', 'a') >>> f.real.compress() 1 [X0] + @@ -302,13 +302,13 @@ def terms(self) -> typing.Dict[typing.Tuple[int, str], ParameterResolver]: @staticmethod def from_openfermion(of_ops) -> "QubitOperator": """ - Convert qubit operator from openfermion to mindquantum format. + Convert qubit operator from openfermion to quafu format. Args: of_ops (openfermion.QubitOperator): Qubit operator from openfermion. Returns: - QubitOperator, qubit operator from mindquantum. + QubitOperator, qubit operator from quafu. """ # pylint: disable=import-outside-toplevel try: @@ -336,7 +336,7 @@ def loads(strs: str) -> "QubitOperator": QubitOperator, the QubitOperator loaded from JSON-formatted strings. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> f = QubitOperator('0', 1 + 2j) + QubitOperator('0^', 'a') >>> obj = QubitOperator.loads(f.dumps()) >>> obj == f @@ -356,18 +356,18 @@ def astype(self, dtype) -> "QubitOperator": Converting a complex type QubitOperator to real type will ignore the image part of coefficient. Args: - dtype (mindquantum.dtype): new data type of fermion operator. + dtype (quafu.dtype): new data type of fermion operator. Returns: QubitOperator, new fermion operator with given data type. Examples: - >>> from mindquantum.core.operators import QubitOperator - >>> import mindquantum as mq + >>> from quafu.core.operators import QubitOperator + >>> import quafu >>> f = QubitOperator('X0', 2 + 3j) >>> f.dtype - mindquantum.complex128 - >>> f.astype(mq.float64) + quafu.complex128 + >>> f.astype(quafu.float64) 2 [X0] """ return QubitOperator(QubitOperator_.astype(self, dtype)) @@ -375,10 +375,10 @@ def astype(self, dtype) -> "QubitOperator": def cast_complex(self) -> "QubitOperator": """Cast a QubitOperator into its complex equivalent.""" new_type = self.dtype - if new_type == mq.float32: - new_type = mq.complex64 - elif new_type == mq.float64: - new_type = mq.complex128 + if new_type == quafu.float32: + new_type = quafu.complex64 + elif new_type == quafu.float64: + new_type = quafu.complex128 return self.astype(new_type) def compress(self, abs_tol=EQ_TOLERANCE) -> "QubitOperator": @@ -392,7 +392,7 @@ def compress(self, abs_tol=EQ_TOLERANCE) -> "QubitOperator": QubitOperator, the compressed operator. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ham_compress = QubitOperator('X0 Y1', 0.5) + QubitOperator('Z1 X3', 1e-7) >>> ham_compress 1/2 [Y1 X0] + @@ -421,7 +421,7 @@ def count_gates(self): int, number of the single qubit quantum gates. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> a = QubitOperator("X0 Y1") + QubitOperator("X2 Z3") >>> a.count_gates() 4 @@ -436,7 +436,7 @@ def count_qubits(self) -> int: int, the qubits number before remove unused qubit. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> a = QubitOperator("Z0 Y3") >>> a.count_qubits() 4 @@ -455,7 +455,7 @@ def dumps(self, indent: int = 4) -> str: JSON (str), the JSON strings of this QubitOperator Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> f = QubitOperator('0', 1 + 2j) + QubitOperator('0^', 'a') >>> len(f.dumps()) 581 @@ -477,7 +477,7 @@ def get_coeff(self, term) -> ParameterResolver: term (List[Tuple[int, Union[int, str]]]): the term you want get coefficient. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> q = QubitOperator('X0 Y1', 1.2) >>> q.get_coeff([(1, 'Y'), (0, 'X')]) ParameterResolver(dtype: float64, const: 1.200000) @@ -492,7 +492,7 @@ def hermitian(self) -> "QubitOperator": QubitOperator, the hermitian of this QubitOperator. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> a = QubitOperator("X0 Y1", {"a": 1 + 2j}) >>> a.hermitian() (-1 + 2j)*a [1 0^] @@ -542,7 +542,7 @@ def relabel(self, logic_qubits: typing.List[int]) -> "QubitOperator": logic_qubits is `[2, 0, 1]`, original qubit `0` will label as `2`. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> o = QubitOperator('Z0 Y1 X2 Z3') >>> o 1 [Z0 Y1 X2 Z3] @@ -563,7 +563,7 @@ def singlet(self) -> typing.List["QubitOperator"]: RuntimeError: if the size of terms is not equal to 1. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ops = QubitOperator("1^ 2", 1) >>> print(ops.singlet()) [1 [2], 1 [1^]] @@ -581,7 +581,7 @@ def singlet_coeff(self) -> ParameterResolver: RuntimeError: if the size of terms is not equal to 1. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> ops = QubitOperator("X0 Y1", "a") >>> print(ops) -a [2 1^] @@ -598,7 +598,7 @@ def split(self): List[List[ParameterResolver, QubitOperator]], the split result. Examples: - >>> from mindquantum.core.operators import QubitOperator + >>> from quafu.core.operators import QubitOperator >>> a = QubitOperator('X0', 'a') + QubitOperator('Z1', 1.2) >>> for i, j in a.split(): ... print(f"{i}, {j}") @@ -616,8 +616,8 @@ def subs(self, params_value: PRConvertible) -> "QubitOperator": params_value (Union[Dict[str, numbers.Number], ParameterResolver]): the value of variable in coefficient. Examples: - >>> from mindquantum.core.operators import QubitOperator - >>> from mindquantum.core.parameterresolver import ParameterResolver + >>> from quafu.core.operators import QubitOperator + >>> from quafu.core.parameterresolver import ParameterResolver >>> q = QubitOperator('X0', ParameterResolver({'a': 2.0}, 3.0)) >>> q 2*a + 3 [X0] diff --git a/mindquantum/core/operators/time_evolution.py b/quafu/core/operators/time_evolution.py similarity index 97% rename from mindquantum/core/operators/time_evolution.py rename to quafu/core/operators/time_evolution.py index 17064f829..d50346e2f 100644 --- a/mindquantum/core/operators/time_evolution.py +++ b/quafu/core/operators/time_evolution.py @@ -42,7 +42,7 @@ class TimeEvolution: # pylint: disable=too-few-public-methods Default: ``None``. Examples: - >>> from mindquantum.core.operators import TimeEvolution, QubitOperator + >>> from quafu.core.operators import TimeEvolution, QubitOperator >>> q1 = QubitOperator('Z0 Y1', 'a') >>> q2 = QubitOperator('X0 Z1', 'b') >>> ops1 = q1 + q2 @@ -66,7 +66,7 @@ class TimeEvolution: # pylint: disable=too-few-public-methods def __init__(self, ops: QubitOperator, time=None): """Initialize a TimeEvolution object.""" # pylint: disable=import-outside-toplevel - from mindquantum.utils.type_value_check import _num_type + from quafu.utils.type_value_check import _num_type if time is None: time = 1 diff --git a/mindquantum/core/operators/utils.py b/quafu/core/operators/utils.py similarity index 91% rename from mindquantum/core/operators/utils.py rename to quafu/core/operators/utils.py index 82d689588..473bbdd9a 100644 --- a/mindquantum/core/operators/utils.py +++ b/quafu/core/operators/utils.py @@ -39,7 +39,7 @@ def count_qubits(operator): TypeError: Operator of invalid type. Examples: - >>> from mindquantum.core.operators import QubitOperator,FermionOperator, count_qubits + >>> from quafu.core.operators import QubitOperator,FermionOperator, count_qubits >>> qubit_op = QubitOperator("X1 Y2") >>> count_qubits(qubit_op) 3 @@ -87,7 +87,7 @@ def commutator(left_operator, right_operator): TypeError: `left_operator` and `right_operator` are not of the same type. Examples: - >>> from mindquantum.core.operators import QubitOperator, FermionOperator, commutator + >>> from quafu.core.operators import QubitOperator, FermionOperator, commutator >>> qub_op1 = QubitOperator("X1 Y2") >>> qub_op2 = QubitOperator("X1 Z2") >>> commutator(qub_op1, qub_op1) @@ -121,7 +121,7 @@ def normal_ordered(fermion_operator): FermionOperator, the FermionOperator with normal order. Examples: - >>> from mindquantum.core.operators import FermionOperator, normal_ordered + >>> from quafu.core.operators import FermionOperator, normal_ordered >>> op = FermionOperator("3 4^", 'a') >>> normal_ordered(op) -a [4^ 3] @@ -145,7 +145,7 @@ def number_operator(n_modes=None, mode=None, coefficient=1.0): FermionOperator, a fermionic number operator for the reverse_jordan_wigner transform. Examples: - >>> from mindquantum.core.operators import FermionOperator, number_operator + >>> from quafu.core.operators import FermionOperator, number_operator >>> n_mode = 3 >>> number_operator(n_mode) 1 [0^ 0] + @@ -195,7 +195,7 @@ def hermitian_conjugated(operator): the hermitian form of the input operator. Examples: - >>> from mindquantum.core.operators import QubitOperator, hermitian_conjugated + >>> from quafu.core.operators import QubitOperator, hermitian_conjugated >>> q = QubitOperator('X0', {'a' : 2j}) >>> hermitian_conjugated(q) (-2j)*a [X0] @@ -222,7 +222,7 @@ def up_index(index): int, the index of the associated spin-up orbital. Examples: - >>> from mindquantum.core.operators import up_index + >>> from quafu.core.operators import up_index >>> up_index(1) 2 """ @@ -243,7 +243,7 @@ def down_index(index): int, the index of the associated spin-down orbital. Examples: - >>> from mindquantum.core.operators import down_index + >>> from quafu.core.operators import down_index >>> down_index(1) 3 """ @@ -266,7 +266,7 @@ def sz_operator(n_spatial_orbitals): `n_spatial_orbitals`. Examples: - >>> from mindquantum.core.operators import sz_operator + >>> from quafu.core.operators import sz_operator >>> sz_operator(3) 1/2 [0^ 0] + -1/2 [1^ 1] + @@ -287,20 +287,20 @@ def sz_operator(n_spatial_orbitals): return sz_up - sz_down -def ground_state_of_sum_zz(ops: QubitOperator, sim='mqvector') -> float: +def ground_state_of_sum_zz(ops: QubitOperator, sim='quafuvector') -> float: """ Find the ground state energy of qubit operator that only has pauli :math:`Z` term. Args: ops (QubitOperator): qubit operator that only has pauli :math:`Z` term. sim (str): use which simulator to do calculation. Currently, we support - ``'mqvector'`` and ``'mqvector_gpu'``. Default: ``'mqvector'``. + ``'quafuvector'`` and ``'quafuvector_gpu'``. Default: ``'quafuvector'``. Returns: float, the ground state energy of given qubit operator. Examples: - >>> from mindquantum.core.operators import ground_state_of_sum_zz, QubitOperator + >>> from quafu.core.operators import ground_state_of_sum_zz, QubitOperator >>> h = QubitOperator('Z0 Z1', 1.0) + QubitOperator('Z0 Z2', -1.5) >>> ground_state_of_sum_zz(h) -2.5 @@ -309,8 +309,8 @@ def ground_state_of_sum_zz(ops: QubitOperator, sim='mqvector') -> float: (-2.5+0j) """ # pylint: disable=import-outside-toplevel - if sim.startswith('mqmatrix'): - raise ValueError("mqmatrix simulator not support this method yet.") + if sim.startswith('quafumatrix'): + raise ValueError("quafumatrix simulator not support this method yet.") c_module = SUPPORTED_SIMULATOR.c_module(sim) ground_state_of_zs = getattr(c_module, "ground_state_of_zs") masks_value = {} diff --git a/mindquantum/core/parameterresolver/__init__.py b/quafu/core/parameterresolver/__init__.py similarity index 100% rename from mindquantum/core/parameterresolver/__init__.py rename to quafu/core/parameterresolver/__init__.py diff --git a/mindquantum/core/parameterresolver/parameterresolver.py b/quafu/core/parameterresolver/parameterresolver.py similarity index 86% rename from mindquantum/core/parameterresolver/parameterresolver.py rename to quafu/core/parameterresolver/parameterresolver.py index 53c20c2b6..82ef2230c 100644 --- a/mindquantum/core/parameterresolver/parameterresolver.py +++ b/quafu/core/parameterresolver/parameterresolver.py @@ -21,15 +21,15 @@ import numpy as np -import mindquantum as mq -from mindquantum._math.pr import ParameterResolver as ParameterResolver_ -from mindquantum._math.tensor import from_numpy -from mindquantum.dtype.dtype import mq_complex_number_type, str_dtype_map -from mindquantum.utils.string_utils import join_without_empty, string_expression -from mindquantum.utils.type_value_check import ( +import quafu +from quafu._math.pr import ParameterResolver as ParameterResolver_ +from quafu._math.tensor import from_numpy +from quafu.dtype.dtype import quafu_complex_number_type, str_dtype_map +from quafu.utils.string_utils import join_without_empty, string_expression +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, - _check_mq_type, + _check_quafu_type, ) PRConvertible = typing.Union[numbers.Number, str, typing.Dict[str, numbers.Number], "ParameterResolver"] @@ -48,11 +48,11 @@ class ParameterResolver(ParameterResolver_): be 1. Default: ``None``. const (number.Number): the constant part of this parameter resolver. Default: ``None``. - dtype (mindquantum.dtype): the data type of this parameter resolver. Default: ``None``. + dtype (quafu.dtype): the data type of this parameter resolver. Default: ``None``. internal (bool): whether the first argument is the c++ object of parameter resolver. Default: ``False``. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver + >>> from quafu.core.parameterresolver import ParameterResolver >>> pr = ParameterResolver({'a': 0.3}) >>> pr['b'] = 0.5 >>> pr.no_grad_part('a') @@ -95,7 +95,7 @@ class ParameterResolver(ParameterResolver_): def __init__(self, data=None, const=None, dtype=None, internal=False): """Initialize a ParameterResolver object.""" if dtype is not None: - _check_mq_type(dtype) + _check_quafu_type(dtype) if isinstance(data, ParameterResolver): internal = True if internal: @@ -106,44 +106,44 @@ def __init__(self, data=None, const=None, dtype=None, internal=False): else: if isinstance(data, str): if dtype is None: - dtype = mq.float64 + dtype = quafu.float64 if const is not None: if isinstance(const, numbers.Number) and not isinstance(const, numbers.Real): - dtype = mq.complex128 + dtype = quafu.complex128 if const is None: - const = from_numpy(np.array([0.0], dtype=mq.to_np_type(dtype))) + const = from_numpy(np.array([0.0], dtype=quafu.to_np_type(dtype))) else: - const = from_numpy(np.array([const], dtype=mq.to_np_type(dtype))) - ParameterResolver_.__init__(self, data, const, dtype) # PR('a'[, 1.0, mq.float64]) + const = from_numpy(np.array([const], dtype=quafu.to_np_type(dtype))) + ParameterResolver_.__init__(self, data, const, dtype) # PR('a'[, 1.0, quafu.float64]) elif isinstance(data, dict): if dtype is None: - dtype = mq.float64 + dtype = quafu.float64 for v in data.values(): if isinstance(v, numbers.Number) and not isinstance(v, numbers.Real): - dtype = mq.complex128 + dtype = quafu.complex128 break if const is not None: if isinstance(const, numbers.Number) and not isinstance(const, numbers.Real): - dtype = mq.complex128 + dtype = quafu.complex128 if const is None: - const = from_numpy(np.array([0.0], dtype=mq.to_np_type(dtype))) + const = from_numpy(np.array([0.0], dtype=quafu.to_np_type(dtype))) else: - const = from_numpy(np.array([const], dtype=mq.to_np_type(dtype))) - # PR({'a': 1.0}[, 2.0, mq.float64]) + const = from_numpy(np.array([const], dtype=quafu.to_np_type(dtype))) + # PR({'a': 1.0}[, 2.0, quafu.float64]) ParameterResolver_.__init__( self, - {i: from_numpy(np.array([j], dtype=mq.to_np_type(dtype))) for i, j in data.items()}, + {i: from_numpy(np.array([j], dtype=quafu.to_np_type(dtype))) for i, j in data.items()}, const, dtype, ) elif isinstance(data, numbers.Number): if dtype is None: - dtype = mq.float64 + dtype = quafu.float64 if isinstance(data, numbers.Number) and not isinstance(data, numbers.Real): - dtype = mq.complex128 + dtype = quafu.complex128 ParameterResolver_.__init__( - self, from_numpy(np.array([data], dtype=mq.to_np_type(dtype))) - ) # PR(1.0[, mq.float64]) + self, from_numpy(np.array([data], dtype=quafu.to_np_type(dtype))) + ) # PR(1.0[, quafu.float64]) elif data is None: ParameterResolver_.__init__(self) else: @@ -169,7 +169,7 @@ def __len__(self) -> int: int, the number of all parameters. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 0, 'b': 1}) >>> a.expression() 'b' @@ -183,7 +183,7 @@ def __contains__(self, key: str) -> bool: Check whether the given key is in this parameter resolver or not. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1, 'b': 2}) >>> 'c' in pr False @@ -199,7 +199,7 @@ def __copy__(self) -> "ParameterResolver": Examples: >>> import copy - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 2}, 3) >>> b = copy.copy(a) >>> c = a @@ -230,7 +230,7 @@ def __eq__(self, other: PRConvertible) -> bool: bool, whether two parameter resolvers are equal. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> PR(3) == 3 True >>> PR({'a': 2}, 3) == PR({'a': 2}) + 3 @@ -246,7 +246,7 @@ def __bool__(self) -> bool: bool, False if this parameter resolver represent zero and True if not. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR(0) >>> bool(pr) False @@ -260,7 +260,7 @@ def __setitem__(self, key: str, value: numbers.Number): You can set multiple values of multiple parameters with given iterable keys and values. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR(0) >>> pr['a'] = 2.5 >>> pr.expression() @@ -276,7 +276,7 @@ def __getitem__(self, key: str) -> numbers.Number: numbers.Number, the parameter value. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1, 'b': 2}) >>> pr['a'] 1.0 @@ -288,7 +288,7 @@ def __iter__(self) -> typing.Generator[str, None, None]: Yield the parameter name. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1, 'b': 2}) >>> list(pr) ['a', 'b'] @@ -309,7 +309,7 @@ def __iadd__(self, other: PRConvertible) -> "ParameterResolver": resolver you want add. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 3}) >>> pr += 4 >>> pr.expression() @@ -341,7 +341,7 @@ def __add__(self, other: PRConvertible) -> "ParameterResolver": ParameterResolver, the result of add. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 3}) >>> (pr + 1).expression() '3*a + 1' @@ -440,7 +440,7 @@ def ansatz_parameters(self) -> typing.List[str]: set, the set of ansatz parameters. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 1, 'b': 2}) >>> a.ansatz_parameters ['a', 'b'] @@ -456,7 +456,7 @@ def const(self) -> numbers.Number: numbers.Number, the constant part of this parameter resolver. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1}, 2.5) >>> pr.const 2.5 @@ -477,7 +477,7 @@ def encoder_parameters(self) -> typing.List[str]: set, the set of encoder parameters. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 1, 'b': 2}) >>> a.as_encoder() >>> a.encoder_parameters @@ -494,7 +494,7 @@ def imag(self) -> "ParameterResolver": ParameterResolver, image part parameter value. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR('a', 3) + 1j * PR('a', 4) >>> pr ParameterResolver(dtype: complex128, @@ -516,7 +516,7 @@ def imag(self) -> "ParameterResolver": @property def is_complex(self) -> bool: """Return whether the ParameterResolver instance is currently using complex coefficients.""" - return self.dtype in mq_complex_number_type + return self.dtype in quafu_complex_number_type @property def no_grad_parameters(self) -> typing.List[str]: @@ -527,7 +527,7 @@ def no_grad_parameters(self) -> typing.List[str]: set, the set of parameters that do not require grad. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 1, 'b': 2}) >>> a.no_grad() >>> a.no_grad_parameters @@ -544,7 +544,7 @@ def params_name(self) -> typing.List[str]: list, a list of parameters name. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.params_name ['a', 'b'] @@ -560,7 +560,7 @@ def params_value(self) -> typing.List[numbers.Number]: list, a list of parameters value. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.params_value [1.0, 2.0] @@ -576,7 +576,7 @@ def real(self) -> "ParameterResolver": ParameterResolver, real part parameter value. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR('a', 3) + 1j * PR('a', 4) >>> pr ParameterResolver(dtype: complex128, @@ -604,7 +604,7 @@ def requires_grad_parameters(self) -> typing.List[str]: set, the set of parameters that requires grad. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 1, 'b': 2}) >>> a.requires_grad_parameters ['a', 'b'] @@ -623,7 +623,7 @@ def loads(strs: str) -> "ParameterResolver": FermionOperator, the FermionOperator load from strings Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver + >>> from quafu.core.parameterresolver import ParameterResolver >>> ori = ParameterResolver({'a': 1, 'b': 2, 'c': 3, 'd': 4}) >>> ori.no_grad_part('a', 'b') >>> string = ori.dumps() @@ -640,7 +640,7 @@ def loads(strs: str) -> "ParameterResolver": if 'dtype' not in dic: raise ValueError("Invalid string. Cannot convert it to ParameterResolver, no key dtype") dtype = str_dtype_map[dic['dtype']] - if dtype in mq_complex_number_type: + if dtype in quafu_complex_number_type: const = dic['const'][0] + 1j * dic['const'][1] data = {i: j[0] + j[1] * 1j for i, j in dic['pr_data'].items()} else: @@ -662,7 +662,7 @@ def ansatz_part(self, *names): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.as_encoder() >>> pr.ansatz_part('a') @@ -682,7 +682,7 @@ def as_encoder(self): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1, 'b': 2}) >>> pr.as_encoder() >>> pr.encoder_parameters @@ -699,7 +699,7 @@ def as_ansatz(self): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1, 'b': 2}) >>> pr.as_encoder() >>> pr.as_ansatz() @@ -714,10 +714,10 @@ def astype(self, dtype) -> "ParameterResolver": Convert ParameterResolver to different dtype. Args: - dtype (mindquantum.dtype): new data type of parameter resolver you want. + dtype (quafu.dtype): new data type of parameter resolver you want. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver + >>> from quafu.core.parameterresolver import ParameterResolver >>> a = ParameterResolver('a') >>> a ParameterResolver(dtype: float64, @@ -726,8 +726,8 @@ def astype(self, dtype) -> "ParameterResolver": ], const: 0.000000 ) - >>> import mindquantum as mq - >>> a.astype(mq.complex128) + >>> import quafu + >>> a.astype(quafu.complex128) ParameterResolver(dtype: complex128, data: [ a: (1.000000, 0.000000) @@ -735,7 +735,7 @@ def astype(self, dtype) -> "ParameterResolver": const: (0.000000, 0.000000) ) """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return ParameterResolver(ParameterResolver_.astype(self, dtype), internal=True) def combination(self, other: typing.Union[typing.Dict[str, numbers.Number], "ParameterResolver"]): @@ -750,7 +750,7 @@ def combination(self, other: typing.Union[typing.Dict[str, numbers.Number], "Par numbers.Number, the combination result. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr1 = ParameterResolver({'a': 1, 'b': 2}) >>> pr2 = ParameterResolver({'a': 2, 'b': 3}) >>> pr1.combination(pr2) @@ -778,9 +778,9 @@ def conjugate(self) -> "ParameterResolver": ParameterResolver, the conjugate version of this parameter resolver. Examples: - >>> import mindquantum as mq - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR - >>> pr = PR({'a' : 1, 'b': 1j}, dtype=mq.complex128) + >>> import quafu + >>> from quafu.core.parameterresolver import ParameterResolver as PR + >>> pr = PR({'a' : 1, 'b': 1j}, dtype=quafu.complex128) >>> pr.conjugate().expression() 'a + (-1j)*b' """ @@ -792,7 +792,7 @@ def dumps(self, indent=4) -> str: Note: Since float32 type value is not serializable, so ParameterResolver with - mindquantum.float32 and mindquantum.complex64 type is not serializable. + quafu.float32 and quafu.complex64 type is not serializable. Args: indent (int): Then JSON array elements and object members will be @@ -802,7 +802,7 @@ def dumps(self, indent=4) -> str: string(JSON), the JSON of ParameterResolver Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver + >>> from quafu.core.parameterresolver import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}, const=3 + 4j) >>> pr.no_grad_part('a', 'b') >>> print(pr.dumps()) @@ -821,7 +821,7 @@ def dumps(self, indent=4) -> str: 3.0, 4.0 ], - "dtype": "mindquantum.complex128", + "dtype": "quafu.complex128", "no_grad_parameters": [ "b", "a" @@ -833,8 +833,8 @@ def dumps(self, indent=4) -> str: _check_int_type('indent', indent) dic = {} dic['dtype'] = str(self.dtype) - if mq.is_single_precision(self.dtype): - double_version = self.astype(mq.to_double_precision(self.dtype)) + if quafu.is_single_precision(self.dtype): + double_version = self.astype(quafu.to_double_precision(self.dtype)) else: double_version = self dic['pr_data'] = {i: (j.real, j.imag) for i, j in double_version.items()} @@ -854,7 +854,7 @@ def encoder_part(self, *names): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.encoder_part('a') ParameterResolver(dtype: float64, @@ -881,7 +881,7 @@ def expression(self) -> str: str, the string expression of this parameter resolver. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> import numpy as np >>> pr = PR({'a': np.pi}, np.sqrt(2)) >>> pr.expression() @@ -915,7 +915,7 @@ def items(self) -> typing.Generator[str, numbers.Number, None]: Return an iterator that yields the name and value of all parameters. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 0, 'b': 1}) >>> list(a.items()) [('a', 0.0), ('b', 1.0)] @@ -931,7 +931,7 @@ def is_anti_hermitian(self) -> bool: bool, whether the parameter resolver is anti hermitian or not. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1}) >>> pr.is_anti_hermitian() False @@ -952,7 +952,7 @@ def is_const(self) -> bool: bool, whether this parameter resolver represent a constant number. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR(1.0) >>> pr.is_const() True @@ -967,7 +967,7 @@ def is_hermitian(self) -> bool: bool, whether the parameter resolver is hermitian or not. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> pr = PR({'a': 1}) >>> pr.is_hermitian() True @@ -983,7 +983,7 @@ def keys(self) -> typing.Generator[str, None, None]: Return an iterator that yields the name and value of all parameters. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 0, 'b': 1}) >>> list(a.keys()) ['a', 'b'] @@ -998,7 +998,7 @@ def no_grad(self): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.no_grad() ParameterResolver(dtype: float64, @@ -1026,7 +1026,7 @@ def no_grad_part(self, *names): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.no_grad_part('a') ParameterResolver(dtype: float64, @@ -1056,7 +1056,7 @@ def pop(self, v: str) -> numbers.Number: numbers.Number, the popped out parameter value. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 1, 'b': 2}) >>> a.pop('a') 1.0 @@ -1073,7 +1073,7 @@ def requires_grad(self): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.no_grad_part('a') ParameterResolver(dtype: float64, @@ -1109,7 +1109,7 @@ def requires_grad_part(self, *names): ParameterResolver, the parameter resolver itself. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr = ParameterResolver({'a': 1, 'b': 2}) >>> pr.no_grad() ParameterResolver(dtype: float64, @@ -1145,7 +1145,7 @@ def subs(self, other: typing.Union["ParameterResolver", typing.Dict[str, numbers other (Union[ParameterResolver, Dict[str, numbers.Number]]): the value of variables in parameter resolver. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 1.2, 'b': 2}, 3.4) >>> a.expression() '1.2*a + 2*b + 3.4' @@ -1159,7 +1159,7 @@ def subs(self, other: typing.Union["ParameterResolver", typing.Dict[str, numbers def to_real_obj(self) -> "ParameterResolver": """Convert to real type.""" - return self.astype(mq.to_real_type(self.dtype)) + return self.astype(quafu.to_real_type(self.dtype)) def update(self, other: "ParameterResolver"): """ @@ -1173,7 +1173,7 @@ def update(self, other: "ParameterResolver"): and some parameters are encoder parameters and not encoder in other parameter resolver and vice versa. Examples: - >>> from mindquantum import ParameterResolver + >>> from quafu import ParameterResolver >>> pr1 = ParameterResolver({'a': 1}) >>> pr2 = ParameterResolver({'b': 2}) >>> pr2.no_grad() @@ -1205,7 +1205,7 @@ def values(self) -> typing.Generator[numbers.Number, None, None]: Return an iterator that yields the name and value of all parameters. Examples: - >>> from mindquantum.core.parameterresolver import ParameterResolver as PR + >>> from quafu.core.parameterresolver import ParameterResolver as PR >>> a = PR({'a': 0, 'b': 1}) >>> list(a.values()) [0.0, 1.0] diff --git a/mindquantum/core/parameterresolver/pr_generator.py b/quafu/core/parameterresolver/pr_generator.py similarity index 88% rename from mindquantum/core/parameterresolver/pr_generator.py rename to quafu/core/parameterresolver/pr_generator.py index 67924dacb..659d79dcd 100644 --- a/mindquantum/core/parameterresolver/pr_generator.py +++ b/quafu/core/parameterresolver/pr_generator.py @@ -14,7 +14,7 @@ # ============================================================================ """Parameter Generator.""" -import mindquantum as mq +import quafu from .parameterresolver import ParameterResolver @@ -27,11 +27,11 @@ class PRGenerator: name (str): The main name of parameters. Default: ``'p'``. prefix (str): The prefix of parameters. Default: ``''``. suffix (str): The suffix of parameters. Default: ``''``. - dtype (mindquantum.dtype): the data type of this parameter resolver. If ``None``, - dtype would be ``mindquantum.float64``. Default: ``None``. + dtype (quafu.dtype): the data type of this parameter resolver. If ``None``, + dtype would be ``quafu.float64``. Default: ``None``. Examples: - >>> from mindquantum.core.parameterresolver import PRGenerator + >>> from quafu.core.parameterresolver import PRGenerator >>> pr_gen = PRGenerator() >>> print(pr_gen.new()) p0 @@ -47,7 +47,7 @@ class PRGenerator: def __init__(self, name='p', prefix: str = '', suffix: str = '', dtype=None): """Initialize a pr generator.""" if dtype is None: - self.dtype = mq.float64 + self.dtype = quafu.float64 else: self.dtype = dtype self.name = name @@ -74,7 +74,7 @@ def new(self, prefix: str = '', suffix: str = '') -> ParameterResolver: suffix (str): The extra suffix when generate this new parameter. Default: ``''``. Examples: - >>> from mindquantum.core.parameterresolver import PRGenerator + >>> from quafu.core.parameterresolver import PRGenerator >>> pr_gen = PRGenerator(prefix='l') >>> print(pr_gen.new(suffix='a')) l_p1_a diff --git a/mindquantum/core/third_party/__init__.py b/quafu/core/third_party/__init__.py similarity index 92% rename from mindquantum/core/third_party/__init__.py rename to quafu/core/third_party/__init__.py index a795472cf..81422537c 100644 --- a/mindquantum/core/third_party/__init__.py +++ b/quafu/core/third_party/__init__.py @@ -11,7 +11,7 @@ # 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. -"""Third-party modules for MindQuantum eDSL.""" +"""Third-party modules for quafu eDSL.""" import importlib import pkgutil @@ -21,7 +21,7 @@ # Automatically import all submodules and bring their exported symbols (__all__) into our namespace __all__ = [] -for (_, pkg_name, _) in pkgutil.iter_modules(path=__path__): +for _, pkg_name, _ in pkgutil.iter_modules(path=__path__): imported_module = importlib.import_module('.' + pkg_name, package=__name__) if hasattr(imported_module, '__all__'): diff --git a/mindquantum/device/__init__.py b/quafu/device/__init__.py similarity index 100% rename from mindquantum/device/__init__.py rename to quafu/device/__init__.py diff --git a/mindquantum/device/chip.py b/quafu/device/chip.py similarity index 100% rename from mindquantum/device/chip.py rename to quafu/device/chip.py diff --git a/mindquantum/device/topology.py b/quafu/device/topology.py similarity index 90% rename from mindquantum/device/topology.py rename to quafu/device/topology.py index 00b68bce7..7d1ed880a 100644 --- a/mindquantum/device/topology.py +++ b/quafu/device/topology.py @@ -28,10 +28,10 @@ from rich.console import Console -from mindquantum.utils.type_value_check import _check_input_type, _check_int_type +from quafu.utils.type_value_check import _check_input_type, _check_int_type -from ..mqbackend.device import QubitNode as QubitNode_ -from ..mqbackend.device import QubitsTopology as QubitsTopology_ +from ..quafubackend.device import QubitNode as QubitNode_ +from ..quafubackend.device import QubitsTopology as QubitsTopology_ AVA_SHOW_METHOD = Literal['mpl', 'svg'] # pylint: disable=invalid-name @@ -50,7 +50,7 @@ class QubitNode: poi_y (float): y position in canvas. Examples: - >>> from mindquantum.device import QubitNode + >>> from quafu.device import QubitNode >>> q0 = QubitNode(0) >>> q1 = QubitNode(1) >>> q = q0 << q1 @@ -85,8 +85,8 @@ def __gt__(self, other: "QubitNode") -> "QubitNode": :class:`~.device.QubitNode`, the right hand size qubit. Examples: - >>> from mindquantum.device import QubitNode - >>> from mindquantum.device import QubitsTopology + >>> from quafu.device import QubitNode + >>> from quafu.device import QubitsTopology >>> q0 = QubitNode(0) >>> q1 = QubitNode(1) >>> topology = QubitsTopology([q0, q1]) @@ -114,7 +114,7 @@ def __int__(self) -> int: int, the id of qubit. Examples: - >>> from mindquantum.device import QubitNode + >>> from quafu.device import QubitNode >>> q0 = QubitNode(0) >>> int(q0) 0 @@ -132,8 +132,8 @@ def __lshift__(self, other: "QubitNode") -> "QubitNode": :class:`~.device.QubitNode`, the left hand size qubit. Examples: - >>> from mindquantum.device import QubitNode - >>> from mindquantum.device import QubitsTopology + >>> from quafu.device import QubitNode + >>> from quafu.device import QubitsTopology >>> q0 = QubitNode(0) >>> q1 = QubitNode(1) >>> topology = QubitsTopology([q0, q1]) @@ -162,8 +162,8 @@ def __lt__(self, other: "QubitNode") -> "QubitNode": :class:`~.device.QubitNode`, the left hand size qubit. Examples: - >>> from mindquantum.device import QubitNode - >>> from mindquantum.device import QubitsTopology + >>> from quafu.device import QubitNode + >>> from quafu.device import QubitsTopology >>> q0 = QubitNode(0) >>> q1 = QubitNode(1) >>> topology = QubitsTopology([q0, q1]) @@ -197,8 +197,8 @@ def __rshift__(self, other: "QubitNode") -> "QubitNode": :class:`~.device.QubitNode`, the right hand side qubit. Examples: - >>> from mindquantum.device import QubitNode - >>> from mindquantum.device import QubitsTopology + >>> from quafu.device import QubitNode + >>> from quafu.device import QubitsTopology >>> q0 = QubitNode(0) >>> q1 = QubitNode(1) >>> topology = QubitsTopology([q0, q1]) @@ -224,7 +224,7 @@ def set_color(self, color: str) -> None: color (str): The new color. Examples: - >>> from mindquantum.device import QubitNode + >>> from quafu.device import QubitNode >>> q0 = QubitNode(1) >>> q0.set_color('#ababab') >>> q0.color @@ -242,7 +242,7 @@ def set_poi(self, poi_x: float, poi_y: float) -> None: poi_y (float): y position of qubit in canvas. Examples: - >>> from mindquantum.device import QubitNode + >>> from quafu.device import QubitNode >>> q0 = QubitNode(1, poi_x=0, poi_y=1) >>> q0.set_poi(1, 0) >>> print(q0.poi_x, q0.poi_y) @@ -304,8 +304,8 @@ class QubitsTopology: qubits (List[:class:`~.device.QubitNode`]): All qubit nodes in this topology. Examples: - >>> from mindquantum.device import QubitsTopology - >>> from mindquantum.device import QubitNode + >>> from quafu.device import QubitsTopology + >>> from quafu.device import QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology[0] >> topology[1] >>> topology.is_coupled_with(0, 1) @@ -338,8 +338,8 @@ def __getitem__(self, qubit_id: int) -> QubitNode: :class:`~.device.QubitNode`, the qubit node with given id. Examples: - >>> from mindquantum.device import QubitsTopology - >>> from mindquantum.device import QubitNode + >>> from quafu.device import QubitsTopology + >>> from quafu.device import QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology[2].qubit_id 2 @@ -359,7 +359,7 @@ def add_qubit_node(self, qubit: QubitNode) -> None: qubit (:class:`~.device.QubitNode`): the qubit you want to add into this topology. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(2)]) >>> topology.add_qubit_node(QubitNode(2)); >>> topology.all_qubit_id() @@ -378,7 +378,7 @@ def all_qubit_id(self) -> typing.Set[int]: Set[int], all qubit id in this qubit topology. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(2)]) >>> topology.add_qubit_node(QubitNode(2)); >>> topology.all_qubit_id() @@ -396,7 +396,7 @@ def compress(self) -> typing.Tuple["QubitsTopology", typing.Dict[int, int]]: value be the qubit id in new topology. Examples: - >>> from mindquantum.device import LinearQubits + >>> from quafu.device import LinearQubits >>> topo1 = LinearQubits(5) >>> topo1.remove_qubit_node(0) >>> topo1.remove_qubit_node(2) @@ -430,7 +430,7 @@ def edges_with_id(self) -> typing.Set[typing.Tuple[int, int]]: Set[Tuple[int, int]], all connected edges in this qubit topology. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(2)]) >>> topology[0] << topology[1] >>> topology.edges_with_id() @@ -453,7 +453,7 @@ def edges_with_poi(self) -> typing.Set[typing.Tuple[typing.Tuple[float, float], Set[Tuple[Tuple[float, float], Tuple[float, float]]], the x and y position of two connected qubits. Examples: - >>> from mindquantum.device import QubitNode, QubitsTopology + >>> from quafu.device import QubitNode, QubitsTopology >>> q0 = QubitNode(0, poi_x=0, poi_y=0) >>> q1 = QubitNode(1, poi_x=1, poi_y=0) >>> q0 >> q1 @@ -479,7 +479,7 @@ def has_qubit_node(self, qubit_id: int) -> bool: bool, whether this topology has qubit node with given id. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(2)]) >>> topology.has_qubit_node(0) True @@ -499,7 +499,7 @@ def is_coupled_with(self, id1: int, id2: int) -> bool: bool, whether two qubits node with given ids coupled. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(2)]) >>> topology.is_coupled_with(0, 1) False @@ -519,7 +519,7 @@ def isolate_with_near(self, qubit_id: int) -> None: qubit_id (int): the id of qubit you want to disconnect with all nearby qubits. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology[0] >> topology[1] >> topology[2] >>> topology.edges_with_id() @@ -542,7 +542,7 @@ def n_edges(self) -> int: int, the edge number of this qubit topology. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology[0] >> topology[1] >> topology[2] >>> topology.n_edges() @@ -561,7 +561,7 @@ def choose(self, ids: typing.List[int]) -> typing.List[QubitNode]: List[:class:`~.device.QubitNode`], a list of qubit node based on given qubit node id. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology[0] >> topology[1] >> topology[2] >>> nodes = topology.choose([0, 1]) @@ -578,7 +578,7 @@ def remove_isolate_node(self) -> None: Remove qubit node that do not connect with any other qubits. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology[0] >> topology[1] >> topology[2] >>> topology.edges_with_id() @@ -606,7 +606,7 @@ def remove_qubit_node(self, qubit_id: int) -> None: qubit_id (int): the id of qubit you want to remove. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology.remove_qubit_node(1) >>> topology.all_qubit_id() @@ -630,7 +630,7 @@ def select(self, ids: typing.List[int]) -> "QubitsTopology": :class:`~.device.QubitsTopology`, a new topology while keeping the connection property. Examples: - >>> from mindquantum.device import LinearQubits + >>> from quafu.device import LinearQubits >>> t1 = LinearQubits(4) >>> t2 = t1.select([0, 1, 2]) >>> t2.edges_with_id() @@ -655,7 +655,7 @@ def set_color(self, qubit_id: int, color: str) -> None: color (str): the new color. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology.set_color(0, "#ababab") >>> topology[0].color @@ -703,7 +703,7 @@ def set_position(self, qubit_id: int, poi_x: float, poi_y: float) -> None: poi_y (float): new y position. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology.set_position(0, 1, 1) >>> topology[0].poi_x, topology[0].poi_y @@ -724,7 +724,7 @@ def show(self, method: Optional[AVA_SHOW_METHOD] = None): can also set it to ``'mpl'`` or ``'svg'`` manually. Default: ``None``. """ # pylint: disable=import-outside-toplevel - from mindquantum.io.display import draw_topology, draw_topology_plt + from quafu.io.display import draw_topology, draw_topology_plt is_jupyter = Console().is_jupyter if method is None: @@ -743,7 +743,7 @@ def size(self) -> int: int, the total qubit number. Examples: - >>> from mindquantum.device import QubitsTopology, QubitNode + >>> from quafu.device import QubitsTopology, QubitNode >>> topology = QubitsTopology([QubitNode(i) for i in range(3)]) >>> topology.size() 3 @@ -759,7 +759,7 @@ class LinearQubits(QubitsTopology): n_qubits (int): total qubit size. Examples: - >>> from mindquantum.device import LinearQubits + >>> from quafu.device import LinearQubits >>> topology = LinearQubits(5) >>> topology.is_coupled_with(0, 1) True @@ -786,7 +786,7 @@ class GridQubits(QubitsTopology): n_col (int): how many columns of your grid quits. Examples: - >>> from mindquantum.device import GridQubits + >>> from quafu.device import GridQubits >>> topology = GridQubits(2, 3) >>> topology.n_row() 2 @@ -820,7 +820,7 @@ def n_col(self) -> int: int, the column number. Examples: - >>> from mindquantum.device import GridQubits + >>> from quafu.device import GridQubits >>> topology = GridQubits(2, 3) >>> topology.n_col() 3 @@ -835,7 +835,7 @@ def n_row(self) -> int: int, the row number. Examples: - >>> from mindquantum.device import GridQubits + >>> from quafu.device import GridQubits >>> topology = GridQubits(2, 3) >>> topology.n_row() 2 diff --git a/mindquantum/device/vigo_property.py b/quafu/device/vigo_property.py similarity index 99% rename from mindquantum/device/vigo_property.py rename to quafu/device/vigo_property.py index 2d670bb72..b31fdc22f 100644 --- a/mindquantum/device/vigo_property.py +++ b/quafu/device/vigo_property.py @@ -13,8 +13,8 @@ # limitations under the License. # ============================================================================ """Vigo.""" -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import BitFlipChannel, DepolarizingChannel, KrausChannel +from quafu.core.circuit import Circuit +from quafu.core.gates import BitFlipChannel, DepolarizingChannel, KrausChannel vigo_noise_model = { ('readout', 0): BitFlipChannel(0.07509999999999994).on(0), diff --git a/mindquantum/dtype/__init__.py b/quafu/dtype/__init__.py similarity index 94% rename from mindquantum/dtype/__init__.py rename to quafu/dtype/__init__.py index be68912fe..3c555bf59 100644 --- a/mindquantum/dtype/__init__.py +++ b/quafu/dtype/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Data type module for MindQuantum.""" +"""Data type module for quafu.""" from .dtype import ( complex64, @@ -25,7 +25,7 @@ precision_str, to_complex_type, to_double_precision, - to_mq_type, + to_quafu_type, to_np_type, to_precision_like, to_real_type, @@ -41,7 +41,7 @@ "to_complex_type", "to_double_precision", "to_single_precision", - "to_mq_type", + "to_quafu_type", "to_np_type", "precision_str", "is_same_precision", diff --git a/mindquantum/dtype/dtype.py b/quafu/dtype/dtype.py similarity index 67% rename from mindquantum/dtype/dtype.py rename to quafu/dtype/dtype.py index ed4fdc298..56f89a897 100644 --- a/mindquantum/dtype/dtype.py +++ b/quafu/dtype/dtype.py @@ -15,8 +15,8 @@ """MindSpore Quantum dtype module.""" import numpy as np -from mindquantum._math import dtype as dtype_ -from mindquantum.utils.type_value_check import _check_mq_type +from quafu._math import dtype as dtype_ +from quafu.utils.type_value_check import _check_quafu_type __dtype__ = [ 'float32', @@ -29,9 +29,9 @@ float64 = dtype_.float64 complex64 = dtype_.complex64 complex128 = dtype_.complex128 -mq_number_type = [float32, float64, complex64, complex128] -mq_real_number_type = [float32, float64] -mq_complex_number_type = [complex64, complex128] +quafu_number_type = [float32, float64, complex64, complex128] +quafu_real_number_type = [float32, float64] +quafu_complex_number_type = [complex64, complex128] str_dtype_map = { str(float32): float32, @@ -41,19 +41,19 @@ } -def to_mq_type(dtype): +def to_quafu_type(dtype): """ - Convert type to mindquantum type. + Convert type to quafu type. Args: - dtype (Union[mindquantum.dtype, mindspore.dtype, numpy.dtype]): The data type supported by - mindquantum or mindspore or numpy. + dtype (Union[quafu.dtype, mindspore.dtype, numpy.dtype]): The data type supported by + quafu or mindspore or numpy. Examples: - >>> from mindquantum import to_mq_type + >>> from quafu import to_quafu_type >>> import numpy as np - >>> to_mq_type(np.complex128) - mindquantum.complex128 + >>> to_quafu_type(np.complex128) + quafu.complex128 """ type_mapper = { float32: float32, @@ -91,14 +91,14 @@ def to_real_type(dtype): Convert type to real type while keeping precision. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import to_real_type, complex128 + >>> from quafu import to_real_type, complex128 >>> to_real_type(complex128) - mindquantum.float64 + quafu.float64 """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return { float32: float32, float64: float64, @@ -112,14 +112,14 @@ def to_complex_type(dtype): Convert type to complex type while keeping precision. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import to_complex_type, float32 + >>> from quafu import to_complex_type, float32 >>> to_complex_type(float32) - mindquantum.complex64 + quafu.complex64 """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return { float32: complex64, float64: complex128, @@ -133,14 +133,14 @@ def to_double_precision(dtype): Convert type to double precision. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import to_double_precision, float32 + >>> from quafu import to_double_precision, float32 >>> to_double_precision(float32) - mindquantum.float64 + quafu.float64 """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return { float32: float64, float64: float64, @@ -154,14 +154,14 @@ def to_single_precision(dtype): Convert type to single precision. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import to_single_precision, complex128 + >>> from quafu import to_single_precision, complex128 >>> to_single_precision(complex128) - mindquantum.complex64 + quafu.complex64 """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return { float32: float32, float64: float32, @@ -175,13 +175,13 @@ def to_precision_like(dtype_src, dtype_des): Convert dtype_src to same precision as dtype_des. Args: - dtype_src (mindquantum.dtype): The data type supported by mindquantum. - dtype_des (mindquantum.dtype): The data type supported by mindquantum. + dtype_src (quafu.dtype): The data type supported by quafu. + dtype_des (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import to_precision_like, float32, complex128 + >>> from quafu import to_precision_like, float32, complex128 >>> to_precision_like(float32, complex128) - >>> mindquantum.float64 + >>> quafu.float64 """ if is_double_precision(dtype_des): return to_double_precision(dtype_src) @@ -195,10 +195,10 @@ def to_np_type(dtype): Convert type to numpy data type. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import to_np_type, complex128 + >>> from quafu import to_np_type, complex128 >>> to_np_type(complex128) numpy.complex128 """ @@ -215,14 +215,14 @@ def is_double_precision(dtype) -> bool: Check whether a type is double precision or not. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import is_double_precision, complex128 + >>> from quafu import is_double_precision, complex128 >>> is_double_precision(complex128) True """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return dtype in [complex128, float64] @@ -231,14 +231,14 @@ def is_single_precision(dtype) -> bool: Check whether a type is single precision or not. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import is_single_precision, complex128 + >>> from quafu import is_single_precision, complex128 >>> is_single_precision(complex128) False """ - _check_mq_type(dtype) + _check_quafu_type(dtype) return dtype in [complex64, float32] @@ -247,11 +247,11 @@ def is_same_precision(dtype1, dtype2) -> bool: Check whether two type is same precision or not. Args: - dtype1 (mindquantum.dtype): The data type supported by mindquantum. - dtype2 (mindquantum.dtype): The data type supported by mindquantum. + dtype1 (quafu.dtype): The data type supported by quafu. + dtype2 (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import is_same_precision, complex128, float64 + >>> from quafu import is_same_precision, complex128, float64 >>> is_same_precision(complex128, float64) True """ @@ -265,10 +265,10 @@ def precision_str(dtype) -> str: Get precision string. Args: - dtype (mindquantum.dtype): The data type supported by mindquantum. + dtype (quafu.dtype): The data type supported by quafu. Examples: - >>> from mindquantum import precision_str, complex128 + >>> from quafu import precision_str, complex128 >>> precision_str(complex128) 'double precision' """ diff --git a/mindquantum/engine/__init__.py b/quafu/engine/__init__.py similarity index 100% rename from mindquantum/engine/__init__.py rename to quafu/engine/__init__.py diff --git a/mindquantum/engine/circuitengine.py b/quafu/engine/circuitengine.py similarity index 94% rename from mindquantum/engine/circuitengine.py rename to quafu/engine/circuitengine.py index a37030986..5d7f32897 100644 --- a/mindquantum/engine/circuitengine.py +++ b/quafu/engine/circuitengine.py @@ -14,7 +14,7 @@ # ============================================================================ """Simple engine to generate parameterized quantum circuit.""" -from mindquantum.core.circuit import Circuit +from quafu.core.circuit import Circuit class BasicQubit: @@ -88,8 +88,8 @@ def generator(n_qubits, *args, **kwds): n_qubits (int): qubit number of quantum circuit. Examples: - >>> import mindquantum.core.gates as G - >>> from mindquantum.engine import circuit_generator + >>> import quafu.core.gates as G + >>> from quafu.engine import circuit_generator >>> @circuit_generator(2,prefix='p') ... def ansatz(qubits, prefix): ... G.X | (qubits[0], qubits[1]) @@ -101,7 +101,7 @@ def generator(n_qubits, *args, **kwds): q1: ──┨╺╋╸┠─┨ RX(p_0) ┠─── ┗━━━┛ ┗━━━━━━━━━┛ >>> print(type(ansatz)) - + """ def deco(func): diff --git a/mindquantum/framework/__init__.py b/quafu/framework/__init__.py similarity index 72% rename from mindquantum/framework/__init__.py rename to quafu/framework/__init__.py index 097c3f09e..ea311d7cf 100644 --- a/mindquantum/framework/__init__.py +++ b/quafu/framework/__init__.py @@ -16,16 +16,16 @@ import warnings framework_modules = [ - "MQAnsatzOnlyLayer", - "MQN2AnsatzOnlyLayer", - "MQLayer", - "MQN2Layer", - "MQOps", - "MQN2Ops", - "MQAnsatzOnlyOps", - "MQN2AnsatzOnlyOps", - "MQEncoderOnlyOps", - "MQN2EncoderOnlyOps", + "QUAFUAnsatzOnlyLayer", + "QUAFUN2AnsatzOnlyLayer", + "QUAFULayer", + "QUAFUN2Layer", + "QUAFUOps", + "QUAFUN2Ops", + "QUAFUAnsatzOnlyOps", + "QUAFUN2AnsatzOnlyOps", + "QUAFUEncoderOnlyOps", + "QUAFUN2EncoderOnlyOps", "QRamVecOps", "QRamVecLayer", ] @@ -35,19 +35,19 @@ import mindspore from .layer import ( - MQAnsatzOnlyLayer, - MQLayer, - MQN2AnsatzOnlyLayer, - MQN2Layer, + QUAFUAnsatzOnlyLayer, + QUAFULayer, + QUAFUN2AnsatzOnlyLayer, + QUAFUN2Layer, QRamVecLayer, ) from .operations import ( - MQAnsatzOnlyOps, - MQEncoderOnlyOps, - MQN2AnsatzOnlyOps, - MQN2EncoderOnlyOps, - MQN2Ops, - MQOps, + QUAFUAnsatzOnlyOps, + QUAFUEncoderOnlyOps, + QUAFUN2AnsatzOnlyOps, + QUAFUN2EncoderOnlyOps, + QUAFUN2Ops, + QUAFUOps, QRamVecOps, ) @@ -64,7 +64,7 @@ "Some functions might not work or even raise error. Please install MindSpore " "version >= 1.4.0. For more details about dependency setting, please check " "the instructions at MindSpore official website https://www.mindspore.cn/install " - "or check the README.md at https://gitee.com/mindspore/mindquantum", + "or check the README.md at https://gitee.com/mindspore/quafu", stacklevel=2, ) @@ -78,8 +78,8 @@ def __getattr__(name): if name in framework_modules: raise ImportError( - f"cannot import '{name}' from 'mindquantum.framework'. " - "MindSpore not installed, 'mindquantum.framework' modules " + f"cannot import '{name}' from 'quafu.framework'. " + "MindSpore not installed, 'quafu.framework' modules " "(for hybrid quantum-classical neural network) are disabled." ) - raise ImportError(f"cannot import '{name}' from 'mindquantum'. '{name}' does not exist in mindquantum.") + raise ImportError(f"cannot import '{name}' from 'quafu'. '{name}' does not exist in quafu.") diff --git a/mindquantum/framework/layer.py b/quafu/framework/layer.py similarity index 85% rename from mindquantum/framework/layer.py rename to quafu/framework/layer.py index 1ab431fd9..08a490aaf 100644 --- a/mindquantum/framework/layer.py +++ b/quafu/framework/layer.py @@ -18,10 +18,10 @@ from mindspore.common.initializer import initializer from mindspore.common.parameter import Parameter -from .operations import MQAnsatzOnlyOps, MQN2AnsatzOnlyOps, MQN2Ops, MQOps, QRamVecOps +from .operations import QUAFUAnsatzOnlyOps, QUAFUN2AnsatzOnlyOps, QUAFUN2Ops, QUAFUOps, QRamVecOps -class MQLayer(nn.Cell): # pylint: disable=too-few-public-methods +class QUAFULayer(nn.Cell): # pylint: disable=too-few-public-methods """ Quantum neural network include encoder and ansatz circuit. @@ -55,19 +55,19 @@ class MQLayer(nn.Cell): # pylint: disable=too-few-public-methods Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQLayer - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFULayer + >>> from quafu.simulator import Simulator >>> ms.set_seed(42) >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> enc = Circuit().ry('a', 0).as_encoder() >>> ans = Circuit().h(0).rx('b', 0).as_ansatz() >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, enc + ans) >>> enc_data = ms.Tensor(np.array([[0.1]])) - >>> net = MQLayer(grad_ops) + >>> net = QUAFULayer(grad_ops) >>> opti = ms.nn.Adam(net.trainable_params(), learning_rate=0.1) >>> train_net = ms.nn.TrainOneStepCell(net, opti) >>> for i in range(100): @@ -80,9 +80,9 @@ class MQLayer(nn.Cell): # pylint: disable=too-few-public-methods """ def __init__(self, expectation_with_grad, weight='normal'): - """Initialize a MQLayer object.""" + """Initialize a QUAFULayer object.""" super().__init__() - self.evolution = MQOps(expectation_with_grad) + self.evolution = QUAFUOps(expectation_with_grad) weight_size = len(self.evolution.expectation_with_grad.ansatz_params_name) if isinstance(weight, ms.Tensor): if weight.ndim != 1 or weight.shape[0] != weight_size: @@ -90,13 +90,13 @@ def __init__(self, expectation_with_grad, weight='normal'): self.weight = Parameter(initializer(weight, weight_size, dtype=ms.float32), name='ansatz_weight') def construct(self, arg): - """Construct a MQLayer node.""" + """Construct a QUAFULayer node.""" return self.evolution(arg, self.weight) -class MQN2Layer(nn.Cell): # pylint: disable=too-few-public-methods +class QUAFUN2Layer(nn.Cell): # pylint: disable=too-few-public-methods """ - MindQuantum trainable layer. + quafu trainable layer. Quantum neural network include encoder and ansatz circuit. The encoder circuit encode classical data into quantum state, while the ansatz circuit act as trainable circuit. This layer will calculate the square of absolute value of @@ -130,19 +130,19 @@ class MQN2Layer(nn.Cell): # pylint: disable=too-few-public-methods Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQN2Layer - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUN2Layer + >>> from quafu.simulator import Simulator >>> ms.set_seed(42) >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> enc = Circuit().ry('a', 0).as_encoder() >>> ans = Circuit().h(0).rx('b', 0).as_ansatz() >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, enc + ans) >>> enc_data = ms.Tensor(np.array([[0.1]])) - >>> net = MQN2Layer(grad_ops) + >>> net = QUAFUN2Layer(grad_ops) >>> opti = ms.nn.Adam(net.trainable_params(), learning_rate=0.1) >>> train_net = ms.nn.TrainOneStepCell(net, opti) >>> for i in range(100): @@ -155,9 +155,9 @@ class MQN2Layer(nn.Cell): # pylint: disable=too-few-public-methods """ def __init__(self, expectation_with_grad, weight='normal'): - """Initialize a MQN2Layer object.""" + """Initialize a QUAFUN2Layer object.""" super().__init__() - self.evolution = MQN2Ops(expectation_with_grad) + self.evolution = QUAFUN2Ops(expectation_with_grad) weight_size = len(self.evolution.expectation_with_grad.ansatz_params_name) if isinstance(weight, ms.Tensor): if weight.ndim != 1 or weight.shape[0] != weight_size: @@ -165,13 +165,13 @@ def __init__(self, expectation_with_grad, weight='normal'): self.weight = Parameter(initializer(weight, weight_size, dtype=ms.float32), name='ansatz_weight') def construct(self, arg): - """Construct a MQN2Layer node.""" + """Construct a QUAFUN2Layer node.""" return self.evolution(arg, self.weight) -class MQAnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods +class QUAFUAnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods """ - MindQuantum trainable layer. + quafu trainable layer. Quantum neural network only include ansatz circuit. The ansatz circuit act as trainable circuit. @@ -200,17 +200,17 @@ class MQAnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQAnsatzOnlyLayer - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUAnsatzOnlyLayer + >>> from quafu.simulator import Simulator >>> ms.set_seed(42) >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) - >>> net = MQAnsatzOnlyLayer(grad_ops) + >>> net = QUAFUAnsatzOnlyLayer(grad_ops) >>> opti = ms.nn.Adam(net.trainable_params(), learning_rate=0.1) >>> train_net = ms.nn.TrainOneStepCell(net, opti) >>> for i in range(100): @@ -222,9 +222,9 @@ class MQAnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods """ def __init__(self, expectation_with_grad, weight='normal'): - """Initialize a MQAnsatzOnlyLayer object.""" + """Initialize a QUAFUAnsatzOnlyLayer object.""" super().__init__() - self.evolution = MQAnsatzOnlyOps(expectation_with_grad) + self.evolution = QUAFUAnsatzOnlyOps(expectation_with_grad) weight_size = len(self.evolution.expectation_with_grad.ansatz_params_name) if isinstance(weight, ms.Tensor): if weight.ndim != 1 or weight.shape[0] != weight_size: @@ -232,13 +232,13 @@ def __init__(self, expectation_with_grad, weight='normal'): self.weight = Parameter(initializer(weight, weight_size, dtype=ms.float32), name='ansatz_weight') def construct(self): - """Construct a MQAnsatzOnlyLayer node.""" + """Construct a QUAFUAnsatzOnlyLayer node.""" return self.evolution(self.weight) -class MQN2AnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods +class QUAFUN2AnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods """ - MindQuantum trainable layer. + quafu trainable layer. Quantum neural network only include ansatz circuit. The ansatz circuit act as trainable circuit. This layer will calculate the square of absolute value of expectation automatically. @@ -271,17 +271,17 @@ class MQN2AnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQN2AnsatzOnlyLayer - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUN2AnsatzOnlyLayer + >>> from quafu.simulator import Simulator >>> ms.set_seed(43) >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) - >>> net = MQN2AnsatzOnlyLayer(grad_ops) + >>> net = QUAFUN2AnsatzOnlyLayer(grad_ops) >>> opti = ms.nn.Adam(net.trainable_params(), learning_rate=0.1) >>> train_net = ms.nn.TrainOneStepCell(net, opti) >>> for i in range(100): @@ -293,9 +293,9 @@ class MQN2AnsatzOnlyLayer(nn.Cell): # pylint: disable=too-few-public-methods """ def __init__(self, expectation_with_grad, weight='normal'): - """Initialize a MQN2AnsatzOnlyLayer object.""" + """Initialize a QUAFUN2AnsatzOnlyLayer object.""" super().__init__() - self.evolution = MQN2AnsatzOnlyOps(expectation_with_grad) + self.evolution = QUAFUN2AnsatzOnlyOps(expectation_with_grad) weight_size = len(self.evolution.expectation_with_grad.ansatz_params_name) if isinstance(weight, ms.Tensor): if weight.ndim != 1 or weight.shape[0] != weight_size: @@ -303,7 +303,7 @@ def __init__(self, expectation_with_grad, weight='normal'): self.weight = Parameter(initializer(weight, weight_size, dtype=ms.float32), name='ansatz_weight') def construct(self): - """Construct a MQN2AnsatzOnlyLayer node.""" + """Construct a QUAFUN2AnsatzOnlyLayer node.""" return self.evolution(self.weight) @@ -352,15 +352,15 @@ class QRamVecLayer(nn.Cell): # pylint: disable=too-few-public-methods Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import QRamVecLayer - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QRamVecLayer + >>> from quafu.simulator import Simulator >>> ms.set_seed(42) >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> ans = Circuit().ry('a', 0).rx('b', 0).as_ansatz() >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, ans) >>> qs = np.array([[1.0, 2.0]])/np.sqrt(5) >>> qs_r, qs_i = ms.Tensor(qs.real), ms.Tensor(qs.imag) @@ -382,7 +382,7 @@ class QRamVecLayer(nn.Cell): # pylint: disable=too-few-public-methods # pylint: disable=too-many-arguments def __init__(self, ham, circ, sim, n_thread=None, weight='normal'): - """Initialize a MQLayer object.""" + """Initialize a QUAFULayer object.""" super().__init__() self.evolution = QRamVecOps(ham, circ, sim, n_thread) weight_size = len(self.evolution.circ.params_name) @@ -392,5 +392,5 @@ def __init__(self, ham, circ, sim, n_thread=None, weight='normal'): self.weight = Parameter(initializer(weight, weight_size, dtype=ms.float32), name='ansatz_weight') def construct(self, qs_r, qs_i): - """Construct a MQLayer node.""" + """Construct a QUAFULayer node.""" return self.evolution(qs_r, qs_i, self.weight) diff --git a/mindquantum/framework/operations.py b/quafu/framework/operations.py similarity index 87% rename from mindquantum/framework/operations.py rename to quafu/framework/operations.py index 64c7ee3b9..0ba593950 100644 --- a/mindquantum/framework/operations.py +++ b/quafu/framework/operations.py @@ -19,10 +19,10 @@ from mindspore.ops import operations from mindspore.ops.primitive import constexpr -from mindquantum.core.circuit import Circuit -from mindquantum.core.operators import Hamiltonian -from mindquantum.simulator import GradOpsWrapper, Simulator -from mindquantum.utils.type_value_check import ( +from quafu.core.circuit import Circuit +from quafu.core.operators import Hamiltonian +from quafu.simulator import GradOpsWrapper, Simulator +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_value_should_not_less, @@ -64,9 +64,9 @@ def check_state_vector_shape(data, data_shape, qubit_dim): ) -class MQOps(nn.Cell): +class QUAFUOps(nn.Cell): """ - MindQuantum operator. + quafu operator. A quantum circuit evolution operator that include encoder and ansatz circuit, who return the expectation of given hamiltonian w.r.t final state of parameterized quantum circuit (PQC). @@ -93,22 +93,22 @@ class MQOps(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQOps - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUOps + >>> from quafu.simulator import Simulator >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> enc = Circuit().ry('a', 0).as_encoder() >>> ans = Circuit().h(0).rx('b', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, enc + ans) >>> enc_data = np.array([[0.1]]) >>> ans_data = np.array([0.2]) >>> f, g_enc, g_ans = grad_ops(enc_data, ans_data) >>> f array([[0.0978434+0.j]]) - >>> net = MQOps(grad_ops) + >>> net = QUAFUOps(grad_ops) >>> f_ms = net(ms.Tensor(enc_data), ms.Tensor(ans_data)) >>> f_ms Tensor(shape=[1, 1], dtype=Float32, value= @@ -116,7 +116,7 @@ class MQOps(nn.Cell): """ def __init__(self, expectation_with_grad): - """Initialize a MQOps object.""" + """Initialize a QUAFUOps object.""" super().__init__() _mode_check(self) _check_grad_ops(expectation_with_grad) @@ -130,7 +130,7 @@ def extend_repr(self): return self.expectation_with_grad.str def construct(self, enc_data, ans_data): - """Construct an MQOps node.""" + """Construct an QUAFUOps node.""" check_enc_input_shape(enc_data, self.shape_ops(enc_data), len(self.expectation_with_grad.encoder_params_name)) check_ans_input_shape(ans_data, self.shape_ops(ans_data), len(self.expectation_with_grad.ansatz_params_name)) fval, g_enc, g_ans = self.expectation_with_grad(enc_data.asnumpy(), ans_data.asnumpy()) @@ -146,9 +146,9 @@ def bprop(self, enc_data, ans_data, out, dout): # pylint: disable=unused-argume return ms.Tensor(enc_grad, dtype=ms.float32), ms.Tensor(ans_grad, dtype=ms.float32) -class MQN2Ops(nn.Cell): +class QUAFUN2Ops(nn.Cell): r""" - MindQuantum operator. + quafu operator. A quantum circuit evolution operator that include encoder and ansatz circuit, who return the square of absolute value of expectation of given hamiltonian w.r.t final state of @@ -179,22 +179,22 @@ class MQN2Ops(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQN2Ops - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUN2Ops + >>> from quafu.simulator import Simulator >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> enc = Circuit().ry('a', 0).as_encoder() >>> ans = Circuit().h(0).rx('b', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, enc + ans) >>> enc_data = np.array([[0.1]]) >>> ans_data = np.array([0.2]) >>> f, g_enc, g_ans = grad_ops(enc_data, ans_data) >>> np.abs(f) ** 2 array([[0.00957333]]) - >>> net = MQN2Ops(grad_ops) + >>> net = QUAFUN2Ops(grad_ops) >>> f_ms = net(ms.Tensor(enc_data), ms.Tensor(ans_data)) >>> f_ms Tensor(shape=[1, 1], dtype=Float32, value= @@ -202,7 +202,7 @@ class MQN2Ops(nn.Cell): """ def __init__(self, expectation_with_grad): - """Initialize a MQN2Ops object.""" + """Initialize a QUAFUN2Ops object.""" super().__init__() _mode_check(self) _check_grad_ops(expectation_with_grad) @@ -217,7 +217,7 @@ def extend_repr(self): return self.expectation_with_grad.str def construct(self, enc_data, ans_data): - """Construct an MQN2Ops node.""" + """Construct an QUAFUN2Ops node.""" check_enc_input_shape(enc_data, self.shape_ops(enc_data), len(self.expectation_with_grad.encoder_params_name)) check_ans_input_shape(ans_data, self.shape_ops(ans_data), len(self.expectation_with_grad.ansatz_params_name)) fval, g_enc, g_ans = self.expectation_with_grad(enc_data.asnumpy(), ans_data.asnumpy()) @@ -234,9 +234,9 @@ def bprop(self, enc_data, ans_data, out, dout): # pylint: disable=unused-argume return ms.Tensor(enc_grad, dtype=ms.float32), ms.Tensor(ans_grad, dtype=ms.float32) -class MQAnsatzOnlyOps(nn.Cell): +class QUAFUAnsatzOnlyOps(nn.Cell): r""" - MindQuantum operator. + quafu operator. A quantum circuit evolution operator that only include ansatz circuit, who return the expectation of given hamiltonian w.r.t final state of parameterized quantum circuit (PQC). @@ -260,27 +260,27 @@ class MQAnsatzOnlyOps(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQAnsatzOnlyOps - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUAnsatzOnlyOps + >>> from quafu.simulator import Simulator >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) >>> data = np.array([0.1, 0.2]) >>> f, g = grad_ops(data) >>> f array([[0.0978434+0.j]]) - >>> net = MQAnsatzOnlyOps(grad_ops) + >>> net = QUAFUAnsatzOnlyOps(grad_ops) >>> f_ms = net(ms.Tensor(data)) >>> f_ms Tensor(shape=[1], dtype=Float32, value= [ 9.78433937e-02]) """ def __init__(self, expectation_with_grad): - """Initialize a MQAnsatzOnlyOps object.""" + """Initialize a QUAFUAnsatzOnlyOps object.""" super().__init__() _mode_check(self) _check_grad_ops(expectation_with_grad) @@ -293,7 +293,7 @@ def extend_repr(self): return self.expectation_with_grad.str def construct(self, arg): - """Construct a MQAnsatzOnlyOps node.""" + """Construct a QUAFUAnsatzOnlyOps node.""" check_ans_input_shape(arg, self.shape_ops(arg), len(self.expectation_with_grad.ansatz_params_name)) fval, g_ans = self.expectation_with_grad(arg.asnumpy()) self.g = np.real(g_ans[0]) @@ -306,9 +306,9 @@ def bprop(self, arg, out, dout): # pylint: disable=unused-argument return ms.Tensor(grad, dtype=ms.float32) -class MQN2AnsatzOnlyOps(nn.Cell): +class QUAFUN2AnsatzOnlyOps(nn.Cell): r""" - MindQuantum operator. + quafu operator. A quantum circuit evolution operator that only include ansatz circuit, who return the square of absolute value of given hamiltonian w.r.t final state of parameterized @@ -332,27 +332,27 @@ class MQN2AnsatzOnlyOps(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQN2AnsatzOnlyOps - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUN2AnsatzOnlyOps + >>> from quafu.simulator import Simulator >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) >>> data = np.array([0.1, 0.2]) >>> f, g = grad_ops(data) >>> np.abs(f) ** 2 array([[0.00957333]]) - >>> net = MQN2AnsatzOnlyOps(grad_ops) + >>> net = QUAFUN2AnsatzOnlyOps(grad_ops) >>> f_ms = net(ms.Tensor(data)) >>> f_ms Tensor(shape=[1], dtype=Float32, value= [ 9.57333017e-03]) """ def __init__(self, expectation_with_grad): - """Initialize a MQN2AnsatzOnlyOps object.""" + """Initialize a QUAFUN2AnsatzOnlyOps object.""" super().__init__() _mode_check(self) _check_grad_ops(expectation_with_grad) @@ -367,7 +367,7 @@ def extend_repr(self): return self.expectation_with_grad.str def construct(self, arg): - """Construct a MQN2AnsatzOnlyOps node.""" + """Construct a QUAFUN2AnsatzOnlyOps node.""" check_ans_input_shape(arg, self.shape_ops(arg), len(self.expectation_with_grad.ansatz_params_name)) fval, g_ans = self.expectation_with_grad(arg.asnumpy()) self.f = fval[0] @@ -381,9 +381,9 @@ def bprop(self, arg, out, dout): # pylint: disable=unused-argument return ms.Tensor(grad, dtype=ms.float32) -class MQEncoderOnlyOps(nn.Cell): +class QUAFUEncoderOnlyOps(nn.Cell): r""" - MindQuantum operator. + quafu operator. A quantum circuit evolution operator that only include encoder circuit, who return the square of absolute value of given hamiltonian w.r.t final state of parameterized @@ -408,21 +408,21 @@ class MQEncoderOnlyOps(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQEncoderOnlyOps - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUEncoderOnlyOps + >>> from quafu.simulator import Simulator >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0).as_encoder() >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) >>> data = np.array([[0.1, 0.2], [0.3, 0.4]]) >>> f, g = grad_ops(data) >>> f array([[0.0978434 +0.j], [0.27219214+0.j]]) - >>> net = MQEncoderOnlyOps(grad_ops) + >>> net = QUAFUEncoderOnlyOps(grad_ops) >>> f_ms = net(ms.Tensor(data)) >>> f_ms Tensor(shape=[2, 1], dtype=Float32, value= @@ -431,7 +431,7 @@ class MQEncoderOnlyOps(nn.Cell): """ def __init__(self, expectation_with_grad): - """Initialize a MQEncoderOnlyOps object.""" + """Initialize a QUAFUEncoderOnlyOps object.""" super().__init__() _mode_check(self) _check_grad_ops(expectation_with_grad) @@ -444,7 +444,7 @@ def extend_repr(self): return self.expectation_with_grad.str def construct(self, arg): - """Construct a MQEncoderOnlyOps node.""" + """Construct a QUAFUEncoderOnlyOps node.""" check_enc_input_shape(arg, self.shape_ops(arg), len(self.expectation_with_grad.encoder_params_name)) fval, g_enc = self.expectation_with_grad(arg.asnumpy()) self.g = np.real(g_enc) @@ -457,9 +457,9 @@ def bprop(self, arg, out, dout): # pylint: disable=unused-argument return ms.Tensor(grad, dtype=ms.float32) -class MQN2EncoderOnlyOps(nn.Cell): +class QUAFUN2EncoderOnlyOps(nn.Cell): r""" - MindQuantum operator. + quafu operator. A quantum circuit evolution operator that only include encoder circuit, who return the square of absolute value of given hamiltonian w.r.t final state of parameterized @@ -483,21 +483,21 @@ class MQN2EncoderOnlyOps(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import MQN2EncoderOnlyOps - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QUAFUN2EncoderOnlyOps + >>> from quafu.simulator import Simulator >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0).as_encoder() >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) >>> data = np.array([[0.1, 0.2], [0.3, 0.4]]) >>> f, g = grad_ops(data) >>> np.abs(f) ** 2 array([[0.00957333], [0.07408856]]) - >>> net = MQN2EncoderOnlyOps(grad_ops) + >>> net = QUAFUN2EncoderOnlyOps(grad_ops) >>> f_ms = net(ms.Tensor(data)) >>> f_ms Tensor(shape=[2, 1], dtype=Float32, value= @@ -506,7 +506,7 @@ class MQN2EncoderOnlyOps(nn.Cell): """ def __init__(self, expectation_with_grad): - """Initialize a MQN2EncoderOnlyOps object.""" + """Initialize a QUAFUN2EncoderOnlyOps object.""" super().__init__() _mode_check(self) _check_grad_ops(expectation_with_grad) @@ -521,7 +521,7 @@ def extend_repr(self): return self.expectation_with_grad.str def construct(self, arg): - """Construct a MQN2EncoderOnlyOps node.""" + """Construct a QUAFUN2EncoderOnlyOps node.""" check_enc_input_shape(arg, self.shape_ops(arg), len(self.expectation_with_grad.encoder_params_name)) fval, g_enc = self.expectation_with_grad(arg.asnumpy()) self.f = fval @@ -538,7 +538,7 @@ def bprop(self, arg, out, dout): # pylint: disable=unused-argument # pylint: disable=too-many-instance-attributes class QRamVecOps(nn.Cell): r""" - MindQuantum vector state qram operator. + quafu vector state qram operator. A QRam operator with can directly encode classical data into quantum state vector. This ops is `PYNATIVE_MODE` supported only. @@ -575,15 +575,15 @@ class QRamVecOps(nn.Cell): Examples: >>> import numpy as np >>> import mindspore as ms - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import Hamiltonian, QubitOperator - >>> from mindquantum.framework import QRamVecOps - >>> from mindquantum.simulator import Simulator - >>> from mindquantum.utils import random_state + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import Hamiltonian, QubitOperator + >>> from quafu.framework import QRamVecOps + >>> from quafu.simulator import Simulator + >>> from quafu.utils import random_state >>> ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") >>> circ = Circuit().ry('a', 0).h(0).rx('b', 0).as_ansatz() >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) >>> qs = random_state((3, 2), norm_axis=1, seed=42) >>> qs_r, qs_i = ms.Tensor(qs.real), ms.Tensor(qs.imag) @@ -636,7 +636,7 @@ def extend_repr(self): return grad_str def construct(self, qs_r, qs_i, ans_data): - """Construct an MQOps node.""" + """Construct an QUAFUOps node.""" check_state_vector_shape(qs_r, self.shape_ops(qs_r), self.dim) check_state_vector_shape(qs_i, self.shape_ops(qs_i), self.dim) check_ans_input_shape(ans_data, self.shape_ops(ans_data), len(self.circ.params_name)) diff --git a/mindquantum/io/__init__.py b/quafu/io/__init__.py similarity index 95% rename from mindquantum/io/__init__.py rename to quafu/io/__init__.py index d66a73a35..5df583315 100644 --- a/mindquantum/io/__init__.py +++ b/quafu/io/__init__.py @@ -11,7 +11,7 @@ # 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. -"""Input/Output module for MindQuantum.""" +"""Input/Output module for quafu.""" from . import display, qasm from .beauty_print import bprint diff --git a/mindquantum/io/beauty_print.py b/quafu/io/beauty_print.py similarity index 98% rename from mindquantum/io/beauty_print.py rename to quafu/io/beauty_print.py index a5148a87d..85680dfd4 100644 --- a/mindquantum/io/beauty_print.py +++ b/quafu/io/beauty_print.py @@ -46,7 +46,7 @@ def bprint(strings: list, align=":", title='', v_around='=', h_around='|', fill_ list, a list of formatted string. Examples: - >>> from mindquantum.io import bprint + >>> from quafu.io import bprint >>> title='Info of Bob' >>> o = bprint(['Name:Bob', 'Age:17', 'Nationality:China'], ... title=title) diff --git a/mindquantum/io/display/__init__.py b/quafu/io/display/__init__.py similarity index 100% rename from mindquantum/io/display/__init__.py rename to quafu/io/display/__init__.py diff --git a/mindquantum/io/display/_config.py b/quafu/io/display/_config.py similarity index 100% rename from mindquantum/io/display/_config.py rename to quafu/io/display/_config.py diff --git a/mindquantum/io/display/bloch_plt_drawer.py b/quafu/io/display/bloch_plt_drawer.py similarity index 99% rename from mindquantum/io/display/bloch_plt_drawer.py rename to quafu/io/display/bloch_plt_drawer.py index e992466dc..2856e35c7 100644 --- a/mindquantum/io/display/bloch_plt_drawer.py +++ b/quafu/io/display/bloch_plt_drawer.py @@ -28,11 +28,11 @@ from mpl_toolkits.mplot3d.axes3d import Axes3D from mpl_toolkits.mplot3d.proj3d import proj_transform -from mindquantum.io.display._config import ( +from quafu.io.display._config import ( _bloch_default_style_, _bloch_default_style_dark_, ) -from mindquantum.utils.type_value_check import _check_input_type, _check_int_type +from quafu.utils.type_value_check import _check_input_type, _check_int_type class Arrow3D(FancyArrowPatch): @@ -78,8 +78,8 @@ class BlochScene: # pylint: disable=too-many-instance-attributes Examples: >>> import matplotlib.pyplot as plt >>> import numpy as np - >>> from mindquantum.core.gates import RX, RZ - >>> from mindquantum.io.display import BlochScene + >>> from quafu.core.gates import RX, RZ + >>> from quafu.io.display import BlochScene >>> state = np.array([1, 1 + 1j])/np.sqrt(3) >>> scene = BlochScene() >>> fig, ax = scene.create_scene() @@ -578,6 +578,7 @@ def func(i): return animation.FuncAnimation(fig, func, new_amps.shape[0], interval=interval, **kwargs) + def plot_state_bloch(quantum_state): scene = BlochScene() _, ax = scene.create_scene() diff --git a/mindquantum/io/display/circuit_svg_drawer.py b/quafu/io/display/circuit_svg_drawer.py similarity index 99% rename from mindquantum/io/display/circuit_svg_drawer.py rename to quafu/io/display/circuit_svg_drawer.py index 2025f3ef2..09207ecb8 100644 --- a/mindquantum/io/display/circuit_svg_drawer.py +++ b/quafu/io/display/circuit_svg_drawer.py @@ -22,8 +22,8 @@ import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import ( +from quafu.core.circuit import Circuit +from quafu.core.gates import ( BarrierGate, CNOTGate, Measure, @@ -34,9 +34,9 @@ TGate, XGate, ) -from mindquantum.io.display._config import _DAGGER_MASK -from mindquantum.utils import fdopen -from mindquantum.utils.type_value_check import _check_input_type +from quafu.io.display._config import _DAGGER_MASK +from quafu.utils import fdopen +from quafu.utils.type_value_check import _check_input_type class BaseComponent(ABC): diff --git a/mindquantum/io/display/circuit_text_drawer.py b/quafu/io/display/circuit_text_drawer.py similarity index 99% rename from mindquantum/io/display/circuit_text_drawer.py rename to quafu/io/display/circuit_text_drawer.py index 56aedfc52..d485ffa02 100644 --- a/mindquantum/io/display/circuit_text_drawer.py +++ b/quafu/io/display/circuit_text_drawer.py @@ -19,7 +19,7 @@ import numpy as np -from mindquantum.core import ( +from quafu.core import ( BarrierGate, BasicGate, Circuit, @@ -32,8 +32,8 @@ SWAPGate, XGate, ) -from mindquantum.io.display._config import TextCircConfig -from mindquantum.io.display.circuit_text_drawer_helper import ( +from quafu.io.display._config import TextCircConfig +from quafu.io.display.circuit_text_drawer_helper import ( BasicObj, BoxStyle, Container, diff --git a/mindquantum/io/display/circuit_text_drawer_helper.py b/quafu/io/display/circuit_text_drawer_helper.py similarity index 100% rename from mindquantum/io/display/circuit_text_drawer_helper.py rename to quafu/io/display/circuit_text_drawer_helper.py diff --git a/mindquantum/io/display/measure_res_drawer.py b/quafu/io/display/measure_res_drawer.py similarity index 100% rename from mindquantum/io/display/measure_res_drawer.py rename to quafu/io/display/measure_res_drawer.py diff --git a/mindquantum/io/display/measure_res_svg_drawer.py b/quafu/io/display/measure_res_svg_drawer.py similarity index 99% rename from mindquantum/io/display/measure_res_svg_drawer.py rename to quafu/io/display/measure_res_svg_drawer.py index 8fe844d3d..f4c9d0dac 100644 --- a/mindquantum/io/display/measure_res_svg_drawer.py +++ b/quafu/io/display/measure_res_svg_drawer.py @@ -21,7 +21,7 @@ import numpy as np -from mindquantum.io.display.circuit_svg_drawer import ( +from quafu.io.display.circuit_svg_drawer import ( BaseComponent, Line, Rect, diff --git a/mindquantum/io/display/topology_drawer.py b/quafu/io/display/topology_drawer.py similarity index 100% rename from mindquantum/io/display/topology_drawer.py rename to quafu/io/display/topology_drawer.py diff --git a/mindquantum/io/qasm/__init__.py b/quafu/io/qasm/__init__.py similarity index 100% rename from mindquantum/io/qasm/__init__.py rename to quafu/io/qasm/__init__.py diff --git a/mindquantum/io/qasm/hiqasm.py b/quafu/io/qasm/hiqasm.py similarity index 95% rename from mindquantum/io/qasm/hiqasm.py rename to quafu/io/qasm/hiqasm.py index 1e6a14cca..025ec359c 100644 --- a/mindquantum/io/qasm/hiqasm.py +++ b/quafu/io/qasm/hiqasm.py @@ -17,8 +17,8 @@ import numpy as np -from mindquantum.utils import fdopen -from mindquantum.utils.type_value_check import ( +from quafu.utils import fdopen +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_seed, @@ -52,7 +52,7 @@ def _find_qubit_id(cmd): def u3(theta, psi, lambd, qubit): """Decompose u3 gate.""" - from mindquantum import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu import ( # pylint: disable=import-outside-toplevel,cyclic-import Circuit, ) @@ -76,8 +76,8 @@ def random_hiqasm(n_qubits, gate_num, version='0.1', seed=42): # pylint: disabl str, quantum circuit in HIQASM format. Examples: - >>> from mindquantum.io import random_hiqasm - >>> from mindquantum.io import HiQASM + >>> from quafu.io import random_hiqasm + >>> from quafu.io import HiQASM >>> HiQASM_str = random_hiqasm(2, 5) >>> HiQASM = HiQASM() >>> circuit = HiQASM.from_string(HiQASM_str) @@ -153,8 +153,8 @@ class HiQASM: Examples: >>> import numpy as np - >>> from mindquantum.io.qasm import HiQASM - >>> from mindquantum.core import Circuit + >>> from quafu.io.qasm import HiQASM + >>> from quafu.core import Circuit >>> circuit = Circuit().rx(0.3, 0).z(0, 1).rzz(np.pi, [0, 1]) >>> HiQASM = HiQASM() >>> circuit_str = HiQASM.to_string(circuit) @@ -169,7 +169,7 @@ class HiQASM: def __init__(self): """Initialize a HiQASM object.""" - from mindquantum import Circuit # pylint: disable=import-outside-toplevel + from quafu import Circuit # pylint: disable=import-outside-toplevel self.circuit = Circuit() self.cmds = [] @@ -213,7 +213,7 @@ def to_string(self, circuit, version='0.1'): # pylint: disable=too-many-branche NotImplementedError: if HiQASM version not implement. ValueError: if gate not implement in this version. """ - from mindquantum import ( # pylint: disable=import-outside-toplevel + from quafu import ( # pylint: disable=import-outside-toplevel Circuit, gates, ) @@ -258,7 +258,7 @@ def to_string(self, circuit, version='0.1'): # pylint: disable=too-many-branche def _to_string_non_parametric(self, gate, ctrl_qubits, obj_qubits, version): # pylint: disable=too-many-branches """Conversion of simple gates to string.""" - from mindquantum.core import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core import ( # pylint: disable=import-outside-toplevel,cyclic-import gates, ) @@ -310,7 +310,7 @@ def _to_string_non_parametric(self, gate, ctrl_qubits, obj_qubits, version): # def _to_string_parametric(self, gate, ctrl_qubits, obj_qubits, version): """Conversion of parametric gates to string.""" - from mindquantum.core import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core import ( # pylint: disable=import-outside-toplevel,cyclic-import gates, ) @@ -388,7 +388,7 @@ def to_file(self, file_name, circuit, version='0.1'): TypeError: if `circuit` is not a Circuit. TypeError: if `version` is not a str. """ - from mindquantum.core import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core import ( # pylint: disable=import-outside-toplevel,cyclic-import Circuit, ) @@ -402,7 +402,7 @@ def to_file(self, file_name, circuit, version='0.1'): def _trans_v01(self, cmds, n_qubits): # pylint: disable=too-many-branches """Trans method for HiQASM version 0.1.""" - from mindquantum import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu import ( # pylint: disable=import-outside-toplevel,cyclic-import Circuit, gates, ) @@ -450,7 +450,7 @@ def _trans_v01(self, cmds, n_qubits): # pylint: disable=too-many-branches def _trans_v01_single_qubit(self, cmd, qubit): """Trans method for HiQASM version 0.1 (single-qubit gates).""" - from mindquantum.core import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core import ( # pylint: disable=import-outside-toplevel,cyclic-import gates, ) diff --git a/mindquantum/io/qasm/openqasm.py b/quafu/io/qasm/openqasm.py similarity index 88% rename from mindquantum/io/qasm/openqasm.py rename to quafu/io/qasm/openqasm.py index 65f83ec1a..c0fd4794e 100644 --- a/mindquantum/io/qasm/openqasm.py +++ b/quafu/io/qasm/openqasm.py @@ -20,8 +20,8 @@ import numpy as np -from mindquantum.utils import fdopen -from mindquantum.utils.type_value_check import _check_input_type +from quafu.utils import fdopen +from quafu.utils.type_value_check import _check_input_type def join_qubit(gate): @@ -30,7 +30,7 @@ def join_qubit(gate): def x_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if len(ctrl) == 1: @@ -43,7 +43,7 @@ def x_related(gate): def y_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if len(ctrl) == 1: @@ -54,7 +54,7 @@ def y_related(gate): def z_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if len(ctrl) == 1: @@ -65,21 +65,21 @@ def z_related(gate): def cnot_related(gate): - """Convert mindquantum gate to qasm.""" - from mindquantum.core import gates as G # noqa: N812 + """Convert quafu gate to qasm.""" + from quafu.core import gates as G # noqa: N812 return x_related(G.X.on(gate.obj_qubits[0], gate.obj_qubits[1:] + gate.ctrl_qubits)) def global_phase_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" if len(gate.ctrl_qubits) == 1: return f"p({-gate.coeff.const}) {gate.ctrl_qubits[0]};" raise ValueError(f"Cannot convert {gate} to qasm.") def h_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if len(ctrl) == 1: @@ -90,12 +90,12 @@ def h_related(gate): def i_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" return f"id q[{gate.obj_qubits[0]}];" def phase_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) coeff = gate.coeff.const @@ -107,7 +107,7 @@ def phase_related(gate): def rx_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) coeff = gate.coeff.const @@ -119,7 +119,7 @@ def rx_related(gate): def ry_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) coeff = gate.coeff.const @@ -131,7 +131,7 @@ def ry_related(gate): def rz_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) coeff = gate.coeff.const @@ -143,7 +143,7 @@ def rz_related(gate): def rxx_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) coeff = gate.coeff.const @@ -153,7 +153,7 @@ def rxx_related(gate): def rzz_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) coeff = gate.coeff.const @@ -163,7 +163,7 @@ def rzz_related(gate): def s_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if not ctrl: @@ -174,7 +174,7 @@ def s_related(gate): def t_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if not ctrl: @@ -185,7 +185,7 @@ def t_related(gate): def sx_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if not ctrl: @@ -196,7 +196,7 @@ def sx_related(gate): def swap_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" ctrl = gate.ctrl_qubits jointed = join_qubit(gate) if len(ctrl) == 1: @@ -207,7 +207,7 @@ def swap_related(gate): def u3_related(gate): - """Convert mindquantum gate to qasm.""" + """Convert quafu gate to qasm.""" p_0, p_1, p_2 = gate.prs p_0 = p_0.const p_1 = p_1.const @@ -367,9 +367,9 @@ def eval_pr(pr, prs, gate_params): return eval_expr(pr) -def generate_custom_gate(gate_def, custom_gate, gate_map_openqasm_mq): +def generate_custom_gate(gate_def, custom_gate, gate_map_openqasm_quafu): """Generate a custom gate defined in openqasm.""" - from mindquantum.core.circuit import Circuit + from quafu.core.circuit import Circuit gate_name, gate_params, gate_qids = extra_func_head(gate_def) body = extra_func_body(gate_def) @@ -388,22 +388,22 @@ def gate(prs, qids): sub_gate_qid = [i.strip() for i in sub_gate_qid.split(',')] real_qid = [qids[gate_qids.index(i)] for i in sub_gate_qid] real_prs = [eval_pr(i, prs, gate_params) for i in sub_gate_params] - if sub_gate_name not in gate_map_openqasm_mq: + if sub_gate_name not in gate_map_openqasm_quafu: if sub_gate_name not in custom_gate: raise ValueError(f"{sub_gate_name} not defined.") circ += custom_gate[sub_gate_name](real_prs, real_qid) else: - circ += gate_map_openqasm_mq[sub_gate_name](real_prs, real_qid) + circ += gate_map_openqasm_quafu[sub_gate_name](real_prs, real_qid) return circ custom_gate[gate_name] = gate -def mq_to_qasm_v2(circ, gate_map_mq_openqasm, version: str = '2.0'): - """Convert mindquantum circuit to openqasm.""" - from mindquantum.algorithm.compiler import BasicDecompose, compile_circuit - from mindquantum.core import gates as G # noqa: N812 - from mindquantum.core.circuit import Circuit +def quafu_to_qasm_v2(circ, gate_map_quafu_openqasm, version: str = '2.0'): + """Convert quafu circuit to openqasm.""" + from quafu.algorithm.compiler import BasicDecompose, compile_circuit + from quafu.core import gates as G # noqa: N812 + from quafu.core.circuit import Circuit if version != '2.0': raise ValueError("Only support qasm version 2.0") @@ -425,13 +425,13 @@ def mq_to_qasm_v2(circ, gate_map_mq_openqasm, version: str = '2.0'): if isinstance(gate, G.Measure): cmds.append(f"measure q[{gate.obj_qubits[0]}] -> c[{reg_map[gate.obj_qubits[0]]}];") continue - if gate.__class__ in gate_map_mq_openqasm: - cmds.append(gate_map_mq_openqasm[gate.__class__](gate)) + if gate.__class__ in gate_map_quafu_openqasm: + cmds.append(gate_map_quafu_openqasm[gate.__class__](gate)) continue compiled_circ = compile_circuit(BasicDecompose(), Circuit([gate])) for sub_gate in compiled_circ: - if sub_gate.__class__ in gate_map_mq_openqasm: - cmds.append(gate_map_mq_openqasm[sub_gate.__class__](sub_gate)) + if sub_gate.__class__ in gate_map_quafu_openqasm: + cmds.append(gate_map_quafu_openqasm[sub_gate.__class__](sub_gate)) else: raise ValueError(f"Cannot convert {sub_gate} to openqasm after decompose gate {gate}") return '\n'.join(cmds) @@ -455,9 +455,9 @@ def prepare_qasm(qasm: str): # pylint: disable=too-many-locals,too-many-branches -def qasm_to_mq_v2(qasm: str, gate_map_openqasm_mq): - """Convert openqasm to mindquantum circuit.""" - from mindquantum.core.circuit import Circuit +def qasm_to_quafu_v2(qasm: str, gate_map_openqasm_quafu): + """Convert openqasm to quafu circuit.""" + from quafu.core.circuit import Circuit cmds = prepare_qasm(qasm) circ = Circuit() @@ -476,22 +476,22 @@ def qasm_to_mq_v2(qasm: str, gate_map_openqasm_mq): if i.startswith('qreg') or i.startswith('creg') or not i: continue if i.startswith('gate '): - generate_custom_gate(i, custom_gate, gate_map_openqasm_mq) + generate_custom_gate(i, custom_gate, gate_map_openqasm_quafu) else: cmd = i.strip() gate_name, params, qids = parse_gate_cmd(cmd, qregs, cregs) if gate_name == 'barrier': - circ += gate_map_openqasm_mq['barrier'](params, [q[0] for q in qids]) + circ += gate_map_openqasm_quafu['barrier'](params, [q[0] for q in qids]) continue for qid in qids: if gate_name in custom_gate: circ += custom_gate[gate_name](params, qid) - elif gate_name in gate_map_openqasm_mq: - mq_gate = gate_map_openqasm_mq[gate_name](params, qid) + elif gate_name in gate_map_openqasm_quafu: + quafu_gate = gate_map_openqasm_quafu[gate_name](params, qid) if gate_name == 'measure': - mq_gate.key = f"q{qid[0]}_{measures.get(qid[0], 0)}" + quafu_gate.key = f"q{qid[0]}_{measures.get(qid[0], 0)}" measures[qid[0]] = measures.get(qid[0], 0) + 1 - circ += mq_gate + circ += quafu_gate else: raise ValueError(f"{cmd} not implement.") return circ @@ -503,8 +503,8 @@ class OpenQASM: Examples: >>> import numpy as np - >>> from mindquantum.core import Circuit - >>> from mindquantum.io import OpenQASM + >>> from quafu.core import Circuit + >>> from quafu.io import OpenQASM >>> circuit = Circuit().rx(0.3, 0).z(0, 1).zz(np.pi, [0, 1]) >>> openqasm = OpenQASM() >>> circuit_str = openqasm.to_string(circuit) @@ -519,10 +519,10 @@ class OpenQASM: def __init__(self): """Construct a openqasm parse.""" - from mindquantum.core import gates as G # noqa: N812 - from mindquantum.core.circuit import Circuit + from quafu.core import gates as G # noqa: N812 + from quafu.core.circuit import Circuit - self.gate_map_openqasm_mq = { + self.gate_map_openqasm_quafu = { 'barrier': lambda prs, qids: Circuit([G.BarrierGate().on(qids)]), 'ccx': lambda prs, qids: G.X.on(qids[-1], qids[:-1]), 'ch': lambda prs, qids: G.H.on(qids[-1], qids[:-1]), @@ -590,7 +590,7 @@ def __init__(self): 'c4x': lambda prs, qids: G.X.on(qids[-1], qids[:-1]), } - self.gate_map_mq_openqasm = { + self.gate_map_quafu_openqasm = { G.XGate: x_related, G.YGate: y_related, G.ZGate: z_related, @@ -628,7 +628,7 @@ def to_string(self, circuit, version="2.0"): # pylint: disable=R0912,R0914,R091 NotImplementedError: if openqasm version not implement. ValueError: if gate not implement in this version. """ - return mq_to_qasm_v2(circuit, self.gate_map_mq_openqasm, version) + return quafu_to_qasm_v2(circuit, self.gate_map_quafu_openqasm, version) def to_file(self, file_name, circuit, version="2.0"): """ @@ -644,7 +644,7 @@ def to_file(self, file_name, circuit, version="2.0"): TypeError: if `circuit` is not a Circuit. TypeError: if `version` is not a str. """ - from mindquantum.core import ( # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core import ( # pylint: disable=import-outside-toplevel,cyclic-import Circuit, ) @@ -670,7 +670,7 @@ def from_file(self, file_name): """ with fdopen(file_name, 'r') as fd: cmds = fd.readlines() - return qasm_to_mq_v2('\n'.join(cmds), self.gate_map_openqasm_mq) + return qasm_to_quafu_v2('\n'.join(cmds), self.gate_map_openqasm_quafu) def from_string(self, string): """ @@ -683,8 +683,8 @@ def from_string(self, string): :class:`~.core.circuit.Circuit`, the quantum circuit translated from OpenQASM string. Examples: - >>> from mindquantum.io import OpenQASM - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.io import OpenQASM + >>> from quafu.core.circuit import Circuit >>> circ = Circuit().x(0, 1).h(1) >>> string = OpenQASM().to_string(circ) >>> OpenQASM().from_string(string) @@ -696,4 +696,4 @@ def from_string(self, string): ┗━━━┛ """ _check_input_type('string', str, string) - return qasm_to_mq_v2(string, self.gate_map_openqasm_mq) + return qasm_to_quafu_v2(string, self.gate_map_openqasm_quafu) diff --git a/mindquantum/io/qasm/qcis.py b/quafu/io/qasm/qcis.py similarity index 94% rename from mindquantum/io/qasm/qcis.py rename to quafu/io/qasm/qcis.py index 0e82570e9..d15faf8f8 100644 --- a/mindquantum/io/qasm/qcis.py +++ b/quafu/io/qasm/qcis.py @@ -19,9 +19,10 @@ import numpy as np -from mindquantum.utils import fdopen -from mindquantum.utils.type_value_check import _check_input_type -from mindquantum.core.parameterresolver import ParameterResolver +from quafu.utils import fdopen +from quafu.utils.type_value_check import _check_input_type +from quafu.core.parameterresolver import ParameterResolver + def _floatable(string) -> bool: """Whether the input string can be converted to a float number. @@ -36,6 +37,7 @@ def _floatable(string) -> bool: num_chars = re.findall(r"([\d\.\+\-\*\/])", string) return len(num_chars) == len(string) + def _to_float(string) -> float: """convert the input floatable string to a float number. @@ -52,6 +54,7 @@ def _to_float(string) -> float: res = float(tmp[0]) return res + def _string_to_param(string) -> ParameterResolver: """Convert the input string to a ParameterResolver object. @@ -65,12 +68,12 @@ def _string_to_param(string) -> ParameterResolver: """ if "√" in string: tmp = re.findall(r"(\d+\√\d)", string) - if tmp: # there are digits before √. + if tmp: # there are digits before √. both = tmp[0].split("√") left = _to_float(both[0]) right = _to_float(both[1]) - string = string.replace(tmp[0], str(left*np.sqrt(right))) - else: # # there are not digits before √. + string = string.replace(tmp[0], str(left * np.sqrt(right))) + else: # # there are not digits before √. tmp = re.findall(r"√(\d)", string) num = _to_float(tmp[0]) string = string.replace("√" + tmp[0], str(np.sqrt(num))) @@ -83,7 +86,7 @@ def _string_to_param(string) -> ParameterResolver: string = string.replace("pi", str(np.pi)).replace("π", str(np.pi)) terms = re.findall(r"(.+?)(?=[\+\-\s])", string) data = {} - const = 0. + const = 0.0 for term in terms: tmp = re.findall(r"([^\*]+)", term) if len(tmp) == 1: @@ -105,16 +108,20 @@ def _string_to_param(string) -> ParameterResolver: data[tmp[0]] = _to_float(tmp[1]) return ParameterResolver(data=data, const=const) + def _failed_from_qcis(gate_name): raise NotImplementedError(f"Cannot convert the {gate_name} from QCIS to gate.") + def _failed_to_qcis(gate): raise NotImplementedError(f"Cannot convert the {gate} from gate to QCIS.") + def _valid_angle(angle) -> float: """Restrict the angle to the interval [-pi, pi].""" return np.mod(angle + np.pi, np.pi * 2) - np.pi + class QCIS: """Convert a circuit to qcis format. @@ -140,9 +147,11 @@ class QCIS: q1: ────────┨ Z ┠───────────────────────▓─┨ RY(-π*theta + π) ┠─── ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━┛ """ + def __init__(self): - from mindquantum.core import gates as G # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.core.circuit import Circuit # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core import gates as G # pylint: disable=import-outside-toplevel,cyclic-import + from quafu.core.circuit import Circuit # pylint: disable=import-outside-toplevel,cyclic-import + self.gate_class = G self.circuit_class = Circuit @@ -160,7 +169,7 @@ def _get_gate_name(self, term) -> str: def _get_qubits(self, term) -> List[int]: """Get the qubits acted upon by the gate from the term.""" qubits = re.findall(r"(?<=Q)(\d+)", term) - return list(reversed([int(i) for i in qubits])) # [obj_qubit, ctrl_qubit] + return list(reversed([int(i) for i in qubits])) # [obj_qubit, ctrl_qubit] def _get_gate_info(self, term) -> Tuple[str, List[int], List[ParameterResolver]]: """Get the gate information (name, params and qubits) according to the term.""" @@ -200,9 +209,9 @@ def _to_gate(self, gate_name: str, qubits: List[int], params: List[ParameterReso if gate_name == "X2M": return self.gate_class.SX.hermitian().on(*qubits) if gate_name == "Y2P": - return self.gate_class.RY(np.pi/2).on(*qubits) + return self.gate_class.RY(np.pi / 2).on(*qubits) if gate_name == "Y2M": - return self.gate_class.RY(-np.pi/2).on(*qubits) + return self.gate_class.RY(-np.pi / 2).on(*qubits) if gate_name == "RX": return self.gate_class.RX(*params).on(*qubits) if gate_name == "RY": @@ -245,7 +254,8 @@ def from_string(self, string: str): q1: ────────┨ Z ┠───────────────────────▓─┨ RY(-π*theta + π) ┠─── ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━┛ """ - from mindquantum.core.gates import BarrierGate + from quafu.core.gates import BarrierGate + _check_input_type('string', str, string) terms = self._get_gate_terms(string) circ = self.circuit_class() @@ -303,7 +313,7 @@ def to_string(self, circuit, parametric: bool = True) -> str: if circuit.is_noise_circuit: raise ValueError("Cannot convert noise circuit to QCIS.") string = [] - for gate in circuit: # type: ignore + for gate in circuit: # type: ignore if isinstance(gate, self.gate_class.BarrierGate): if not gate.obj_qubits: for i in range(circuit.n_qubits): @@ -321,7 +331,7 @@ def to_string(self, circuit, parametric: bool = True) -> str: continue if isinstance(gate, self.gate_class.XGate): if not gate.ctrl_qubits: - string.append("X " +self. _qubits_str(gate)) + string.append("X " + self._qubits_str(gate)) continue elif len(gate.ctrl_qubits) == 1: string.append("H " + f"Q{gate.obj_qubits[0]}") diff --git a/mindquantum/simulator/__init__.py b/quafu/simulator/__init__.py similarity index 100% rename from mindquantum/simulator/__init__.py rename to quafu/simulator/__init__.py diff --git a/mindquantum/simulator/available_simulator.py b/quafu/simulator/available_simulator.py similarity index 61% rename from mindquantum/simulator/available_simulator.py rename to quafu/simulator/available_simulator.py index 1e3724508..8c3e6ff65 100644 --- a/mindquantum/simulator/available_simulator.py +++ b/quafu/simulator/available_simulator.py @@ -16,25 +16,25 @@ import typing import warnings -from mindquantum import _mq_matrix, _mq_vector, mqbackend -from mindquantum.dtype import complex64, complex128 -from mindquantum.simulator.backend_base import BackendBase -from mindquantum.utils.error import SimNotAvailableError +from quafu import _quafu_matrix, _quafu_vector, quafubackend +from quafu.dtype import complex64, complex128 +from quafu.simulator.backend_base import BackendBase +from quafu.utils.error import SimNotAvailableError GPU_DISABLED_REASON = None try: - from mindquantum import _mq_vector_gpu + from quafu import _quafu_vector_gpu # pylint: disable=no-member - _mq_vector_gpu.double.mqvector_gpu(1).apply_gate(mqbackend.gate.HGate([0])) - MQVECTOR_GPU_SUPPORTED = True + _quafu_vector_gpu.double.quafuvector_gpu(1).apply_gate(quafubackend.gate.HGate([0])) + QUAFUVECTOR_GPU_SUPPORTED = True except ImportError as err: - GPU_DISABLED_REASON = f"Unable to import mqvector_gpu backend. This backend requires CUDA 11 or higher." - MQVECTOR_GPU_SUPPORTED = False + GPU_DISABLED_REASON = f"Unable to import quafuvector_gpu backend. This backend requires CUDA 11 or higher." + QUAFUVECTOR_GPU_SUPPORTED = False except RuntimeError as err: - GPU_DISABLED_REASON = f"Disable mqvector gpu backend due to: {err}" - MQVECTOR_GPU_SUPPORTED = False + GPU_DISABLED_REASON = f"Disable quafuvector gpu backend due to: {err}" + QUAFUVECTOR_GPU_SUPPORTED = False class _AvailableSimulator: @@ -43,26 +43,26 @@ class _AvailableSimulator: def __init__(self): """Init available simulator obj.""" self.base_module = { - 'mqvector': _mq_vector, - 'mqmatrix': _mq_matrix, - 'stabilizer': _mq_vector, + 'quafuvector': _quafu_vector, + 'quafumatrix': _quafu_matrix, + 'stabilizer': _quafu_vector, } self.sims = { - 'mqvector': { - complex64: _mq_vector.float, - complex128: _mq_vector.double, + 'quafuvector': { + complex64: _quafu_vector.float, + complex128: _quafu_vector.double, }, - 'mqmatrix': { - complex64: _mq_matrix.float, - complex128: _mq_matrix.double, + 'quafumatrix': { + complex64: _quafu_matrix.float, + complex128: _quafu_matrix.double, }, - 'stabilizer': _mq_vector.stabilizer, + 'stabilizer': _quafu_vector.stabilizer, } - if MQVECTOR_GPU_SUPPORTED: - self.base_module['mqvector_gpu'] = _mq_vector_gpu - self.sims['mqvector_gpu'] = { - complex64: _mq_vector_gpu.float, - complex128: _mq_vector_gpu.double, + if QUAFUVECTOR_GPU_SUPPORTED: + self.base_module['quafuvector_gpu'] = _quafu_vector_gpu + self.sims['quafuvector_gpu'] = { + complex64: _quafu_vector_gpu.float, + complex128: _quafu_vector_gpu.double, } def is_available(self, sim: typing.Union[str, BackendBase], dtype) -> bool: @@ -77,7 +77,7 @@ def is_available(self, sim: typing.Union[str, BackendBase], dtype) -> bool: def c_module(self, sim: str, dtype=None): """Get available simulator c module.""" - if sim == 'mqvector_gpu' and not MQVECTOR_GPU_SUPPORTED: + if sim == 'quafuvector_gpu' and not QUAFUVECTOR_GPU_SUPPORTED: warnings.warn(f"{GPU_DISABLED_REASON}", stacklevel=3) if dtype is None: if sim not in self.base_module: @@ -90,14 +90,14 @@ def c_module(self, sim: str, dtype=None): def py_class(self, sim: str): """Get python base class of simulator.""" if sim in self.sims: - if sim in ['mqvector', 'mqvector_gpu', 'mqmatrix']: + if sim in ['quafuvector', 'quafuvector_gpu', 'quafumatrix']: # pylint: disable=import-outside-toplevel - from mindquantum.simulator.mqsim import MQSim + from quafu.simulator.quafusim import QUAFUSim - return MQSim + return QUAFUSim if sim == 'stabilizer': # pylint: disable=import-outside-toplevel - from mindquantum.simulator.stabilizer import Stabilizer + from quafu.simulator.stabilizer import Stabilizer return Stabilizer raise SimNotAvailableError(sim) diff --git a/mindquantum/simulator/backend_base.py b/quafu/simulator/backend_base.py similarity index 95% rename from mindquantum/simulator/backend_base.py rename to quafu/simulator/backend_base.py index 94b5dfe90..b0e1d3f9e 100644 --- a/mindquantum/simulator/backend_base.py +++ b/quafu/simulator/backend_base.py @@ -18,11 +18,11 @@ import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import BasicGate -from mindquantum.core.operators import Hamiltonian -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.utils.type_value_check import _check_seed +from quafu.core.circuit import Circuit +from quafu.core.gates import BasicGate +from quafu.core.operators import Hamiltonian +from quafu.core.parameterresolver import ParameterResolver +from quafu.utils.type_value_check import _check_seed class BackendBase: diff --git a/mindquantum/simulator/mq_blas.py b/quafu/simulator/mq_blas.py similarity index 70% rename from mindquantum/simulator/mq_blas.py rename to quafu/simulator/mq_blas.py index 7c876a867..ce3ad12d8 100644 --- a/mindquantum/simulator/mq_blas.py +++ b/quafu/simulator/mq_blas.py @@ -16,34 +16,34 @@ from typing import Union -from mindquantum.utils.type_value_check import _check_input_type +from quafu.utils.type_value_check import _check_input_type # This import is required to register some of the C++ types (e.g. ParameterResolver) -from .. import mqbackend # noqa: F401 # pylint: disable=unused-import +from .. import quafubackend # noqa: F401 # pylint: disable=unused-import # isort: split -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR -from .mqsim import MQSim +from .quafusim import QUAFUSim -class MQBlas: # pylint: disable=too-few-public-methods - """MindQuantum blas module.""" +class QUAFUBlas: # pylint: disable=too-few-public-methods + """quafu blas module.""" @staticmethod - def inner_product(bra: MQSim, ket: MQSim) -> Union[float, complex]: + def inner_product(bra: QUAFUSim, ket: QUAFUSim) -> Union[float, complex]: """Get the inner product of two quantum state.""" - _check_input_type("bra", MQSim, bra) - _check_input_type("ket", MQSim, ket) + _check_input_type("bra", QUAFUSim, bra) + _check_input_type("ket", QUAFUSim, ket) if bra.name != ket.name: raise ValueError("inner product can only do between two same simulator backend.") if bra.n_qubits != ket.n_qubits: raise ValueError("Qubit of these two vector state should be same.") - blas = MQBlas._get_blas(bra) + blas = QUAFUBlas._get_blas(bra) return blas.inner_product(bra.sim, ket.sim) @staticmethod - def _get_blas(simulator: MQSim): + def _get_blas(simulator: QUAFUSim): """Get blas module w.r.t given backend.""" return SUPPORTED_SIMULATOR.c_module(simulator.name, simulator.dtype).blas diff --git a/mindquantum/simulator/mqsim.py b/quafu/simulator/mqsim.py similarity index 87% rename from mindquantum/simulator/mqsim.py rename to quafu/simulator/mqsim.py index dc455990a..d1e8c288d 100644 --- a/mindquantum/simulator/mqsim.py +++ b/quafu/simulator/mqsim.py @@ -18,16 +18,16 @@ import numpy as np from scipy.linalg import eigvals -import mindquantum as mq -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import BarrierGate, BasicGate, Measure, MeasureResult -from mindquantum.core.gates.basicgate import MultiParamsGate -from mindquantum.core.operators import Hamiltonian -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.dtype import complex128 -from mindquantum.dtype.dtype import mq_complex_number_type -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR -from mindquantum.utils.type_value_check import ( +import quafu +from quafu.core.circuit import Circuit +from quafu.core.gates import BarrierGate, BasicGate, Measure, MeasureResult +from quafu.core.gates.basicgate import MultiParamsGate +from quafu.core.operators import Hamiltonian +from quafu.core.parameterresolver import ParameterResolver +from quafu.dtype import complex128 +from quafu.dtype.dtype import quafu_complex_number_type +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.utils.type_value_check import ( _check_and_generate_pr_type, _check_ansatz, _check_encoder, @@ -35,7 +35,7 @@ _check_hamiltonian_qubits_number, _check_input_type, _check_int_type, - _check_mq_type, + _check_quafu_type, _check_seed, _check_value_should_not_less, ) @@ -47,11 +47,11 @@ # pylint: disable=abstract-method,too-many-arguments -class MQSim(BackendBase): +class QUAFUSim(BackendBase): """Mindquantum Backend.""" def __init__(self, name: str, n_qubits: int, seed=None, dtype=complex128, internal=False): - """Initialize a mindquantum backend.""" + """Initialize a quafu backend.""" super().__init__(name, n_qubits, seed, dtype) self.internal = internal if internal: @@ -60,7 +60,7 @@ def __init__(self, name: str, n_qubits: int, seed=None, dtype=complex128, intern if dtype is None: dtype = complex128 self.arithmetic_type = dtype - _check_mq_type(dtype) + _check_quafu_type(dtype) self.sim = getattr(SUPPORTED_SIMULATOR.c_module(name, dtype), name)(n_qubits, seed) def __str__(self): @@ -68,7 +68,7 @@ def __str__(self): state = self.get_qs() ret = f"{self.name} simulator with {self.n_qubits} qubit{'s' if self.n_qubits > 1 else ''} " ret += f"(little endian), dtype: {self.dtype}." - if self.name.startswith('mqvector'): + if self.name.startswith('quafuvector'): ret += "\nCurrent quantum state:\n" if self.n_qubits < 4: ret += '\n'.join(ket_string(state)) @@ -148,12 +148,12 @@ def apply_gate( def apply_hamiltonian(self, hamiltonian: Hamiltonian): """Apply a hamiltonian.""" - if not mq.is_same_precision(self.dtype, hamiltonian.dtype): + if not quafu.is_same_precision(self.dtype, hamiltonian.dtype): raise TypeError( - f"Data type of {self.name} simulator is {mq.precision_str(self.dtype)} ({self.dtype}), " - f"but given hamiltonian is {mq.precision_str(hamiltonian.dtype)} ({hamiltonian.dtype}). " - f"Please convert given hamiltonian to {mq.precision_str(self.dtype)} " - f"({mq.to_precision_like(hamiltonian.dtype, self.dtype)})." + f"Data type of {self.name} simulator is {quafu.precision_str(self.dtype)} ({self.dtype}), " + f"but given hamiltonian is {quafu.precision_str(hamiltonian.dtype)} ({hamiltonian.dtype}). " + f"Please convert given hamiltonian to {quafu.precision_str(self.dtype)} " + f"({quafu.to_precision_like(hamiltonian.dtype, self.dtype)})." ) _check_input_type('hamiltonian', Hamiltonian, hamiltonian) _check_hamiltonian_qubits_number(hamiltonian, self.n_qubits) @@ -161,10 +161,10 @@ def apply_hamiltonian(self, hamiltonian: Hamiltonian): def astype(self, dtype, seed): """Convert simulator to other type.""" - _check_mq_type(dtype) - if dtype not in mq_complex_number_type: - raise TypeError(f"dtype should be complex type, available types are {mq_complex_number_type}") - sim = MQSim(getattr(self.sim, str(dtype).rsplit('.', maxsplit=1)[-1])(seed), self.n_qubits, internal=True) + _check_quafu_type(dtype) + if dtype not in quafu_complex_number_type: + raise TypeError(f"dtype should be complex type, available types are {quafu_complex_number_type}") + sim = QUAFUSim(getattr(self.sim, str(dtype).rsplit('.', maxsplit=1)[-1])(seed), self.n_qubits, internal=True) sim.name = self.sim.sim_name() return sim @@ -175,7 +175,7 @@ def dtype(self): def copy(self) -> "BackendBase": """Copy a simulator.""" - sim = MQSim(self.name, self.n_qubits, self.seed) + sim = QUAFUSim(self.name, self.n_qubits, self.seed) sim.sim = self.sim.copy() return sim @@ -195,12 +195,12 @@ def get_expectation( if not isinstance(hamiltonian, Hamiltonian): raise TypeError(f"hamiltonian requires a Hamiltonian, but got {type(hamiltonian)}") _check_hamiltonian_qubits_number(hamiltonian, self.n_qubits) - if not mq.is_same_precision(self.dtype, hamiltonian.dtype): + if not quafu.is_same_precision(self.dtype, hamiltonian.dtype): raise TypeError( - f"Data type of {self.name} simulator is {mq.precision_str(self.dtype)} ({self.dtype}), " - f"but given hamiltonian is {mq.precision_str(hamiltonian.dtype)} ({hamiltonian.dtype}). " - f"Please convert given hamiltonian to {mq.precision_str(self.dtype)} " - f"({mq.to_precision_like(hamiltonian.dtype, self.dtype)})." + f"Data type of {self.name} simulator is {quafu.precision_str(self.dtype)} ({self.dtype}), " + f"but given hamiltonian is {quafu.precision_str(hamiltonian.dtype)} ({hamiltonian.dtype}). " + f"Please convert given hamiltonian to {quafu.precision_str(self.dtype)} " + f"({quafu.to_precision_like(hamiltonian.dtype, self.dtype)})." ) hermitian = True if circ_right is None: @@ -229,8 +229,8 @@ def get_expectation( pr = ParameterResolver(pr) if hermitian: return self.sim.get_expectation(hamiltonian.get_cpp_obj(), circ_right.get_cpp_obj(), pr) - if self.name == 'mqmatrix': - raise NotImplementedError("Non hermitian case for get_expectation not implement for mqmatrix yet.") + if self.name == 'quafumatrix': + raise NotImplementedError("Non hermitian case for get_expectation not implement for quafumatrix yet.") if simulator_left is None: return self.sim.get_expectation( hamiltonian.get_cpp_obj(), circ_right.get_cpp_obj(), circ_left.get_cpp_obj(), pr @@ -254,25 +254,25 @@ def get_expectation_with_grad( # pylint: disable=R0912,R0913,R0914,R0915 elif not isinstance(hams, list): raise TypeError(f"hams requires a Hamiltonian or a list of Hamiltonian, but get {type(hams)}") for i, ham in enumerate(hams): - if not mq.is_same_precision(self.dtype, ham.dtype): + if not quafu.is_same_precision(self.dtype, ham.dtype): raise TypeError( - f"Data type of {self.name} simulator is {mq.precision_str(self.dtype)} ({self.dtype})," - f" but {i}th hamiltonian is {mq.precision_str(ham.dtype)} ({ham.dtype}). " - f"Please convert {i}th hamiltonian to {mq.precision_str(self.dtype)} " - f"({mq.to_precision_like(ham.dtype, self.dtype)})." + f"Data type of {self.name} simulator is {quafu.precision_str(self.dtype)} ({self.dtype})," + f" but {i}th hamiltonian is {quafu.precision_str(ham.dtype)} ({ham.dtype}). " + f"Please convert {i}th hamiltonian to {quafu.precision_str(self.dtype)} " + f"({quafu.to_precision_like(ham.dtype, self.dtype)})." ) for h_tmp in hams: _check_input_type("hams's element", Hamiltonian, h_tmp) _check_hamiltonian_qubits_number(h_tmp, self.n_qubits) _check_input_type("circ_right", Circuit, circ_right) - if circ_right.is_noise_circuit and "mqvector" in self.name: + if circ_right.is_noise_circuit and "quafuvector" in self.name: if circ_left is not None or simulator_left is not None: raise ValueError( "noise circuit use parameter shift rule to get grad, \ which not support circ_left and simulator_left." ) pr_shift = True - if pr_shift and not self.name.startswith('mqvector'): + if pr_shift and not self.name.startswith('quafuvector'): raise ValueError(f"{self.name} simulator not support parameter-shift rule.") non_hermitian = False if circ_left is not None: @@ -281,7 +281,7 @@ def get_expectation_with_grad( # pylint: disable=R0912,R0913,R0914,R0915 raise ValueError("noise left circuit not support yet.") non_hermitian = True if simulator_left is not None: - _check_input_type("simulator_left", MQSim, simulator_left) + _check_input_type("simulator_left", QUAFUSim, simulator_left) if self.name != simulator_left.name: raise ValueError( "simulator_left should have the same backend as this simulator, " @@ -373,7 +373,7 @@ def grad_ops(*inputs_): batch_threads, mea_threads, ) - elif circ_right.is_noise_circuit and self.name.startswith('mqmatrix'): + elif circ_right.is_noise_circuit and self.name.startswith('quafumatrix'): f_g1_g2 = self.sim.get_expectation_with_noise_grad_multi_multi( [i.get_cpp_obj() for i in hams], circ_right.get_cpp_obj(), @@ -426,7 +426,7 @@ def grad_ops(*inputs_): return grad_wrapper def get_qs(self, ket=False) -> np.ndarray: - """Get quantum state of mqvector simulator.""" + """Get quantum state of quafuvector simulator.""" if not isinstance(ket, bool): raise TypeError(f"ket requires a bool, but get {type(ket)}") state = np.array(self.sim.get_qs()) @@ -435,7 +435,7 @@ def get_qs(self, ket=False) -> np.ndarray: return state def reset(self): - """Reset mindquantum simulator to quantum zero state.""" + """Reset quafu simulator to quantum zero state.""" return self.sim.reset() def sampling( @@ -479,8 +479,8 @@ def set_qs(self, quantum_state: np.ndarray): """Set quantum state of simulator. Args: - quantum_state: Input quantum state as numpy array. For mqmatrix simulator, - can be either 1D vector or 2D density matrix. For mqvector simulator, + quantum_state: Input quantum state as numpy array. For quafumatrix simulator, + can be either 1D vector or 2D density matrix. For quafuvector simulator, must be 1D vector. """ try: @@ -494,7 +494,7 @@ def set_qs(self, quantum_state: np.ndarray): if self.n_qubits != int(n_qubits): raise ValueError(f"{int(n_qubits)} qubits vec does not match with simulation qubits ({self.n_qubits})") - if self.name == "mqmatrix": + if self.name == "quafumatrix": self._set_matrix_state(quantum_state) else: self._set_vector_state(quantum_state) @@ -537,15 +537,15 @@ def get_partial_trace(self, obj_qubits) -> np.ndarray: raise ValueError("obj_qubits cannot be repeated.") if self.n_qubits <= max(obj_qubits): raise ValueError(f"object qubits {obj_qubits} is higher than simulator qubits.") - if not self.name.startswith('mqmatrix'): + if not self.name.startswith('quafumatrix'): raise ValueError(f"{self.name} simulator not support partial trace method.") return np.array(self.sim.get_partial_trace(obj_qubits)) def entropy(self) -> float: """Get the von-Neumann entropy of quantum state.""" - if self.name.startswith('mqvector'): + if self.name.startswith('quafuvector'): return 0 - if not self.name.startswith('mqmatrix'): + if not self.name.startswith('quafumatrix'): raise ValueError(f"{self.name} simulator not support entropy method.") eigens = np.real(eigvals(self.get_qs())) res = 0 @@ -556,13 +556,13 @@ def entropy(self) -> float: def purity(self) -> float: """Calculate the purity of quantum state.""" - if self.name.startswith('mqvector'): + if self.name.startswith('quafuvector'): return 1.0 return self.sim.purity() def get_pure_state_vector(self) -> np.ndarray: """Get the state vector from a pure density matrix.""" - if self.name.startswith('mqvector'): + if self.name.startswith('quafuvector'): return self.get_qs() if 1 - self.purity() > 1e-6: raise ValueError("Cannot transform mixed density matrix to vector.") diff --git a/mindquantum/simulator/noise.py b/quafu/simulator/noise.py similarity index 86% rename from mindquantum/simulator/noise.py rename to quafu/simulator/noise.py index a3402b7aa..c0cdbeeee 100644 --- a/mindquantum/simulator/noise.py +++ b/quafu/simulator/noise.py @@ -17,12 +17,12 @@ import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.circuit.channel_adder import ChannelAdderBase -from mindquantum.core.gates import BasicGate -from mindquantum.core.operators import Hamiltonian -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.simulator.backend_base import BackendBase +from quafu.core.circuit import Circuit +from quafu.core.circuit.channel_adder import ChannelAdderBase +from quafu.core.gates import BasicGate +from quafu.core.operators import Hamiltonian +from quafu.core.parameterresolver import ParameterResolver +from quafu.simulator.backend_base import BackendBase # pylint: disable=abstract-method,super-init-not-called,too-many-arguments @@ -32,7 +32,7 @@ class NoiseBackendImpl(BackendBase): def __init__(self, base_sim: str, n_qubits: int, adder: ChannelAdderBase, seed: int = None, dtype=None): """Initialize a noise backend.""" # pylint: disable=import-outside-toplevel - from mindquantum.simulator import Simulator + from quafu.simulator import Simulator self.base_sim = Simulator(base_sim, n_qubits, seed=seed) self.adder: ChannelAdderBase = adder @@ -67,7 +67,7 @@ def get_qs(self, ket=False): return self.base_sim.get_qs(ket) def reset(self): - """Reset mindquantum simulator to quantum zero state.""" + """Reset quafu simulator to quantum zero state.""" self.base_sim.reset() def sampling(self, circuit: Circuit, pr: Union[Dict, ParameterResolver] = None, shots: int = 1, seed: int = None): @@ -84,17 +84,17 @@ class NoiseBackend(NoiseBackendImpl): Noise simulator backend based on channel adder. Args: - base_sim (str): The simulator that supported by MindQuantum. + base_sim (str): The simulator that supported by quafu. n_qubits (int): The qubit number of this noise simulator. adder (:class:`~.core.circuit.ChannelAdderBase`): A channel adder that can transform a circuit to noise circuit. seed (int): A random seed. Default: ``None``. - dtype (mindquantum.dtype): The data type of simulator. If ``None``, it will be mindquantum.complex128. + dtype (quafu.dtype): The data type of simulator. If ``None``, it will be quafu.complex128. Default: ``None``. Examples: - >>> from mindquantum.simulator import NoiseBackend, Simulator - >>> from mindquantum.core.circuit import Circuit, MeasureAccepter, MixerAdder, BitFlipAdder + >>> from quafu.simulator import NoiseBackend, Simulator + >>> from quafu.core.circuit import Circuit, MeasureAccepter, MixerAdder, BitFlipAdder >>> circ = Circuit().h(0).x(1, 0).measure_all() >>> circ ┏━━━┓ ┍━━━━━━┑ @@ -114,7 +114,7 @@ class NoiseBackend(NoiseBackendImpl): ┏━┻━┓ ╔════════════╗ ┍━━━━━━┑ q1: ────────┨╺╋╸┠─╢ BFC(p=1/5) ╟─┤ M q1 ├─── ┗━━━┛ ╚════════════╝ ┕━━━━━━┙ - >>> noise_sim = Simulator(NoiseBackend('mqvector', 2, adder=adder)) + >>> noise_sim = Simulator(NoiseBackend('quafuvector', 2, adder=adder)) >>> noise_sim.sampling(circ,seed=42, shots=5000) shots: 5000 Keys: q1 q0│0.00 0.085 0.17 0.255 0.34 0.425 diff --git a/mindquantum/simulator/simulator.py b/quafu/simulator/simulator.py similarity index 86% rename from mindquantum/simulator/simulator.py rename to quafu/simulator/simulator.py index ce43041de..6964e1a82 100644 --- a/mindquantum/simulator/simulator.py +++ b/quafu/simulator/simulator.py @@ -20,19 +20,19 @@ from ..utils.type_value_check import ( _check_input_type, _check_int_type, - _check_mq_type, + _check_quafu_type, _check_seed, _check_value_should_not_less, ) from .available_simulator import SUPPORTED_SIMULATOR from .backend_base import BackendBase -from .mq_blas import MQBlas -from .mqsim import MQSim +from .quafu_blas import QUAFUBlas +from .quafusim import QUAFUSim def get_supported_simulator(): """ - Get simulator name that supported by MindQuantum. + Get simulator name that supported by quafu. Returns: list, The supported simulator list. @@ -50,7 +50,7 @@ class Simulator: n_qubits (int): number of quantum simulator. Default: ``None``. seed (int): the random seed for this simulator, if ``None``, seed will generate by `numpy.random.randint`. Default: ``None``. - dtype (mindquantum.dtype): the data type of simulator. Default: ``None``. + dtype (quafu.dtype): the data type of simulator. Default: ``None``. Raises: TypeError: if `backend` is not str. @@ -61,9 +61,9 @@ class Simulator: ValueError: if `seed` is less than 0 or great than :math:`2^23 - 1`. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 2) + >>> from quafu.algorithm.library import qft + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 2) >>> sim.apply_circuit(qft(range(2))) >>> sim.get_qs() array([0.5+0.j, 0.5+0.j, 0.5+0.j, 0.5+0.j]) @@ -122,14 +122,14 @@ def apply_circuit(self, circuit, pr=None): Examples: >>> import numpy as np - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import H - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 2) + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import H + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 2) >>> sim.apply_circuit(Circuit().un(H, 2)) >>> sim.apply_circuit(Circuit().ry('a', 0).ry('b', 1), np.array([1.1, 2.2])) >>> sim - mqvector simulator with 2 qubits (little endian). + quafuvector simulator with 2 qubits (little endian). Current quantum state: -0.0721702531972066¦00⟩ -0.30090405886869676¦01⟩ @@ -167,9 +167,9 @@ def apply_gate(self, gate, pr=None, diff=False): Examples: >>> import numpy as np - >>> from mindquantum.core.gates import RY, Measure - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 1) + >>> from quafu.core.gates import RY, Measure + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 1) >>> sim.apply_gate(RY('a').on(0), np.pi/2) >>> sim.get_qs() array([0.70710678+0.j, 0.70710678+0.j]) @@ -191,11 +191,11 @@ def apply_hamiltonian(self, hamiltonian: Hamiltonian): hamiltonian (Hamiltonian): the hamiltonian you want to apply. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import QubitOperator, Hamiltonian - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import QubitOperator, Hamiltonian + >>> from quafu.simulator import Simulator >>> import scipy.sparse as sp - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> sim.apply_circuit(Circuit().h(0)) >>> sim.get_qs() array([0.70710678+0.j, 0.70710678+0.j]) @@ -219,13 +219,13 @@ def astype(self, dtype, seed=None): The quantum state will copied from origin simulator. Args: - dtype (mindquantum.dtype): the data type of new simulator. + dtype (quafu.dtype): the data type of new simulator. seed (int): the seed of new simulator. Default: ``None``. """ if seed is None: seed = np.random.randint(1, 2**23) _check_seed(seed) - _check_mq_type(dtype) + _check_quafu_type(dtype) return Simulator(self.backend.astype(dtype, seed=seed), self.n_qubits) def copy(self): @@ -236,14 +236,14 @@ def copy(self): Simulator, a copy version of this simulator. Examples: - >>> from mindquantum.core.gates import RX - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 1) + >>> from quafu.core.gates import RX + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 1) >>> sim.apply_gate(RX(1).on(0)) >>> sim2 = sim.copy() >>> sim2.apply_gate(RX(-1).on(0)) >>> sim2 - mqvector simulator with 1 qubit (little endian). + quafuvector simulator with 1 qubit (little endian). Current quantum state: 1¦0⟩ """ @@ -284,21 +284,21 @@ def get_expectation(self, hamiltonian, circ_right=None, circ_left=None, simulato numbers.Number, the expectation value. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import QubitOperator, Hamiltonian - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 1) + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import QubitOperator, Hamiltonian + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 1) >>> sim.apply_circuit(Circuit().ry(1.2, 0)) >>> ham = Hamiltonian(QubitOperator('Z0')) >>> sim.get_expectation(ham) (0.36235775447667357+0j) >>> sim.get_expectation(ham, Circuit().rx('a', 0), Circuit().ry(2.3, 0), pr={'a': 2.4}) (-0.25463350745693886+0.8507316752782879j) - >>> sim1, sim2 = Simulator('mqvector', 1), Simulator('mqvector', 1) + >>> sim1, sim2 = Simulator('quafuvector', 1), Simulator('quafuvector', 1) >>> sim1.apply_circuit(Circuit().ry(1.2, 0).rx(2.4, 0)) >>> sim2.apply_circuit(Circuit().ry(1.2, 0).ry(2.3, 0)) >>> sim1.apply_hamiltonian(ham) - >>> from mindquantum.simulator import inner_product + >>> from quafu.simulator import inner_product >>> inner_product(sim2, sim1) (-0.25463350745693886+0.8507316752782879j) """ @@ -348,7 +348,7 @@ def get_expectation_with_grad( assumed to be equals to :math:`\left|\psi\right>`. Default: ``None``. parallel_worker (int): The parallel worker numbers. The parallel workers can handle batch in parallel threads. Default: ``None``. - pr_shift (bool): Whether or not to use parameter-shift rule. Only available in "mqvector" simulator. + pr_shift (bool): Whether or not to use parameter-shift rule. Only available in "quafuvector" simulator. It will be enabled automatically when circuit contains noise channel. Noted that not every gate uses the same shift value π/2, so the gradient of FSim gate and parameterized custom gate will be calculated by finite difference method with gap 0.001. Default: ``False``. @@ -358,27 +358,27 @@ def get_expectation_with_grad( Examples: >>> import numpy as np - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.operators import QubitOperator, Hamiltonian - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.operators import QubitOperator, Hamiltonian + >>> from quafu.simulator import Simulator >>> circ = Circuit().ry('a', 0) >>> ham = Hamiltonian(QubitOperator('Z0')) - >>> sim = Simulator('mqvector', 1) + >>> sim = Simulator('quafuvector', 1) >>> grad_ops = sim.get_expectation_with_grad(ham, circ) >>> grad_ops(np.array([1.0])) (array([[0.54030231+0.j]]), array([[[-0.84147098+0.j]]])) - >>> sim1 = Simulator('mqvector', 1) + >>> sim1 = Simulator('quafuvector', 1) >>> prep_circ = Circuit().h(0) >>> ansatz = Circuit().ry('a', 0).rz('b', 0).ry('c', 0) >>> sim1.apply_circuit(prep_circ) - >>> sim2 = Simulator('mqvector', 1) + >>> sim2 = Simulator('quafuvector', 1) >>> ham = Hamiltonian(QubitOperator("")) >>> grad_ops = sim2.get_expectation_with_grad(ham, ansatz, Circuit(), simulator_left=sim1) >>> f, g = grad_ops(np.array([7.902762e-01, 2.139225e-04, 7.795934e-01])) >>> f array([[0.99999989-7.52279618e-05j]]) """ - if self.backend.name == "mqmatrix": + if self.backend.name == "quafumatrix": if circ_left is not None: raise ValueError("Density matrix simulator doesn't support circ_left.") if simulator_left is not None: @@ -404,9 +404,9 @@ def get_qs(self, ket=False): numpy.ndarray, the current quantum state. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 2) + >>> from quafu.algorithm.library import qft + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 2) >>> sim.apply_circuit(qft(range(2))) >>> sim.get_qs() array([0.5+0.j, 0.5+0.j, 0.5+0.j, 0.5+0.j]) @@ -418,9 +418,9 @@ def reset(self): Reset simulator to zero state. Examples: - >>> from mindquantum.algorithm.library import qft - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 2) + >>> from quafu.algorithm.library import qft + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 2) >>> sim.apply_circuit(qft(range(2))) >>> sim.reset() >>> sim.get_qs() @@ -451,14 +451,14 @@ def sampling(self, circuit, pr=None, shots=1, seed=None): MeasureResult, the measure result of sampling. The bit strings in the result are in little-endian order. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.core.gates import Measure - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.core.gates import Measure + >>> from quafu.simulator import Simulator >>> circ = Circuit().ry('a', 0).ry('b', 1) >>> circ += Measure('q0_0').on(0) >>> circ += Measure('q0_1').on(0) >>> circ += Measure('q1').on(1) - >>> sim = Simulator('mqvector', circ.n_qubits) + >>> sim = Simulator('quafuvector', circ.n_qubits) >>> res = sim.sampling(circ, {'a': 1.1, 'b': 2.2}, shots=100, seed=42) >>> res shots: 100 @@ -485,8 +485,8 @@ def set_qs(self, quantum_state): Examples: >>> import numpy as np - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqvector', 1) + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafuvector', 1) >>> sim.get_qs() array([1.+0.j, 0.+0.j]) >>> sim.set_qs(np.array([1, 1])) @@ -515,10 +515,10 @@ def get_partial_trace(self, obj_qubits): numpy.ndarray, the partial trace of current density matrix. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.circuit import Circuit + >>> from quafu.simulator import Simulator >>> circ = Circuit().h(0).x(1, 0) - >>> sim = Simulator('mqmatrix', 2) + >>> sim = Simulator('quafumatrix', 2) >>> sim.apply_circuit(circ) >>> mat = sim.get_partial_trace(0) >>> mat @@ -543,8 +543,8 @@ def entropy(self): numbers.Number, the von Neumann entropy of current quantum state. Examples: - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqmatrix', 1) + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafumatrix', 1) >>> sim.set_qs([[0.5, 0], [0, 0.5]]) >>> sim.entropy() 0.6931471805599453 @@ -567,8 +567,8 @@ def purity(self): numbers.Number, the purity of current quantum state. Examples: - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqmatrix', 1) + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafumatrix', 1) >>> sim.set_qs([[0.5, 0], [0, 0.5]]) >>> sim.purity() 0.5 @@ -593,8 +593,8 @@ def get_pure_state_vector(self): numpy.ndarray, a state vector calculated from current density matrix. Examples: - >>> from mindquantum.simulator import Simulator - >>> sim = Simulator('mqmatrix', 1) + >>> from quafu.simulator import Simulator + >>> sim = Simulator('quafumatrix', 1) >>> sim.set_qs([[0.5, 0.5], [0.5, 0.5]]) >>> sim.get_pure_state_vector() array([0.70710678+0.j, 0.70710678+0.j]) @@ -614,11 +614,11 @@ def inner_product(bra_simulator: Simulator, ket_simulator: Simulator): numbers.Number, the inner product of two quantum state. Examples: - >>> from mindquantum.core.gates import RX, RY - >>> from mindquantum.simulator import inner_product, Simulator - >>> bra_simulator = Simulator('mqvector', 1) + >>> from quafu.core.gates import RX, RY + >>> from quafu.simulator import inner_product, Simulator + >>> bra_simulator = Simulator('quafuvector', 1) >>> bra_simulator.apply_gate(RY(1.2).on(0)) - >>> ket_simulator = Simulator('mqvector', 1) + >>> ket_simulator = Simulator('quafuvector', 1) >>> ket_simulator.apply_gate(RX(2.3).on(0)) >>> inner_product(bra_simulator, ket_simulator) (0.33713923320500694-0.5153852888544989j) @@ -637,8 +637,8 @@ def inner_product(bra_simulator: Simulator, ket_simulator: Simulator): f"Data type of two simulator are different: bra_simulator is {bra_simulator.dtype}, " f"while ket_simulator is {ket_simulator.dtype}." ) - if isinstance(bra_simulator.backend, MQSim): - return MQBlas.inner_product(bra_simulator.backend, ket_simulator.backend) + if isinstance(bra_simulator.backend, QUAFUSim): + return QUAFUBlas.inner_product(bra_simulator.backend, ket_simulator.backend) raise NotImplementedError(f"inner_product for backend {bra_simulator.backend} not implement.") @@ -672,10 +672,10 @@ def fidelity(rho: np.ndarray, sigma: np.ndarray): numbers.Number, the fidelity of two quantum states. Examples: - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.simulator import Simulator, fidelity + >>> from quafu.core.circuit import Circuit + >>> from quafu.simulator import Simulator, fidelity >>> circ = Circuit().h(0).x(1, 0) - >>> sim = Simulator('mqmatrix', 2) + >>> sim = Simulator('quafumatrix', 2) >>> sim.apply_circuit(circ) >>> rho = sim.get_qs() >>> sim.reset() diff --git a/mindquantum/simulator/stabilizer.py b/quafu/simulator/stabilizer.py similarity index 86% rename from mindquantum/simulator/stabilizer.py rename to quafu/simulator/stabilizer.py index 977ffc58a..3b5a4ca61 100644 --- a/mindquantum/simulator/stabilizer.py +++ b/quafu/simulator/stabilizer.py @@ -21,12 +21,12 @@ import numpy as np -from mindquantum import _mq_vector -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import MeasureResult, S, X -from mindquantum.core.operators import Hamiltonian -from mindquantum.simulator.backend_base import BackendBase -from mindquantum.utils.type_value_check import ( +from quafu import _quafu_vector +from quafu.core.circuit import Circuit +from quafu.core.gates import MeasureResult, S, X +from quafu.core.operators import Hamiltonian +from quafu.simulator.backend_base import BackendBase +from quafu.utils.type_value_check import ( _check_input_type, _check_int_type, _check_seed, @@ -34,7 +34,7 @@ ) if TYPE_CHECKING: - from mindquantum.simulator import Simulator + from quafu.simulator import Simulator class Stabilizer(BackendBase): @@ -47,7 +47,7 @@ def __init__(self, name: str, n_qubits, seed=None, *args, **kwargs): self.sim = name self.name = 'stabilizer' else: - self.sim = _mq_vector.stabilizer.StabilizerTableau(n_qubits, seed) + self.sim = _quafu_vector.stabilizer.StabilizerTableau(n_qubits, seed) def __str__(self): """Return a string representation of the object.""" @@ -80,7 +80,7 @@ def copy(self) -> Stabilizer: def __eq__(self, other: Stabilizer) -> bool: """Check whether two stabilizers are equal or not.""" _check_input_type('other', Stabilizer, other) - return _mq_vector.stabilizer.StabilizerTableau.__eq__(self.sim, other.sim) + return _quafu_vector.stabilizer.StabilizerTableau.__eq__(self.sim, other.sim) # pylint: disable=arguments-differ def get_qs(self, *args, **kwargs): @@ -127,9 +127,9 @@ def get_expectation(self, hamiltonian: Hamiltonian, circuit: Circuit) -> float: float: The expectation value of the Hamiltonian. Examples: - >>> from mindquantum.core.operators import QubitOperator, Hamiltonian - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.simulator import Simulator + >>> from quafu.core.operators import QubitOperator, Hamiltonian + >>> from quafu.core.circuit import Circuit + >>> from quafu.simulator import Simulator >>> ham = Hamiltonian(QubitOperator('Z0', 0.5) + QubitOperator('X1', 0.3)) >>> sim = Simulator('stabilizer', 2) >>> sim.get_expectation(ham, Circuit().x(0)) @@ -152,8 +152,8 @@ def decompose_stabilizer(sim: Simulator | Stabilizer) -> Circuit: sim (Simulator): A stabilizer simulator. Examples: - >>> from mindquantum.simulator import Simulator, decompose_stabilizer - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.simulator import Simulator, decompose_stabilizer + >>> from quafu.core.circuit import Circuit >>> stabilizer = Simulator('stabilizer', 2) >>> stabilizer.apply_circuit(Circuit().h(0).x(1, 0)) >>> decompose_stabilizer(stabilizer) @@ -163,14 +163,14 @@ def decompose_stabilizer(sim: Simulator | Stabilizer) -> Circuit: ┏━┻━┓ q1: ────────┨╺╋╸┠─── ┗━━━┛ - >>> from mindquantum.algorithm.error_mitigation import query_single_qubit_clifford_elem + >>> from quafu.algorithm.error_mitigation import query_single_qubit_clifford_elem >>> decompose_stabilizer(query_single_qubit_clifford_elem(10)) ┏━━━┓ ┏━━━┓ ┏━━━━┓ q0: ──┨╺╋╸┠─┨ Z ┠─┨ S† ┠─── ┗━━━┛ ┗━━━┛ ┗━━━━┛ """ # pylint: disable=import-outside-toplevel - from mindquantum.simulator import Simulator + from quafu.simulator import Simulator if isinstance(sim, Simulator): if sim.backend.name != 'stabilizer': @@ -203,8 +203,8 @@ def get_tableau_string(sim: Simulator | Stabilizer) -> str: sim (Simulator): A stabilizer simulator. Examples: - >>> from mindquantum.simulator import Simulator, get_tableau_string - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.simulator import Simulator, get_tableau_string + >>> from quafu.core.circuit import Circuit >>> stabilizer = Simulator('stabilizer', 2) >>> stabilizer.apply_circuit(Circuit().h(0).x(1, 0)) >>> print(get_tableau_string(stabilizer)) @@ -215,7 +215,7 @@ def get_tableau_string(sim: Simulator | Stabilizer) -> str: 0 0 | 1 1 | 0 """ # pylint: disable=import-outside-toplevel - from mindquantum.simulator import Simulator + from quafu.simulator import Simulator if isinstance(sim, Simulator): if sim.backend.name != 'stabilizer': @@ -234,8 +234,8 @@ def get_stabilizer_string(sim: Simulator | Stabilizer) -> str: sim (Simulator): A stabilizer simulator. Examples: - >>> from mindquantum.simulator import Simulator, get_stabilizer_string - >>> from mindquantum.core.circuit import Circuit + >>> from quafu.simulator import Simulator, get_stabilizer_string + >>> from quafu.core.circuit import Circuit >>> stabilizer = Simulator('stabilizer', 2) >>> stabilizer.apply_circuit(Circuit().h(0).x(1, 0)) >>> print(get_stabilizer_string(stabilizer)) @@ -247,7 +247,7 @@ def get_stabilizer_string(sim: Simulator | Stabilizer) -> str: +ZZ """ # pylint: disable=import-outside-toplevel - from mindquantum.simulator import Simulator + from quafu.simulator import Simulator if isinstance(sim, Simulator): if sim.backend.name != 'stabilizer': diff --git a/mindquantum/simulator/utils.py b/quafu/simulator/utils.py similarity index 100% rename from mindquantum/simulator/utils.py rename to quafu/simulator/utils.py diff --git a/mindquantum/third_party/__init__.py b/quafu/third_party/__init__.py similarity index 94% rename from mindquantum/third_party/__init__.py rename to quafu/third_party/__init__.py index 471135905..2f7984f35 100644 --- a/mindquantum/third_party/__init__.py +++ b/quafu/third_party/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -"""Third-party modules for MindQuantum.""" +"""Third-party modules for quafu.""" # Allow extending this namespace. from .unitary_cc import uccsd_singlet_generator, uccsd_singlet_get_packed_amplitudes diff --git a/mindquantum/third_party/interaction_operator.py b/quafu/third_party/interaction_operator.py similarity index 98% rename from mindquantum/third_party/interaction_operator.py rename to quafu/third_party/interaction_operator.py index 87e9d8d32..a96221c21 100644 --- a/mindquantum/third_party/interaction_operator.py +++ b/quafu/third_party/interaction_operator.py @@ -25,7 +25,7 @@ import itertools -from mindquantum.core.operators.polynomial_tensor import PolynomialTensor +from quafu.core.operators.polynomial_tensor import PolynomialTensor class InteractionOperator(PolynomialTensor): diff --git a/mindquantum/third_party/unitary_cc.py b/quafu/third_party/unitary_cc.py similarity index 94% rename from mindquantum/third_party/unitary_cc.py rename to quafu/third_party/unitary_cc.py index 36afc5e64..60057a6ce 100644 --- a/mindquantum/third_party/unitary_cc.py +++ b/quafu/third_party/unitary_cc.py @@ -17,7 +17,7 @@ import numpy -from mindquantum.core.parameterresolver import ParameterResolver +from quafu.core.parameterresolver import ParameterResolver # pylint: disable=too-many-locals @@ -47,7 +47,7 @@ def uccsd_singlet_get_packed_amplitudes(single_amplitudes, double_amplitudes, n_ Examples: >>> import numpy as np - >>> from mindquantum.algorithm.nisq.chem import uccsd_singlet_get_packed_amplitudes + >>> from quafu.algorithm.nisq.chem import uccsd_singlet_get_packed_amplitudes >>> n_qubits, n_electrons = 4, 2 >>> np.random.seed(42) >>> ccsd_single_amps = np.random.random((4, 4)) @@ -57,7 +57,7 @@ def uccsd_singlet_get_packed_amplitudes(single_amplitudes, double_amplitudes, n_ {'d1_0': 0.76162, 's_0': 0.601115}, const: 0 """ # pylint: disable=import-outside-toplevel - from mindquantum.core.operators.utils import down_index, up_index + from quafu.core.operators.utils import down_index, up_index n_spatial_orbitals = n_qubits // 2 n_occupied = int(numpy.ceil(n_electrons / 2)) @@ -129,7 +129,7 @@ def uccsd_singlet_generator(n_qubits, n_electrons, anti_hermitian=True): builds the UCCSD wavefunction. Examples: - >>> from mindquantum.algorithm.nisq.chem import uccsd_singlet_generator + >>> from quafu.algorithm.nisq.chem import uccsd_singlet_generator >>> uccsd_singlet_generator(4, 2) -s_0 [0^ 2] + -d1_0 [0^ 2 1^ 3] + @@ -141,10 +141,10 @@ def uccsd_singlet_generator(n_qubits, n_electrons, anti_hermitian=True): d1_0 [3^ 1 2^ 0] """ # pylint: disable=import-outside-toplevel - from mindquantum.core.operators import ( # pylint: disable=import-outside-toplevel + from quafu.core.operators import ( # pylint: disable=import-outside-toplevel FermionOperator, ) - from mindquantum.core.operators.utils import down_index, up_index + from quafu.core.operators.utils import down_index, up_index if n_qubits % 2 != 0: raise ValueError('The total number of spin-orbitals should be even.') @@ -206,7 +206,7 @@ def uccsd_singlet_generator(n_qubits, n_electrons, anti_hermitian=True): # Generate double excitations coeff = ParameterResolver({f'd2_{i}': 1}) - for (spin_a, spin_b) in itertools.product(range(2), repeat=2): + for spin_a, spin_b in itertools.product(range(2), repeat=2): # Get the functions which map a spatial orbital index to a # spin orbital index index_a = spin_index_functions[spin_a] diff --git a/mindquantum/utils/__init__.py b/quafu/utils/__init__.py similarity index 100% rename from mindquantum/utils/__init__.py rename to quafu/utils/__init__.py diff --git a/mindquantum/utils/error.py b/quafu/utils/error.py similarity index 97% rename from mindquantum/utils/error.py rename to quafu/utils/error.py index e7953444b..72cbc3183 100644 --- a/mindquantum/utils/error.py +++ b/quafu/utils/error.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""MindQuantum custom error exception.""" +"""quafu custom error exception.""" class DeviceNotSupportedError(Exception): diff --git a/mindquantum/utils/f.py b/quafu/utils/f.py similarity index 94% rename from mindquantum/utils/f.py rename to quafu/utils/f.py index 2ddc83c3f..460ce8aa5 100644 --- a/mindquantum/utils/f.py +++ b/quafu/utils/f.py @@ -23,7 +23,7 @@ import numpy as np -from mindquantum.config.config import _GLOBAL_MAT_VALUE +from quafu.config.config import _GLOBAL_MAT_VALUE from .type_value_check import ( _check_gate_type, @@ -35,7 +35,7 @@ ) if TYPE_CHECKING: - from mindquantum.core import BasicGate, Circuit + from quafu.core import BasicGate, Circuit __all__ = ['random_circuit', 'random_insert_gates', 'mod', 'normalize', 'random_state', 'random_hamiltonian'] @@ -52,8 +52,8 @@ def random_clifford_circuit(n_qubits: int, gate_num: int, seed: int = None) -> C Examples: >>> import numpy as np - >>> from mindquantum.utils import random_clifford_circuit - >>> from mindquantum.simulator import Simulator, decompose_stabilizer + >>> from quafu.utils import random_clifford_circuit + >>> from quafu.simulator import Simulator, decompose_stabilizer >>> rand_clifford = random_clifford_circuit(10, 100, 42) >>> sim = Simulator('stabilizer', rand_clifford.n_qubits) >>> sim.apply_circuit(rand_clifford) @@ -100,7 +100,7 @@ def random_circuit(n_qubits, gate_num, sd_rate=0.5, ctrl_rate=0.2, seed=None): seed (int): Random seed to generate random circuit. Examples: - >>> from mindquantum.utils import random_circuit + >>> from quafu.utils import random_circuit >>> random_circuit(3, 4, 0.5, 0.5, 100) ┏━━━┓ ┏━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━┓ q1: ──┨ Z ┠─┨ RX(0.9437) ┠───────■───────┨ RX(-0.8582) ┠─── @@ -194,9 +194,9 @@ def random_insert_gates( A generator that can generate quantum circuits. Examples: - >>> from mindquantum.core.gates import X, Z, BitFlipChannel, PhaseFlipChannel - >>> from mindquantum.core.circuit import Circuit - >>> from mindquantum.utils import random_insert_gates + >>> from quafu.core.gates import X, Z, BitFlipChannel, PhaseFlipChannel + >>> from quafu.core.circuit import Circuit + >>> from quafu.utils import random_insert_gates >>> origin = Circuit().rx('theta', 0).rz('beta', 1, 0).barrier().measure(0) >>> print(origin) ┏━━━━━━━━━━━┓ ┍━━━━━━┑ @@ -292,7 +292,7 @@ def random_hamiltonian(n_qubits: int, n_terms: int, seed: int = None, dtype=None n_qubits (int): Number of qubits n_terms (int): Number of Pauli terms seed (int, optional): Random seed. Defaults to None. - dtype (mindquantum.dtype): data type of hamiltonian. Default: ``None``. + dtype (quafu.dtype): data type of hamiltonian. Default: ``None``. Returns: Hamiltonian, Randomly generated Hamiltonian @@ -303,7 +303,7 @@ def random_hamiltonian(n_qubits: int, n_terms: int, seed: int = None, dtype=None -0.5018 [Z0] + 1.8029 [X0 X1] + 0.928 [Y0 X1 Y2] + 0.3946 [Z2 X3] - 1.3759 [Z1 Y3] """ import random - from mindquantum.core.operators import QubitOperator, Hamiltonian + from quafu.core.operators import QubitOperator, Hamiltonian _check_int_type('n_qubits', n_qubits) _check_int_type('n_terms', n_terms) @@ -348,7 +348,7 @@ def mod(vec_in, axis=0): numpy.ndarray, The mod of input vector. Examples: - >>> from mindquantum.utils import mod + >>> from quafu.utils import mod >>> vec_in = np.array([[1, 2, 3], [4, 5, 6]]) >>> mod(vec_in) array([[4.12310563, 5.38516481, 6.70820393]]) @@ -374,7 +374,7 @@ def normalize(vec_in, axis=0): numpy.ndarray, Vector after normalization. Examples: - >>> from mindquantum.utils import normalize + >>> from quafu.utils import normalize >>> vec_in = np.array([[1, 2, 3], [4, 5, 6]]) >>> normalize(vec_in) array([[0.24253563, 0.37139068, 0.4472136 ], @@ -404,7 +404,7 @@ def random_state(shapes, norm_axis=0, comp=True, seed=None): numpy.ndarray, A normalized random quantum state. Examples: - >>> from mindquantum.utils import random_state + >>> from quafu.utils import random_state >>> random_state((2, 2), seed=42) array([[0.44644744+0.18597239j, 0.66614846+0.10930256j], [0.87252821+0.06923499j, 0.41946926+0.60691409j]]) @@ -438,11 +438,11 @@ def is_two_number_close(a, b, atol=None): # pylint: disable=invalid-name bool, whether this two number close to each other. Examples: - >>> from mindquantum.utils import is_two_number_close + >>> from quafu.utils import is_two_number_close >>> is_two_number_close(1+1j, 1+1j) True """ - from mindquantum.config.config import ( # pylint: disable=import-outside-toplevel + from quafu.config.config import ( # pylint: disable=import-outside-toplevel context, ) diff --git a/mindquantum/utils/fdopen.py b/quafu/utils/fdopen.py similarity index 100% rename from mindquantum/utils/fdopen.py rename to quafu/utils/fdopen.py diff --git a/mindquantum/utils/progress.py b/quafu/utils/progress.py similarity index 97% rename from mindquantum/utils/progress.py rename to quafu/utils/progress.py index a94a71fd2..d695a64e7 100644 --- a/mindquantum/utils/progress.py +++ b/quafu/utils/progress.py @@ -36,7 +36,7 @@ class TwoLoopsProgress(Progress): Examples: >>> import time - >>> from mindquantum.utils import TwoLoopsProgress + >>> from quafu.utils import TwoLoopsProgress >>> with TwoLoopsProgress(3, 100) as progress: >>> for ep in range(3): >>> for batch in range(100): @@ -102,7 +102,7 @@ class SingleLoopProgress(Progress): Examples: >>> import time - >>> from mindquantum.utils import SingleLoopProgress + >>> from quafu.utils import SingleLoopProgress >>> with SingleLoopProgress(100) as progress: >>> for batch in range(100): >>> progress.update_loop(batch) diff --git a/mindquantum/utils/quantifiers.py b/quafu/utils/quantifiers.py similarity index 100% rename from mindquantum/utils/quantifiers.py rename to quafu/utils/quantifiers.py diff --git a/mindquantum/utils/show_info.py b/quafu/utils/show_info.py similarity index 100% rename from mindquantum/utils/show_info.py rename to quafu/utils/show_info.py diff --git a/mindquantum/utils/string_utils.py b/quafu/utils/string_utils.py similarity index 98% rename from mindquantum/utils/string_utils.py rename to quafu/utils/string_utils.py index 3dd43717a..0d5adbea1 100644 --- a/mindquantum/utils/string_utils.py +++ b/quafu/utils/string_utils.py @@ -105,7 +105,7 @@ def ket_string(state, tol=1e-7): Examples: >>> import numpy as np - >>> from mindquantum.utils import ket_string + >>> from quafu.utils import ket_string >>> state = np.array([1, -1j])/np.sqrt(2) >>> print(ket_string(state)) ['√2/2¦0⟩', '-√2/2j¦1⟩'] diff --git a/mindquantum/utils/type_value_check.py b/quafu/utils/type_value_check.py similarity index 96% rename from mindquantum/utils/type_value_check.py rename to quafu/utils/type_value_check.py index 903466478..bb703d9a8 100644 --- a/mindquantum/utils/type_value_check.py +++ b/quafu/utils/type_value_check.py @@ -51,7 +51,7 @@ def _check_ansatz(data, ansatz_params_size): def _check_hamiltonian_qubits_number(hamiltonian, sim_qubits): """Check hamiltonian qubits number.""" # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.core.operators.hamiltonian import HowTo # noqa: E402 + from quafu.core.operators.hamiltonian import HowTo # noqa: E402 if hamiltonian.how_to != HowTo.ORIGIN: if hamiltonian.n_qubits != sim_qubits: @@ -184,12 +184,12 @@ def _require_package(pkg_name: str, low_version: str = None, high_version: str = raise ImportError(f"Requires {pkg_name}, please install with 'pip install {pkg_name}'") -def _check_mq_type(dtype): +def _check_quafu_type(dtype): # pylint: disable=import-outside-toplevel,cyclic-import - from mindquantum.dtype.dtype import mq_number_type + from quafu.dtype.dtype import quafu_number_type - if dtype not in mq_number_type: - raise ValueError(f"dtype only support {mq_number_type}, but get {dtype}") + if dtype not in quafu_number_type: + raise ValueError(f"dtype only support {quafu_number_type}, but get {dtype}") def _check_numba_validation(): diff --git a/mindquantum_config/__init__.py b/quafu_config/__init__.py similarity index 76% rename from mindquantum_config/__init__.py rename to quafu_config/__init__.py index 6adc360b1..0acc1fe60 100644 --- a/mindquantum_config/__init__.py +++ b/quafu_config/__init__.py @@ -11,7 +11,7 @@ # 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. -"""Console entry point to access MindQuantum installation variables.""" +"""Console entry point to access quafu installation variables.""" import argparse import sys @@ -31,14 +31,14 @@ def print_includes(): """Print a list of include directories using the -I syntax.""" dirs = [ - _ROOT / 'mindquantum' / 'include' / 'mindquantum', + _ROOT / 'quafu' / 'include' / 'quafu', _ROOT / 'ccsrc' / 'include', _ROOT / 'ccsrc' / 'python' / 'core' / 'include', - _ROOT / 'ccsrc' / 'python' / 'mqbackend' / 'include', + _ROOT / 'ccsrc' / 'python' / 'quafubackend' / 'include', _ROOT / 'ccsrc' / 'python' / 'simulator' / 'include', ] - root = _ROOT / 'mindquantum' / 'lib' / 'mindquantum' / 'third_party' + root = _ROOT / 'quafu' / 'lib' / 'quafu' / 'third_party' if root.exists(): for folder in root.iterdir(): if (folder / 'include').exists(): @@ -46,7 +46,7 @@ def print_includes(): else: dirs.append(folder) - root = _ROOT / 'build' / '.mqlibs' + root = _ROOT / 'build' / '.quafulibs' if root.exists(): for folder in root.iterdir(): dirs.append(folder / 'include') @@ -64,7 +64,7 @@ def print_includes(): def get_cmake_dir(as_string=True): """ - Return the path to the MindQuantum CMake module directory. + Return the path to the quafu CMake module directory. Args: as_string (bool): (optional) If true, returned value is a string, else a pathlib.Path object. @@ -76,7 +76,7 @@ def get_dir(folder): return str(folder) return folder - cmake_installed_path = Path(_ROOT, 'mindquantum', 'share', 'mindquantum', 'cmake') + cmake_installed_path = Path(_ROOT, 'quafu', 'share', 'quafu', 'cmake') if cmake_installed_path.exists(): return get_dir(cmake_installed_path) @@ -84,32 +84,32 @@ def get_dir(folder): if build_dir.exists(): return get_dir(build_dir) - raise ImportError('MindQuantum not installed, installation required to access the CMake files') + raise ImportError('quafu not installed, installation required to access the CMake files') # ============================================================================== def print_bin_dir(): - """Print the bin directory of MindQuantum.""" - bin_path = Path(_ROOT, "mindquantum", "bin") + """Print the bin directory of quafu.""" + bin_path = Path(_ROOT, "quafu", "bin") if bin_path.exists(): print(str(bin_path)) return - raise ImportError("MindQuantum not installed.") + raise ImportError("quafu not installed.") # ============================================================================== def print_abi(): - """Print the bin directory of MindQuantum.""" + """Print the bin directory of quafu.""" try: - from mindquantum import mqbackend # pylint: disable=import-outside-toplevel + from quafu import quafubackend # pylint: disable=import-outside-toplevel - print(mqbackend.c.build_abi()) # pylint: disable=no-member + print(quafubackend.c.build_abi()) # pylint: disable=no-member except ImportError as exc: - raise ImportError("MindQuantum not installed.") from exc + raise ImportError("quafu not installed.") from exc # ============================================================================== @@ -125,9 +125,9 @@ def print_temp_dir(): def print_version(): - """Print MindQuantum's version.""" + """Print quafu's version.""" try: - print(importlib_metadata.version('mindquantum')) + print(importlib_metadata.version('quafu')) except importlib_metadata.PackageNotFoundError: with (_ROOT / 'VERSION.txt').open() as fd: print([line.strip() for line in fd.readlines() if line][0]) @@ -143,15 +143,12 @@ def main(): group.add_argument( "--cmakedir", action="store_true", - help=( - "Print the CMake module directory, ideal for setting either -Dmindquantum_ROOT or-Dmindquantum_DIR in " - "CMake." - ), + help=("Print the CMake module directory, ideal for setting either -Dquafu_ROOT or-Dquafu_DIR in " "CMake."), ) group.add_argument( "--includes", action="store_true", - help="Include flags for MindQuantum", + help="Include flags for quafu", ) group.add_argument( "--tempdir", @@ -161,17 +158,17 @@ def main(): group.add_argument( "--version", action="store_true", - help="Print out MindQuantum's version", + help="Print out quafu's version", ) group.add_argument( "--bin", action="store_true", - help="Print bin directory of MindQuantum", + help="Print bin directory of quafu", ) group.add_argument( "--abi", action="store_true", - help="Print abi of MindQuantum backend", + help="Print abi of quafu backend", ) args = parser.parse_args() if not sys.argv[1:]: diff --git a/mindquantum_config/__main__.py b/quafu_config/__main__.py similarity index 91% rename from mindquantum_config/__main__.py rename to quafu_config/__main__.py index 28de25246..2f2aefa72 100644 --- a/mindquantum_config/__main__.py +++ b/quafu_config/__main__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Console entry point to access MindQuantum installation variables.""" +"""Console entry point to access quafu installation variables.""" from . import main diff --git a/scripts/generate_vscode_snippets.py b/scripts/generate_vscode_snippets.py index 1a8b2bd99..579ab9353 100644 --- a/scripts/generate_vscode_snippets.py +++ b/scripts/generate_vscode_snippets.py @@ -17,8 +17,8 @@ import json import os -from mindquantum.io.display.circuit_text_drawer_helper import removesuffix -from mindquantum.utils import fdopen +from quafu.io.display.circuit_text_drawer_helper import removesuffix +from quafu.utils import fdopen def api_snippets(directory, snippets): @@ -29,10 +29,8 @@ def api_snippets(directory, snippets): rel_path = os.path.relpath( # pylint: disable=replace-os-relpath-abspath # noqa: SCS100 file_path, directory ) - en_url = removesuffix(f"https://www.mindspore.cn/mindquantum/docs/en/master/{rel_path}", ".rst") + ".html" - cn_url = ( - removesuffix(f"https://www.mindspore.cn/mindquantum/docs/zh-CN/master/{rel_path}", ".rst") + ".html" - ) + en_url = removesuffix(f"https://www.mindspore.cn/quafu/docs/en/master/{rel_path}", ".rst") + ".html" + cn_url = removesuffix(f"https://www.mindspore.cn/quafu/docs/zh-CN/master/{rel_path}", ".rst") + ".html" api_name = en_url.split('/')[-1].split('.')[-2] snippets[f'en {api_name}'] = { "prefix": f"url_en_{api_name}", @@ -52,7 +50,7 @@ def api_snippets(directory, snippets): SNIPPETS_DIR = os.path.realpath(SNIPPETS_DIR) DIRECTORY_PATH = os.path.realpath(DIRECTORY_PATH) -snippets_path = os.path.join(SNIPPETS_DIR, 'mindquantum_snippets.code-snippets') +snippets_path = os.path.join(SNIPPETS_DIR, 'quafu_snippets.code-snippets') api_snippets(DIRECTORY_PATH, snippets_json) with fdopen(snippets_path, 'w') as f_write: diff --git a/setup.py b/setup.py index 1b881a9e0..fd75ac442 100644 --- a/setup.py +++ b/setup.py @@ -119,7 +119,7 @@ class CMakeBuildExt(build_ext): # pylint: disable=too-many-instance-attributes user_options = build_ext.user_options + [ ('build-dir=', None, 'Specify a location for the build directory'), ('clean-build', None, 'Build in a clean build environment'), - ('install-light', None, 'Install a "light" version of MindQuantum (ie. no development libraries)'), + ('install-light', None, 'Install a "light" version of quafu (ie. no development libraries)'), ('jobs=', None, 'Number of concurrent jobs for sub-build processes'), ('no-arch-native', None, 'Do not use the -march=native flag when compiling'), ] @@ -141,8 +141,8 @@ def finalize_options(self): # pylint: disable=attribute-defined-outside-init self.build_dir = self.build_dir or None self.clean_build = self.clean_build or False - self.fast_bdist_wheel = bool(int(os.getenv('MQ_FAST_BDIST_WHEEL', '0'))) - self.fast_bdist_wheel_dir = os.getenv('MQ_FAST_BDIST_DIR', None) + self.fast_bdist_wheel = bool(int(os.getenv('QUAFU_FAST_BDIST_WHEEL', '0'))) + self.fast_bdist_wheel_dir = os.getenv('QUAFU_FAST_BDIST_DIR', None) self.install_light = self.install_light or False self.jobs = self.jobs or multiprocessing.cpu_count() self.no_arch_native = self.no_arch_native or False @@ -196,8 +196,8 @@ def _src_dir_pred(ext): pkg_name = self.distribution.get_name() if pkg_name == 'UNKNOWN': - warnings.warn('Unable to determine package name automatically... defaulting to `mindquantum`') - pkg_name = 'mindquantum' + warnings.warn('Unable to determine package name automatically... defaulting to `quafu`') + pkg_name = 'quafu' cmake_args = [ '-DPython_EXECUTABLE:FILEPATH=' + python_exec, @@ -205,7 +205,7 @@ def _src_dir_pred(ext): '-DIN_PLACE_BUILD:BOOL=OFF', '-DIS_PYTHON_BUILD:BOOL=ON', f'-DVERSION_INFO="{self.distribution.get_version()}"', - f'-DMQ_PYTHON_PACKAGE_NAME:STRING={pkg_name}', + f'-DQUAFU_PYTHON_PACKAGE_NAME:STRING={pkg_name}', # NB: make sure that the install path is absolute! f'-DCMAKE_INSTALL_PREFIX:FILEPATH={Path(self.build_lib, Path().resolve().name).resolve()}', ] @@ -419,7 +419,7 @@ def run(self): """Run the bdist_wheel command.""" if self.fast_build: logging.info('doing a fast-build') - with modified_environ(MQ_FAST_BDIST_WHEEL=True, MQ_FAST_BDIST_DIR=self.fast_build_dir): + with modified_environ(QUAFU_FAST_BDIST_WHEEL=True, QUAFU_FAST_BDIST_DIR=self.fast_build_dir): super().run() else: super().run() @@ -499,12 +499,12 @@ def run(self): # ============================================================================== ext_modules = [ - CMakeExtension(pymod='mindquantum.mqbackend'), - CMakeExtension(pymod='mindquantum._mq_vector'), - CMakeExtension(pymod='mindquantum._mq_vector_gpu', optional=True), - CMakeExtension(pymod='mindquantum._mq_matrix'), - CMakeExtension(pymod='mindquantum._math'), - CMakeExtension(pymod='mindquantum._qaia_sb', optional=True), + CMakeExtension(pymod='quafu.quafubackend'), + CMakeExtension(pymod='quafu._quafu_vector'), + CMakeExtension(pymod='quafu._quafu_vector_gpu', optional=True), + CMakeExtension(pymod='quafu._quafu_matrix'), + CMakeExtension(pymod='quafu._math'), + CMakeExtension(pymod='quafu._qaia_sb', optional=True), ] @@ -568,7 +568,7 @@ def __call__(self, parser, namespace, values, option_string=None): arg_parser.add_argument('-G', dest='cmake_generator', action=ArgsCMakeFlag) if 'bdist_wheel' in sys.argv: - sys.argv.extend(arg.strip() for arg in os.environ.get('MQ_CIBW_BUILD_ARGS', '').split(',') if arg) + sys.argv.extend(arg.strip() for arg in os.environ.get('QUAFU_CIBW_BUILD_ARGS', '').split(',') if arg) parsed_args, unparsed_args = arg_parser.parse_known_args() sys.argv = sys.argv[:1] + unparsed_args diff --git a/tests/quick_test.py b/tests/quick_test.py index 2b78c0600..313aae552 100644 --- a/tests/quick_test.py +++ b/tests/quick_test.py @@ -18,9 +18,9 @@ import numpy as np -from mindquantum.core import RX, RY, Hamiltonian, QubitOperator, X -from mindquantum.engine import circuit_generator -from mindquantum.simulator import Simulator +from quafu.core import RX, RY, Hamiltonian, QubitOperator, X +from quafu.engine import circuit_generator +from quafu.simulator import Simulator @circuit_generator(2) @@ -45,7 +45,7 @@ def ansatz(qubits): ansatz_names = ['p1', 'p2'] total_circuit = encoder.as_encoder() + ansatz.as_ansatz() -sim = Simulator('mqvector', total_circuit.n_qubits) +sim = Simulator('quafuvector', total_circuit.n_qubits) grad_ops = sim.get_expectation_with_grad(ham, total_circuit) encoder_data = np.array([[0.1, 0.2]]) ansatz_data = np.array([0.3, 0.4]) diff --git a/tests/st/__init__.py b/tests/st/__init__.py index fc102a95b..76a469e21 100644 --- a/tests/st/__init__.py +++ b/tests/st/__init__.py @@ -13,4 +13,4 @@ # limitations under the License. # ============================================================================ -"""MindQuantum st test module.""" +"""quafu st test module.""" diff --git a/tests/st/conftest.py b/tests/st/conftest.py index a95e5f09d..b2f048173 100644 --- a/tests/st/conftest.py +++ b/tests/st/conftest.py @@ -16,11 +16,11 @@ import os -from mindquantum import logging +from quafu import logging # pylint: disable=no-member -level = os.getenv('MQ_LOG', logging.LogLevel.INFO) +level = os.getenv('QUAFU_LOG', logging.LogLevel.INFO) if isinstance(level, str): level = getattr(logging.LogLevel, level) logging.enable(level) diff --git a/tests/st/test_algorithm/test_bp.py b/tests/st/test_algorithm/test_bp.py index 7667a7fed..8fa4ec310 100644 --- a/tests/st/test_algorithm/test_bp.py +++ b/tests/st/test_algorithm/test_bp.py @@ -16,12 +16,12 @@ import numpy as np import pytest -from mindquantum.algorithm.nisq import ansatz_variance -from mindquantum.algorithm.nisq.chem import HardwareEfficientAnsatz -from mindquantum.core.gates import RY, RZ, Z -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.simulator import Simulator -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.algorithm.nisq import ansatz_variance +from quafu.algorithm.nisq.chem import HardwareEfficientAnsatz +from quafu.core.gates import RY, RZ, Z +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.simulator import Simulator +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR @pytest.mark.level0 @@ -33,7 +33,7 @@ def test_barren_plateau(config): Expectation: success """ simulator, dtype = config - if simulator != 'mqvector': + if simulator != 'quafuvector': return np.random.seed(42) ham = Hamiltonian(QubitOperator('Z0 Z1'), dtype=dtype) diff --git a/tests/st/test_algorithm/test_compiler/test_dag/test_dag.py b/tests/st/test_algorithm/test_compiler/test_dag/test_dag.py index 60fa85200..3a61fb05f 100644 --- a/tests/st/test_algorithm/test_compiler/test_dag/test_dag.py +++ b/tests/st/test_algorithm/test_compiler/test_dag/test_dag.py @@ -15,9 +15,9 @@ '''test DAG circuit''' import pytest -from mindquantum.algorithm.compiler.dag import DAGCircuit -from mindquantum.algorithm.compiler.decompose.utils import is_equiv_unitary -from mindquantum.utils import random_circuit +from quafu.algorithm.compiler.dag import DAGCircuit +from quafu.algorithm.compiler.decompose.utils import is_equiv_unitary +from quafu.utils import random_circuit @pytest.mark.level0 diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_h_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_h_decompose.py index 32ef5f374..47cc81dd1 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_h_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_h_decompose.py @@ -24,9 +24,9 @@ with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=UserWarning, message='MindSpore not installed.*') warnings.simplefilter('ignore', category=DeprecationWarning) - from mindquantum.algorithm.compiler.decompose import ch_decompose - from mindquantum.core.circuit import Circuit - from mindquantum.core.gates import H + from quafu.algorithm.compiler.decompose import ch_decompose + from quafu.core.circuit import Circuit + from quafu.core.gates import H def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rx_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rx_decompose.py index b454296f8..a48bcd03c 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rx_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rx_decompose.py @@ -16,9 +16,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import crx_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import RX +from quafu.algorithm.compiler.decompose import crx_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import RX def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rxx_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rxx_decompose.py index 746d7a19d..9e37e880f 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rxx_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rxx_decompose.py @@ -18,9 +18,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import crxx_decompose, rxx_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import Rxx +from quafu.algorithm.compiler.decompose import crxx_decompose, rxx_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import Rxx def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ry_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ry_decompose.py index 74f4000a5..85492ce5f 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ry_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ry_decompose.py @@ -16,9 +16,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import cry_decompose, cnry_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import RY +from quafu.algorithm.compiler.decompose import cry_decompose, cnry_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import RY def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ryy_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ryy_decompose.py index 3c0eb236a..2bcc21d17 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ryy_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_ryy_decompose.py @@ -17,9 +17,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import cryy_decompose, ryy_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import Ryy +from quafu.algorithm.compiler.decompose import cryy_decompose, ryy_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import Ryy def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rz_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rz_decompose.py index 4fc353b8c..c71f98f8b 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rz_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rz_decompose.py @@ -15,9 +15,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import crz_decompose, cnrz_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import RZ +from quafu.algorithm.compiler.decompose import crz_decompose, cnrz_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import RZ def circuit_equal_test(gate, decompose_circ): @@ -39,6 +39,7 @@ def test_crz(): for solution in crz_decompose(crz): circuit_equal_test(crz, solution) + @pytest.mark.level0 @pytest.mark.platform_x86_cpu def test_cnrz(): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rzz_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rzz_decompose.py index edfde56cd..d445ce648 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rzz_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_rzz_decompose.py @@ -18,9 +18,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import rzz_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import Rzz +from quafu.algorithm.compiler.decompose import rzz_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import Rzz def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_s_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_s_decompose.py index 8f87a2786..4098d8f41 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_s_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_s_decompose.py @@ -18,9 +18,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import cs_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import S +from quafu.algorithm.compiler.decompose import cs_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import S def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_swap_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_swap_decompose.py index 46e251796..dde76a944 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_swap_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_swap_decompose.py @@ -15,9 +15,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import cswap_decompose, swap_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import SWAP +from quafu.algorithm.compiler.decompose import cswap_decompose, swap_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import SWAP def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_t_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_t_decompose.py index 8b1db7cb9..4fa9c6b97 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_t_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_t_decompose.py @@ -18,9 +18,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import ct_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import T +from quafu.algorithm.compiler.decompose import ct_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import T def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_x_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_x_decompose.py index 80a0d0df5..3cd7fb1f9 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_x_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_x_decompose.py @@ -23,9 +23,9 @@ warnings.filterwarnings( 'ignore', category=DeprecationWarning, message=r'Please use `OptimizeResult` from the `scipy\.optimize`' ) - from mindquantum.algorithm.compiler.decompose import ccx_decompose - from mindquantum.core.circuit import Circuit - from mindquantum.core.gates import X + from quafu.algorithm.compiler.decompose import ccx_decompose + from quafu.core.circuit import Circuit + from quafu.core.gates import X def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_y_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_y_decompose.py index a5f202813..0a9e20c59 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_y_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_y_decompose.py @@ -18,9 +18,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import cy_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import Y +from quafu.algorithm.compiler.decompose import cy_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import Y def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_z_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_z_decompose.py index 2f84503c3..da8712ba1 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_z_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_fixed_decompose/test_z_decompose.py @@ -18,9 +18,9 @@ import numpy as np import pytest -from mindquantum.algorithm.compiler.decompose import cz_decompose -from mindquantum.core.circuit import Circuit -from mindquantum.core.gates import Z +from quafu.algorithm.compiler.decompose import cz_decompose +from quafu.core.circuit import Circuit +from quafu.core.gates import Z def circuit_equal_test(gate, decompose_circ): diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_basic_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_basic_decompose.py index 5351439f0..3453737bf 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_basic_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_basic_decompose.py @@ -20,9 +20,9 @@ import pytest from scipy.stats import unitary_group -from mindquantum.algorithm.compiler import decompose -from mindquantum.core import gates -from mindquantum.core.circuit import Circuit +from quafu.algorithm.compiler import decompose +from quafu.core import gates +from quafu.core.circuit import Circuit rand_unitary = unitary_group.rvs diff --git a/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_qs_decompose.py b/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_qs_decompose.py index 0bc22b395..b3170e67d 100644 --- a/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_qs_decompose.py +++ b/tests/st/test_algorithm/test_compiler/test_decompose/test_universal_decompose/test_qs_decompose.py @@ -17,9 +17,9 @@ import pytest from scipy.stats import unitary_group -from mindquantum.algorithm.compiler import decompose -from mindquantum.algorithm.compiler.decompose import utils -from mindquantum.core import gates +from quafu.algorithm.compiler import decompose +from quafu.algorithm.compiler.decompose import utils +from quafu.core import gates rand_unitary = unitary_group.rvs diff --git a/tests/st/test_algorithm/test_compiler/test_rules/test_rules.py b/tests/st/test_algorithm/test_compiler/test_rules/test_rules.py index b8170df2c..7b8fd1a16 100644 --- a/tests/st/test_algorithm/test_compiler/test_rules/test_rules.py +++ b/tests/st/test_algorithm/test_compiler/test_rules/test_rules.py @@ -15,7 +15,7 @@ '''test compiler rules''' import pytest -from mindquantum.algorithm.compiler import ( +from quafu.algorithm.compiler import ( BasicDecompose, SequentialCompiler, KroneckerSeqCompiler, @@ -26,8 +26,8 @@ CZBasedChipCompiler, DAGCircuit, ) -from mindquantum.algorithm.compiler.decompose.utils import is_equiv_unitary -from mindquantum.utils import random_circuit +from quafu.algorithm.compiler.decompose.utils import is_equiv_unitary +from quafu.utils import random_circuit @pytest.mark.level0 diff --git a/tests/st/test_algorithm/test_error_mitigation/test_folding.py b/tests/st/test_algorithm/test_error_mitigation/test_folding.py index 7acf1ed56..66e887bb7 100644 --- a/tests/st/test_algorithm/test_error_mitigation/test_folding.py +++ b/tests/st/test_algorithm/test_error_mitigation/test_folding.py @@ -15,8 +15,8 @@ """Test folding circuit.""" import numpy as np -from mindquantum.algorithm.error_mitigation import fold_at_random -from mindquantum.utils import random_circuit +from quafu.algorithm.error_mitigation import fold_at_random +from quafu.utils import random_circuit def test_folding_circuit(): diff --git a/tests/st/test_algorithm/test_error_mitigation/test_random_benchmarking.py b/tests/st/test_algorithm/test_error_mitigation/test_random_benchmarking.py index 4514a5747..e204b71b3 100644 --- a/tests/st/test_algorithm/test_error_mitigation/test_random_benchmarking.py +++ b/tests/st/test_algorithm/test_error_mitigation/test_random_benchmarking.py @@ -16,7 +16,7 @@ import numpy as np import pytest -from mindquantum.algorithm.error_mitigation import ( +from quafu.algorithm.error_mitigation import ( generate_double_qubits_rb_circ, generate_single_qubit_rb_circ, ) diff --git a/tests/st/test_algorithm/test_error_mitigation/test_virtual_distillation.py b/tests/st/test_algorithm/test_error_mitigation/test_virtual_distillation.py index ba94195b4..9ca785ed4 100644 --- a/tests/st/test_algorithm/test_error_mitigation/test_virtual_distillation.py +++ b/tests/st/test_algorithm/test_error_mitigation/test_virtual_distillation.py @@ -16,10 +16,10 @@ import numpy as np -from mindquantum.algorithm.error_mitigation import virtual_distillation -from mindquantum.simulator import Simulator -from mindquantum.utils import random_circuit -from mindquantum import Hamiltonian, QubitOperator +from quafu.algorithm.error_mitigation import virtual_distillation +from quafu.simulator import Simulator +from quafu.utils import random_circuit +from quafu import Hamiltonian, QubitOperator def test_virtual_distillation(): @@ -31,12 +31,12 @@ def test_virtual_distillation(): circ = random_circuit(4, 100) def executor(test_circ): - sim = Simulator("mqvector", 2 * circ.n_qubits) + sim = Simulator("quafuvector", 2 * circ.n_qubits) res_dict = sim.sampling(test_circ, shots=1000000).data return res_dict result = virtual_distillation(circ, executor) - sim2 = Simulator("mqvector", 4) + sim2 = Simulator("quafuvector", 4) hams = [Hamiltonian(QubitOperator(f"Z{i}")) for i in range(4)] exp = [] for i in range(4): diff --git a/tests/st/test_algorithm/test_error_mitigation/test_zne.py b/tests/st/test_algorithm/test_error_mitigation/test_zne.py index 57709baed..b7f00ae10 100644 --- a/tests/st/test_algorithm/test_error_mitigation/test_zne.py +++ b/tests/st/test_algorithm/test_error_mitigation/test_zne.py @@ -16,18 +16,18 @@ import numpy as np -from mindquantum.algorithm.error_mitigation import zne -from mindquantum.core.circuit import Circuit -from mindquantum.core.circuit.channel_adder import BitFlipAdder -from mindquantum.core.gates import RX, RY, RZ -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.simulator import Simulator -from mindquantum.simulator.noise import NoiseBackend +from quafu.algorithm.error_mitigation import zne +from quafu.core.circuit import Circuit +from quafu.core.circuit.channel_adder import BitFlipAdder +from quafu.core.gates import RX, RY, RZ +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.simulator import Simulator +from quafu.simulator.noise import NoiseBackend def execute(circ: Circuit, noise_level: float, ham: Hamiltonian, seed=42): """Simulator executor.""" - return Simulator(NoiseBackend('mqmatrix', circ.n_qubits, BitFlipAdder(noise_level), seed=seed)).get_expectation( + return Simulator(NoiseBackend('quafumatrix', circ.n_qubits, BitFlipAdder(noise_level), seed=seed)).get_expectation( ham, circ ) diff --git a/tests/st/test_algorithm/test_library/test_amplitude_encoder.py b/tests/st/test_algorithm/test_library/test_amplitude_encoder.py index 00a79ee60..198a00370 100644 --- a/tests/st/test_algorithm/test_library/test_amplitude_encoder.py +++ b/tests/st/test_algorithm/test_library/test_amplitude_encoder.py @@ -19,7 +19,7 @@ import numpy as np import pytest -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=UserWarning, message='MindSpore not installed.*') @@ -27,8 +27,8 @@ 'ignore', category=DeprecationWarning, message=r'Please use `OptimizeResult` from the `scipy\.optimize`' ) - from mindquantum.algorithm.library import amplitude_encoder - from mindquantum.simulator import Simulator + from quafu.algorithm.library import amplitude_encoder + from quafu.simulator import Simulator AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -50,7 +50,7 @@ def test_amplitude_encoder(config): circuit, params = amplitude_encoder([0.5, 0.5, 0.5, 0.5], 3) sim.apply_circuit(circuit, params) state = sim.get_qs(False) - if backend == "mqmatrix": + if backend == "quafumatrix": assert abs(state[0][0].real - 0.25) < 1e-6 assert abs(state[1][1].real - 0.25) < 1e-6 assert abs(state[2][2].real - 0.25) < 1e-6 @@ -64,7 +64,7 @@ def test_amplitude_encoder(config): sim.reset() sim.apply_circuit(circuit, params) state = sim.get_qs(False) - if backend == "mqmatrix": + if backend == "quafumatrix": assert abs(state[2][2].real - 0.25) < 1e-6 assert abs(state[3][3].real - 0.25) < 1e-6 assert abs(state[4][4].real - 0.25) < 1e-6 @@ -78,7 +78,7 @@ def test_amplitude_encoder(config): sim.reset() sim.apply_circuit(circuit, params) state = sim.get_qs(False) - if backend == "mqmatrix": + if backend == "quafumatrix": assert abs(state[0][0].real - 0.25) < 1e-6 assert abs(state[1][1].real - 0.25) < 1e-6 assert abs(state[2][2].real - 0.25) < 1e-6 @@ -94,7 +94,7 @@ def test_amplitude_encoder(config): sim.reset() sim.apply_circuit(circuit, params) state = sim.get_qs(False) - if backend == "mqmatrix": + if backend == "quafumatrix": assert abs(state[0][0].real - 0.25) < 1e-6 assert abs(state[1][1].real - 0.25) < 1e-6 assert abs(state[2][2].real - 0.25) < 1e-6 diff --git a/tests/st/test_algorithm/test_library/test_bitphaseflip_operator.py b/tests/st/test_algorithm/test_library/test_bitphaseflip_operator.py index 2942ea30f..c97a84bcc 100644 --- a/tests/st/test_algorithm/test_library/test_bitphaseflip_operator.py +++ b/tests/st/test_algorithm/test_library/test_bitphaseflip_operator.py @@ -17,16 +17,16 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum import UN, H -from mindquantum.algorithm.library import bitphaseflip_operator -from mindquantum.core.circuit import Circuit +import quafu +from quafu import UN, H +from quafu.algorithm.library import bitphaseflip_operator +from quafu.core.circuit import Circuit @pytest.mark.level0 @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_bitphaseflip_operator(dtype): """ Description: Test bitphaseflip_operator diff --git a/tests/st/test_algorithm/test_library/test_ghz_state.py b/tests/st/test_algorithm/test_library/test_ghz_state.py index 421945c8a..8b84b2b94 100644 --- a/tests/st/test_algorithm/test_library/test_ghz_state.py +++ b/tests/st/test_algorithm/test_library/test_ghz_state.py @@ -17,13 +17,13 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum.algorithm.library import general_ghz_state +import quafu +from quafu.algorithm.library import general_ghz_state @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_general_ghz_state(dtype): """ Description: Test if three qubit general_ghz_state correct or not. diff --git a/tests/st/test_algorithm/test_library/test_qjpeg.py b/tests/st/test_algorithm/test_library/test_qjpeg.py index 967b7fb36..782a887b3 100644 --- a/tests/st/test_algorithm/test_library/test_qjpeg.py +++ b/tests/st/test_algorithm/test_library/test_qjpeg.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.simulator import Simulator -from mindquantum.utils import normalize -from mindquantum.algorithm.library import qjpeg +from quafu.simulator import Simulator +from quafu.utils import normalize +from quafu.algorithm.library import qjpeg def test_qjpeg(): @@ -32,16 +32,12 @@ def test_qjpeg(): assert remainder_qubits == [0, 2] assert discard_qubits == [1, 3] - data = np.array([[1, 0, 0, 0], - [1, 1, 0, 0], - [1, 1, 1, 0], - [1, 1, 1, 1]]) + data = np.array([[1, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 1]]) state = normalize(data.reshape(-1)) - sim = Simulator('mqmatrix', n_qubits) + sim = Simulator('quafumatrix', n_qubits) sim.set_qs(state) sim.apply_circuit(circ) rho = sim.get_partial_trace(discard_qubits) sub_probs = rho.diagonal().real new_data = sub_probs.reshape((2 ** (m_qubits // 2), -1)) - assert np.allclose(new_data, np.array([[0.3, 0.0], - [0.4, 0.3]])) + assert np.allclose(new_data, np.array([[0.3, 0.0], [0.4, 0.3]])) diff --git a/tests/st/test_algorithm/test_library/test_qudit_mapping.py b/tests/st/test_algorithm/test_library/test_qudit_mapping.py index 29cfe3296..719a15f41 100644 --- a/tests/st/test_algorithm/test_library/test_qudit_mapping.py +++ b/tests/st/test_algorithm/test_library/test_qudit_mapping.py @@ -18,11 +18,224 @@ import pytest import numpy as np from numpy.linalg import norm -from mindquantum.algorithm.library import qudit_mapping -from mindquantum.core.circuit import Circuit -qudit_original = {3: np.array([0.26570339 + 0.42469573j, 0.67444848 + 0.11068155j, 0.51928555 + 0.11066444j]), 4: np.array([0.03199561 + 0.01133906j, 0.47713693 + 0.5342791j, 0.33112684 + 0.45855468j, 0.39004489 + 0.11696793j]), 5: np.array([0.15829351 + 0.2535388j, 0.15966864 + 0.53266802j, 0.26486777 + 0.12144082j, 0.45684342 + 0.25433583j, 0.37604349 + 0.31894797j])} # pylint: disable=line-too-long -qubit_original = {3: np.array([0.26570339 + 0.42469573j, 0.47690709 + 0.07826368j, 0.47690709 + 0.07826368j, 0.51928555 + 0.11066444j]), 4: np.array([0.03199561 + 0.01133906j, 0.27547514 + 0.30846618j, 0.27547514 + 0.30846618j, 0.19117617 + 0.26474667j, 0.27547514 + 0.30846618j, 0.19117617 + 0.26474667j, 0.19117617 + 0.26474667j, 0.39004489 + 0.11696793j]), 5: np.array([0.15829351 + 0.2535388j, 0.07983432 + 0.26633401j, 0.07983432 + 0.26633401j, 0.10813182 + 0.04957801j, 0.07983432 + 0.26633401j, 0.10813182 + 0.04957801j, 0.10813182 + 0.04957801j, 0.22842171 + 0.12716791j, 0.07983432 + 0.26633401j, 0.10813182 + 0.04957801j, 0.10813182 + 0.04957801j, 0.22842171 + 0.12716791j, 0.10813182 + 0.04957801j, 0.22842171 + 0.12716791j, 0.22842171 + 0.12716791j, 0.37604349 + 0.31894797j])} # pylint: disable=line-too-long -index_original = {'d3n1': {0: [0], 1: [1, 2], 2: [3]}, 'd4n1': {0: [0], 1: [1, 2, 4], 2: [3, 5, 6], 3: [7]}, 'd5n1': {0: [0], 1: [1, 2, 4, 8], 2: [3, 5, 6, 9, 10, 12], 3: [7, 11, 13, 14], 4: [15]}, 'd3n2': {0: [0], 1: [1, 2], 2: [3], 3: [4, 8], 4: [5, 6, 9, 10], 5: [7, 11], 6: [12], 7: [13, 14], 8: [15]}, 'd4n2': {0: [0], 1: [1, 2, 4], 2: [3, 5, 6], 3: [7], 4: [8, 16, 32], 5: [9, 10, 12, 17, 18, 20, 33, 34, 36], 6: [11, 13, 14, 19, 21, 22, 35, 37, 38], 7: [15, 23, 39], 8: [24, 40, 48], 9: [25, 26, 28, 41, 42, 44, 49, 50, 52], 10: [27, 29, 30, 43, 45, 46, 51, 53, 54], 11: [31, 47, 55], 12: [56], 13: [57, 58, 60], 14: [59, 61, 62], 15: [63]}, 'd5n2': {0: [0], 1: [1, 2, 4, 8], 2: [3, 5, 6, 9, 10, 12], 3: [7, 11, 13, 14], 4: [15], 5: [16, 32, 64, 128], 6: [17, 18, 20, 24, 33, 34, 36, 40, 65, 66, 68, 72, 129, 130, 132, 136], 7: [19, 21, 22, 25, 26, 28, 35, 37, 38, 41, 42, 44, 67, 69, 70, 73, 74, 76, 131, 133, 134, 137, 138, 140], 8: [23, 27, 29, 30, 39, 43, 45, 46, 71, 75, 77, 78, 135, 139, 141, 142], 9: [31, 47, 79, 143], 10: [48, 80, 96, 144, 160, 192], 11: [49, 50, 52, 56, 81, 82, 84, 88, 97, 98, 100, 104, 145, 146, 148, 152, 161, 162, 164, 168, 193, 194, 196, 200], 12: [51, 53, 54, 57, 58, 60, 83, 85, 86, 89, 90, 92, 99, 101, 102, 105, 106, 108, 147, 149, 150, 153, 154, 156, 163, 165, 166, 169, 170, 172, 195, 197, 198, 201, 202, 204], 13: [55, 59, 61, 62, 87, 91, 93, 94, 103, 107, 109, 110, 151, 155, 157, 158, 167, 171, 173, 174, 199, 203, 205, 206], 14: [63, 95, 111, 159, 175, 207], 15: [112, 176, 208, 224], 16: [113, 114, 116, 120, 177, 178, 180, 184, 209, 210, 212, 216, 225, 226, 228, 232], 17: [115, 117, 118, 121, 122, 124, 179, 181, 182, 185, 186, 188, 211, 213, 214, 217, 218, 220, 227, 229, 230, 233, 234, 236], 18: [119, 123, 125, 126, 183, 187, 189, 190, 215, 219, 221, 222, 231, 235, 237, 238], 19: [127, 191, 223, 239], 20: [240], 21: [241, 242, 244, 248], 22: [243, 245, 246, 249, 250, 252], 23: [247, 251, 253, 254], 24: [255]}} # pylint: disable=line-too-long +from quafu.algorithm.library import qudit_mapping +from quafu.core.circuit import Circuit + +qudit_original = { + 3: np.array([0.26570339 + 0.42469573j, 0.67444848 + 0.11068155j, 0.51928555 + 0.11066444j]), + 4: np.array( + [0.03199561 + 0.01133906j, 0.47713693 + 0.5342791j, 0.33112684 + 0.45855468j, 0.39004489 + 0.11696793j] + ), + 5: np.array( + [ + 0.15829351 + 0.2535388j, + 0.15966864 + 0.53266802j, + 0.26486777 + 0.12144082j, + 0.45684342 + 0.25433583j, + 0.37604349 + 0.31894797j, + ] + ), +} # pylint: disable=line-too-long +qubit_original = { + 3: np.array( + [0.26570339 + 0.42469573j, 0.47690709 + 0.07826368j, 0.47690709 + 0.07826368j, 0.51928555 + 0.11066444j] + ), + 4: np.array( + [ + 0.03199561 + 0.01133906j, + 0.27547514 + 0.30846618j, + 0.27547514 + 0.30846618j, + 0.19117617 + 0.26474667j, + 0.27547514 + 0.30846618j, + 0.19117617 + 0.26474667j, + 0.19117617 + 0.26474667j, + 0.39004489 + 0.11696793j, + ] + ), + 5: np.array( + [ + 0.15829351 + 0.2535388j, + 0.07983432 + 0.26633401j, + 0.07983432 + 0.26633401j, + 0.10813182 + 0.04957801j, + 0.07983432 + 0.26633401j, + 0.10813182 + 0.04957801j, + 0.10813182 + 0.04957801j, + 0.22842171 + 0.12716791j, + 0.07983432 + 0.26633401j, + 0.10813182 + 0.04957801j, + 0.10813182 + 0.04957801j, + 0.22842171 + 0.12716791j, + 0.10813182 + 0.04957801j, + 0.22842171 + 0.12716791j, + 0.22842171 + 0.12716791j, + 0.37604349 + 0.31894797j, + ] + ), +} # pylint: disable=line-too-long +index_original = { + 'd3n1': {0: [0], 1: [1, 2], 2: [3]}, + 'd4n1': {0: [0], 1: [1, 2, 4], 2: [3, 5, 6], 3: [7]}, + 'd5n1': {0: [0], 1: [1, 2, 4, 8], 2: [3, 5, 6, 9, 10, 12], 3: [7, 11, 13, 14], 4: [15]}, + 'd3n2': {0: [0], 1: [1, 2], 2: [3], 3: [4, 8], 4: [5, 6, 9, 10], 5: [7, 11], 6: [12], 7: [13, 14], 8: [15]}, + 'd4n2': { + 0: [0], + 1: [1, 2, 4], + 2: [3, 5, 6], + 3: [7], + 4: [8, 16, 32], + 5: [9, 10, 12, 17, 18, 20, 33, 34, 36], + 6: [11, 13, 14, 19, 21, 22, 35, 37, 38], + 7: [15, 23, 39], + 8: [24, 40, 48], + 9: [25, 26, 28, 41, 42, 44, 49, 50, 52], + 10: [27, 29, 30, 43, 45, 46, 51, 53, 54], + 11: [31, 47, 55], + 12: [56], + 13: [57, 58, 60], + 14: [59, 61, 62], + 15: [63], + }, + 'd5n2': { + 0: [0], + 1: [1, 2, 4, 8], + 2: [3, 5, 6, 9, 10, 12], + 3: [7, 11, 13, 14], + 4: [15], + 5: [16, 32, 64, 128], + 6: [17, 18, 20, 24, 33, 34, 36, 40, 65, 66, 68, 72, 129, 130, 132, 136], + 7: [19, 21, 22, 25, 26, 28, 35, 37, 38, 41, 42, 44, 67, 69, 70, 73, 74, 76, 131, 133, 134, 137, 138, 140], + 8: [23, 27, 29, 30, 39, 43, 45, 46, 71, 75, 77, 78, 135, 139, 141, 142], + 9: [31, 47, 79, 143], + 10: [48, 80, 96, 144, 160, 192], + 11: [ + 49, + 50, + 52, + 56, + 81, + 82, + 84, + 88, + 97, + 98, + 100, + 104, + 145, + 146, + 148, + 152, + 161, + 162, + 164, + 168, + 193, + 194, + 196, + 200, + ], + 12: [ + 51, + 53, + 54, + 57, + 58, + 60, + 83, + 85, + 86, + 89, + 90, + 92, + 99, + 101, + 102, + 105, + 106, + 108, + 147, + 149, + 150, + 153, + 154, + 156, + 163, + 165, + 166, + 169, + 170, + 172, + 195, + 197, + 198, + 201, + 202, + 204, + ], + 13: [ + 55, + 59, + 61, + 62, + 87, + 91, + 93, + 94, + 103, + 107, + 109, + 110, + 151, + 155, + 157, + 158, + 167, + 171, + 173, + 174, + 199, + 203, + 205, + 206, + ], + 14: [63, 95, 111, 159, 175, 207], + 15: [112, 176, 208, 224], + 16: [113, 114, 116, 120, 177, 178, 180, 184, 209, 210, 212, 216, 225, 226, 228, 232], + 17: [ + 115, + 117, + 118, + 121, + 122, + 124, + 179, + 181, + 182, + 185, + 186, + 188, + 211, + 213, + 214, + 217, + 218, + 220, + 227, + 229, + 230, + 233, + 234, + 236, + ], + 18: [119, 123, 125, 126, 183, 187, 189, 190, 215, 219, 221, 222, 231, 235, 237, 238], + 19: [127, 191, 223, 239], + 20: [240], + 21: [241, 242, 244, 248], + 22: [243, 245, 246, 249, 250, 252], + 23: [247, 251, 253, 254], + 24: [255], + }, +} # pylint: disable=line-too-long def random_qudits(dim: int, n_qudits: int) -> np.ndarray: @@ -41,7 +254,11 @@ def test_symmetric_state_index(): Description: test arbitrary symmetric state index. Expectation: success. """ - index_test = {f'd{dim}n{n_qudits}': qudit_mapping._symmetric_state_index(dim, n_qudits) for n_qudits in [1, 2] for dim in [3, 4, 5]} # pylint: disable=line-too-long,protected-access + index_test = { + f'd{dim}n{n_qudits}': qudit_mapping._symmetric_state_index(dim, n_qudits) + for n_qudits in [1, 2] + for dim in [3, 4, 5] + } # pylint: disable=line-too-long,protected-access assert index_test == index_original @@ -72,6 +289,7 @@ def test_qudit_symmetric_encoding(): qubit_test = qudit_mapping.qudit_symmetric_encoding(random_qudits(dim, 1)) assert np.allclose(qubit_test, qubit_original[dim]) + @pytest.mark.level0 @pytest.mark.platform_x86_cpu def test_mat_to_op(): @@ -147,7 +365,7 @@ def test_qutrit_symmetric_ansatz(): Description: Test qutrit_symmetric_ansatz function Expectation: success """ - from mindquantum.core.gates import UnivMathGate + from quafu.core.gates import UnivMathGate # Create a simple symmetric 4x4 unitary matrix mat = np.array([[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]) / np.sqrt(2) diff --git a/tests/st/test_algorithm/test_library/test_w_state.py b/tests/st/test_algorithm/test_library/test_w_state.py index 381c5a4ce..0b0fafe49 100644 --- a/tests/st/test_algorithm/test_library/test_w_state.py +++ b/tests/st/test_algorithm/test_library/test_w_state.py @@ -17,13 +17,13 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum.algorithm.library import general_w_state +import quafu +from quafu.algorithm.library import general_w_state @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_general_w_state(dtype): """ Description: Test general_w_state diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_hardware_efficient.py b/tests/st/test_algorithm/test_nisq/test_chem/test_hardware_efficient.py index 61b6e39b2..514bed339 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_hardware_efficient.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_hardware_efficient.py @@ -25,12 +25,12 @@ try: import mindspore as ms - from mindquantum.algorithm.nisq import HardwareEfficientAnsatz - from mindquantum.core.gates import RX, RY, X - from mindquantum.core.operators import Hamiltonian, QubitOperator - from mindquantum.framework import MQAnsatzOnlyLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.algorithm.nisq import HardwareEfficientAnsatz + from quafu.core.gates import RX, RY, X + from quafu.core.operators import Hamiltonian, QubitOperator + from quafu.framework import QUAFUAnsatzOnlyLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) ms.context.set_context(mode=ms.context.PYNATIVE_MODE, device_target="CPU") @@ -63,7 +63,7 @@ def test_hardware_efficient(config): ham = QubitOperator('Z0 Z1 Z2').astype(dtype) sim = Simulator(backend, hea.circuit.n_qubits, dtype=dtype) f_g_ops = sim.get_expectation_with_grad(Hamiltonian(ham), hea.circuit) - net = MQAnsatzOnlyLayer(f_g_ops, 'one') + net = QUAFUAnsatzOnlyLayer(f_g_ops, 'one') opti = ms.nn.Adam(net.trainable_params(), learning_rate=4e-1) train_net = ms.nn.TrainOneStepCell(net, opti) for _ in range(100): diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_qubit_ucc.py b/tests/st/test_algorithm/test_nisq/test_chem/test_qubit_ucc.py index fa5ab9b21..27a9ee88d 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_qubit_ucc.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_qubit_ucc.py @@ -25,13 +25,13 @@ try: import mindspore as ms - from mindquantum.algorithm.nisq import QubitUCCAnsatz - from mindquantum.core.circuit import Circuit - from mindquantum.core.gates import X - from mindquantum.core.operators import Hamiltonian, QubitOperator - from mindquantum.framework import MQAnsatzOnlyLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.algorithm.nisq import QubitUCCAnsatz + from quafu.core.circuit import Circuit + from quafu.core.gates import X + from quafu.core.operators import Hamiltonian, QubitOperator + from quafu.framework import QUAFUAnsatzOnlyLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) ms.context.set_context(mode=ms.context.PYNATIVE_MODE, device_target="CPU") @@ -90,7 +90,7 @@ def test_quccsd(config): # pylint: disable=too-many-locals sim = Simulator(backend, total_circuit.n_qubits, dtype=dtype) f_g_ops = sim.get_expectation_with_grad(Hamiltonian(ham.real.astype(dtype)), total_circuit) - net = MQAnsatzOnlyLayer(f_g_ops) + net = QUAFUAnsatzOnlyLayer(f_g_ops) opti = ms.nn.Adagrad(net.trainable_params(), learning_rate=4e-2) train_net = ms.nn.TrainOneStepCell(net, opti) for i in range(100): diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_quccsd.py b/tests/st/test_algorithm/test_nisq/test_chem/test_quccsd.py index a8ed14366..cd8d67115 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_quccsd.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_quccsd.py @@ -18,10 +18,10 @@ import pytest -from mindquantum.algorithm.nisq import quccsd_generator -from mindquantum.core.operators import TimeEvolution, count_qubits -from mindquantum.core.operators._term_value import TermValue -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.algorithm.nisq import quccsd_generator +from quafu.core.operators import TimeEvolution, count_qubits +from quafu.core.operators._term_value import TermValue +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_transforms.py b/tests/st/test_algorithm/test_nisq/test_chem/test_transforms.py index a2ddea94b..cce193739 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_transforms.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_transforms.py @@ -16,9 +16,9 @@ """ import pytest -import mindquantum as mq -from mindquantum.algorithm.nisq import Transform -from mindquantum.core.operators import FermionOperator +import quafu +from quafu.algorithm.nisq import Transform +from quafu.core.operators import FermionOperator def _get_terms_as_set(qubit_op): @@ -27,7 +27,7 @@ def _get_terms_as_set(qubit_op): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_transform_jordan_wigner(dtype): """ Description: Test transform @@ -41,7 +41,7 @@ def test_transform_jordan_wigner(dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_transform_parity(dtype): """ Description: Test transform @@ -56,7 +56,7 @@ def test_transform_parity(dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_transform_bravyi_kitaev(dtype): """ Description: Test transform @@ -70,7 +70,7 @@ def test_transform_bravyi_kitaev(dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_transform_ternary_tree(dtype): """ Description: Test transform diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_ucc.py b/tests/st/test_algorithm/test_nisq/test_chem/test_ucc.py index acb2895a4..f499e6f6b 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_ucc.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_ucc.py @@ -27,13 +27,13 @@ try: import mindspore as ms - from mindquantum.algorithm.nisq import UCCAnsatz - from mindquantum.core.circuit import Circuit - from mindquantum.core.gates import X - from mindquantum.core.operators import Hamiltonian, QubitOperator - from mindquantum.framework import MQAnsatzOnlyLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.algorithm.nisq import UCCAnsatz + from quafu.core.circuit import Circuit + from quafu.core.gates import X + from quafu.core.operators import Hamiltonian, QubitOperator + from quafu.framework import QUAFUAnsatzOnlyLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -89,7 +89,7 @@ def test_uccsd(config): # pylint: disable=too-many-locals total_circuit += ucc.circuit sim = Simulator(backend, total_circuit.n_qubits, dtype=dtype) f_g_ops = sim.get_expectation_with_grad(Hamiltonian(ham.real.astype(dtype)), total_circuit) - net = MQAnsatzOnlyLayer(f_g_ops) + net = QUAFUAnsatzOnlyLayer(f_g_ops) opti = ms.nn.Adagrad(net.trainable_params(), learning_rate=4e-2) train_net = ms.nn.TrainOneStepCell(net, opti) for i in range(50): diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd.py b/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd.py index 6dc665cef..0650d171a 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd.py @@ -20,8 +20,8 @@ import numpy as np import pytest -from mindquantum.algorithm.nisq import generate_uccsd -from mindquantum.core import gates as G +from quafu.algorithm.nisq import generate_uccsd +from quafu.core import gates as G _HAS_OPENFERMION = True try: diff --git a/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd0.py b/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd0.py index 1ad89b1aa..c63f3087d 100644 --- a/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd0.py +++ b/tests/st/test_algorithm/test_nisq/test_chem/test_uccsd0.py @@ -18,9 +18,9 @@ import pytest -from mindquantum.algorithm.nisq import Transform, uccsd0_singlet_generator -from mindquantum.algorithm.nisq.chem.uccsd0 import spin_adapted_t1, spin_adapted_t2 -from mindquantum.core.operators import TimeEvolution, count_qubits +from quafu.algorithm.nisq import Transform, uccsd0_singlet_generator +from quafu.algorithm.nisq.chem.uccsd0 import spin_adapted_t1, spin_adapted_t2 +from quafu.core.operators import TimeEvolution, count_qubits @pytest.mark.level0 diff --git a/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_2_sat.py b/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_2_sat.py index 4bb3a77d9..25ef57b22 100644 --- a/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_2_sat.py +++ b/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_2_sat.py @@ -22,11 +22,11 @@ try: import mindspore as ms - from mindquantum.algorithm.nisq import Max2SATAnsatz - from mindquantum.core.operators import Hamiltonian - from mindquantum.framework import MQAnsatzOnlyLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.algorithm.nisq import Max2SATAnsatz + from quafu.core.operators import Hamiltonian + from quafu.framework import QUAFUAnsatzOnlyLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -58,7 +58,7 @@ def test_max_2_sat(config): ham = max2sat.hamiltonian.astype(dtype) f_g_ops = sim.get_expectation_with_grad(Hamiltonian(ham), max2sat.circuit) ms.set_seed(42) - net = MQAnsatzOnlyLayer(f_g_ops) + net = QUAFUAnsatzOnlyLayer(f_g_ops) opt = ms.nn.Adagrad(net.trainable_params(), learning_rate=4e-1) train_net = ms.nn.TrainOneStepCell(net, opt) ret = 0 diff --git a/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_cut.py b/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_cut.py index fead8e6f9..6a365598f 100644 --- a/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_cut.py +++ b/tests/st/test_algorithm/test_nisq/test_qaoa/test_max_cut.py @@ -23,11 +23,11 @@ try: import mindspore as ms - from mindquantum.algorithm.nisq import MaxCutAnsatz - from mindquantum.core.operators import Hamiltonian - from mindquantum.framework import MQAnsatzOnlyLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.algorithm.nisq import MaxCutAnsatz + from quafu.core.operators import Hamiltonian + from quafu.framework import QUAFUAnsatzOnlyLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) ms.context.set_context(mode=ms.context.PYNATIVE_MODE, device_target="CPU") @@ -58,7 +58,7 @@ def test_max_cut(config): ham = maxcut.hamiltonian f_g_ops = sim.get_expectation_with_grad(Hamiltonian(-ham, dtype=dtype), maxcut.circuit) ms.set_seed(42) - net = MQAnsatzOnlyLayer(f_g_ops) + net = QUAFUAnsatzOnlyLayer(f_g_ops) opti = ms.nn.Adagrad(net.trainable_params(), learning_rate=4e-1) train_net = ms.nn.TrainOneStepCell(net, opti) for _ in range(50): diff --git a/tests/st/test_algorithm/test_nisq/test_qnn/test_arxiv_ansatz.py b/tests/st/test_algorithm/test_nisq/test_qnn/test_arxiv_ansatz.py index 3a859cdaa..20fb0fe51 100644 --- a/tests/st/test_algorithm/test_nisq/test_qnn/test_arxiv_ansatz.py +++ b/tests/st/test_algorithm/test_nisq/test_qnn/test_arxiv_ansatz.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Test mindquantum provide arxiv ansatz.""" +"""Test quafu provide arxiv ansatz.""" -from mindquantum.algorithm import nisq -import mindquantum.core.gates as G -from mindquantum.core.circuit import Circuit +from quafu.algorithm import nisq +import quafu.core.gates as G +from quafu.core.circuit import Circuit import numpy as np import pytest @@ -210,7 +210,7 @@ def test_ansatz7(): test_cir += G.RZ(f'p{i+qubits+pr_count}').on(i) pr_count += qubits * 2 test_cir += G.BARRIER - for i in range(qubits)[1:qubits - 1:2]: + for i in range(qubits)[1 : qubits - 1 : 2]: test_cir += G.RZ(f'p{pr_count}').on(i, i + 1) pr_count += 1 test_matrix = test_cir.matrix(pr) @@ -245,7 +245,7 @@ def test_ansatz8(): test_cir += G.RZ(f'p{i+qubits+pr_count}').on(i) pr_count += qubits * 2 test_cir += G.BARRIER - for i in range(qubits)[1:qubits - 1:2]: + for i in range(qubits)[1 : qubits - 1 : 2]: test_cir += G.RX(f'p{pr_count}').on(i, i + 1) pr_count += 1 test_matrix = test_cir.matrix(pr) @@ -269,7 +269,7 @@ def test_ansatz9(): for i in range(qubits): test_cir += G.H.on(i) test_cir += G.BARRIER - for i in range(qubits)[qubits - 2::-1]: + for i in range(qubits)[qubits - 2 :: -1]: test_cir += G.Z.on(i, i + 1) test_cir += G.BARRIER for i in range(qubits): @@ -295,7 +295,7 @@ def test_ansatz10(): for i in range(qubits): test_cir += G.RY(f'p{i}').on(i) test_cir += G.BARRIER - for i in range(qubits)[qubits - 1::-1]: + for i in range(qubits)[qubits - 1 :: -1]: if i == 0: test_cir += G.Z.on(i, qubits - 1) else: @@ -325,14 +325,14 @@ def test_ansatz11(): test_cir += G.RY(f'p{i}').on(i) test_cir += G.RZ(f'p{i+qubits}').on(i) test_cir += G.BARRIER - for i in range(qubits)[:qubits - (qubits % 2):2]: + for i in range(qubits)[: qubits - (qubits % 2) : 2]: test_cir += G.X.on(i, i + 1) test_cir += G.BARRIER for i in range(qubits)[1:-1]: test_cir += G.RY(f'p{i+2*qubits-1}').on(i) test_cir += G.RZ(f'p{i+(3*qubits-2)-1}').on(i) test_cir += G.BARRIER - for i in range(qubits)[1:qubits - (qubits % 2) - 1:2]: + for i in range(qubits)[1 : qubits - (qubits % 2) - 1 : 2]: test_cir += G.X.on(i, i + 1) test_matrix = test_cir.matrix(pr) @@ -356,14 +356,14 @@ def test_ansatz12(): test_cir += G.RY(f'p{i}').on(i) test_cir += G.RZ(f'p{i+qubits}').on(i) test_cir += G.BARRIER - for i in range(qubits)[:qubits - (qubits % 2):2]: + for i in range(qubits)[: qubits - (qubits % 2) : 2]: test_cir += G.Z.on(i, i + 1) test_cir += G.BARRIER for i in range(qubits)[1:-1]: test_cir += G.RY(f'p{i+2*qubits-1}').on(i) test_cir += G.RZ(f'p{i+(3*qubits-2)-1}').on(i) test_cir += G.BARRIER - for i in range(qubits)[1:qubits - (qubits % 2) - 1:2]: + for i in range(qubits)[1 : qubits - (qubits % 2) - 1 : 2]: test_cir += G.Z.on(i, i + 1) test_matrix = test_cir.matrix(pr) @@ -482,10 +482,10 @@ def test_ansatz16(): test_cir += G.RZ(f'p{i+qubits}').on(i) test_cir += G.BARRIER pr_count = 2 * qubits - for i in range(qubits)[:qubits - (qubits % 2):2]: + for i in range(qubits)[: qubits - (qubits % 2) : 2]: test_cir += G.RZ(f'p{pr_count}').on(i, i + 1) pr_count += 1 - for i in range(qubits)[1:qubits - (qubits % 2) - 1:2]: + for i in range(qubits)[1 : qubits - (qubits % 2) - 1 : 2]: test_cir += G.RZ(f'p{pr_count}').on(i, i + 1) pr_count += 1 test_matrix = test_cir.matrix(pr) @@ -511,10 +511,10 @@ def test_ansatz17(): test_cir += G.RZ(f'p{i+qubits}').on(i) test_cir += G.BARRIER pr_count = 2 * qubits - for i in range(qubits)[:qubits - (qubits % 2):2]: + for i in range(qubits)[: qubits - (qubits % 2) : 2]: test_cir += G.RX(f'p{pr_count}').on(i, i + 1) pr_count += 1 - for i in range(qubits)[1:qubits - (qubits % 2) - 1:2]: + for i in range(qubits)[1 : qubits - (qubits % 2) - 1 : 2]: test_cir += G.RX(f'p{pr_count}').on(i, i + 1) pr_count += 1 test_matrix = test_cir.matrix(pr) diff --git a/tests/st/test_algorithm/test_nisq/test_qnn/test_hardware_efficient_ansatz.py b/tests/st/test_algorithm/test_nisq/test_qnn/test_hardware_efficient_ansatz.py index 37131b69b..54c38152d 100644 --- a/tests/st/test_algorithm/test_nisq/test_qnn/test_hardware_efficient_ansatz.py +++ b/tests/st/test_algorithm/test_nisq/test_qnn/test_hardware_efficient_ansatz.py @@ -16,9 +16,9 @@ import numpy as np -from mindquantum.algorithm import nisq -from mindquantum.core.circuit import Circuit -from mindquantum.core.parameterresolver import PRGenerator +from quafu.algorithm import nisq +from quafu.core.circuit import Circuit +from quafu.core.parameterresolver import PRGenerator def test_ry_linear(): diff --git a/tests/st/test_algorithm/test_nisq/test_qnn/test_iqp_encoding.py b/tests/st/test_algorithm/test_nisq/test_qnn/test_iqp_encoding.py index d261efc8d..9e1bafba7 100644 --- a/tests/st/test_algorithm/test_nisq/test_qnn/test_iqp_encoding.py +++ b/tests/st/test_algorithm/test_nisq/test_qnn/test_iqp_encoding.py @@ -17,15 +17,15 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum.algorithm.nisq import IQPEncoding +import quafu +from quafu.algorithm.nisq import IQPEncoding @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_general_iqp_encoding(dtype): """ Description: Test general_iqp_encoding diff --git a/tests/st/test_algorithm/test_nisq/test_qnn/test_quantum_neuron.py b/tests/st/test_algorithm/test_nisq/test_qnn/test_quantum_neuron.py index bbe3144bd..9b2c63a0c 100644 --- a/tests/st/test_algorithm/test_nisq/test_qnn/test_quantum_neuron.py +++ b/tests/st/test_algorithm/test_nisq/test_qnn/test_quantum_neuron.py @@ -14,9 +14,9 @@ # ============================================================================ """Test quantum neuron""" -from mindquantum.simulator import Simulator -from mindquantum.algorithm import QuantumNeuron -from mindquantum import Circuit, H +from quafu.simulator import Simulator +from quafu.algorithm import QuantumNeuron +from quafu import Circuit, H import numpy as np import pytest @@ -36,7 +36,7 @@ def test_quantum_neuron(): circ += H.on(1) # Initialize simulator - sim = Simulator('mqvector', 4, seed=2) + sim = Simulator('quafuvector', 4, seed=2) sim.apply_circuit(circ) # Create quantum neuron diff --git a/tests/st/test_algorithm/test_nisq/test_qnn/test_strongly_entangling.py b/tests/st/test_algorithm/test_nisq/test_qnn/test_strongly_entangling.py index c6943e8fa..9c48bb087 100644 --- a/tests/st/test_algorithm/test_nisq/test_qnn/test_strongly_entangling.py +++ b/tests/st/test_algorithm/test_nisq/test_qnn/test_strongly_entangling.py @@ -16,16 +16,16 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum.algorithm.nisq import StronglyEntangling -from mindquantum.core.gates import X +import quafu +from quafu.algorithm.nisq import StronglyEntangling +from quafu.core.gates import X @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) def test_strongly_entangling_ansatz(dtype): """ Description: Test strongly_entangling_ansatz diff --git a/tests/st/test_algorithm/test_qaia/test_qaia.py b/tests/st/test_algorithm/test_qaia/test_qaia.py index 2a33fd5c3..ca5f689e6 100644 --- a/tests/st/test_algorithm/test_qaia/test_qaia.py +++ b/tests/st/test_algorithm/test_qaia/test_qaia.py @@ -20,8 +20,8 @@ import numpy as np from scipy.sparse import coo_matrix -from mindquantum.algorithm.qaia import ASB, BSB, CAC, CFC, DSB, LQA, SFC -from mindquantum.utils.fdopen import fdopen +from quafu.algorithm.qaia import ASB, BSB, CAC, CFC, DSB, LQA, SFC +from quafu.utils.fdopen import fdopen import pytest diff --git a/tests/st/test_applications/test_chem_net.py b/tests/st/test_applications/test_chem_net.py index 3a88a30ea..efabea6bc 100644 --- a/tests/st/test_applications/test_chem_net.py +++ b/tests/st/test_applications/test_chem_net.py @@ -23,13 +23,13 @@ try: import mindspore as ms - from mindquantum.algorithm.nisq import generate_uccsd - from mindquantum.core import gates as G - from mindquantum.core.circuit import Circuit - from mindquantum.core.operators import Hamiltonian - from mindquantum.framework import MQAnsatzOnlyLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.algorithm.nisq import generate_uccsd + from quafu.core import gates as G + from quafu.core.circuit import Circuit + from quafu.core.operators import Hamiltonian + from quafu.framework import QUAFUAnsatzOnlyLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -65,7 +65,7 @@ def test_vqe_net(config): # pylint: disable=too-many-locals Expectation: """ backend, dtype = config - if backend == 'mqmatrix': + if backend == 'quafumatrix': return ms.context.set_context(mode=ms.context.PYNATIVE_MODE, device_target="CPU") ( @@ -80,7 +80,7 @@ def test_vqe_net(config): # pylint: disable=too-many-locals vqe_circuit = hf_circuit + ansatz_circuit sim = Simulator(backend, vqe_circuit.n_qubits, dtype=dtype) f_g_ops = sim.get_expectation_with_grad(Hamiltonian(hamiltonian_qubitop.real.astype(dtype)), vqe_circuit) - molecule_pqcnet = MQAnsatzOnlyLayer(f_g_ops) + molecule_pqcnet = QUAFUAnsatzOnlyLayer(f_g_ops) optimizer = ms.nn.Adagrad(molecule_pqcnet.trainable_params(), learning_rate=4e-2) train_pqcnet = ms.nn.TrainOneStepCell(molecule_pqcnet, optimizer) eps = 1e-8 diff --git a/tests/st/test_core/test_circuit/test_channel_adder.py b/tests/st/test_core/test_circuit/test_channel_adder.py index 815ed1f2d..30f2a7c6c 100644 --- a/tests/st/test_core/test_circuit/test_channel_adder.py +++ b/tests/st/test_core/test_circuit/test_channel_adder.py @@ -14,7 +14,7 @@ # ============================================================================ """Test channel adder.""" -from mindquantum.core.circuit import ( +from quafu.core.circuit import ( BitFlipAdder, Circuit, MeasureAccepter, @@ -26,7 +26,7 @@ ReverseAdder, SequentialAdder, ) -from mindquantum.core.gates import ( +from quafu.core.gates import ( AmplitudeDampingChannel, BitFlipChannel, DepolarizingChannel, diff --git a/tests/st/test_core/test_circuit/test_circuit.py b/tests/st/test_core/test_circuit/test_circuit.py index e3414c6fc..6a71c028a 100644 --- a/tests/st/test_core/test_circuit/test_circuit.py +++ b/tests/st/test_core/test_circuit/test_circuit.py @@ -22,11 +22,11 @@ import numpy as np import pytest -from mindquantum.core import gates as G -from mindquantum.core.circuit import Circuit, add_prefix, shift -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.simulator import Simulator -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.core import gates as G +from quafucircuit import Circuit, add_prefix, shift +from quafuparameterresolver import ParameterResolver +from quafuator import Simulator +from quafuator.available_simulator import SUPPORTED_SIMULATOR try: import importlib.metadata as importlib_metadata @@ -114,7 +114,7 @@ def test_evolution_state(config): simulator.apply_circuit(circ, ParameterResolver({'a': a, 'b': b})) state = simulator.get_qs() state_exp = [0.9580325796404553, -0.14479246283091116j, -0.2446258794777393j, -0.036971585637570345] - if backend == "mqmatrix": + if backend == "quafumatrix": assert np.allclose(state, np.outer(state_exp, np.conj(state_exp))) else: assert np.allclose(state, state_exp) @@ -141,7 +141,7 @@ def test_depth(): Description: Expectation: """ - circ = Circuit().x(0).x(1,0).x(0).barrier().x(3,2).x(1).x(2,1) + circ = Circuit().x(0).x(1, 0).x(0).barrier().x(3, 2).x(1).x(2, 1) assert circ.depth(with_single=True, with_barrier=True) == 5 assert circ.depth(with_single=True, with_barrier=False) == 4 assert circ.depth(with_single=False, with_barrier=True) == 3 diff --git a/tests/st/test_core/test_circuit/test_circuit_utils.py b/tests/st/test_core/test_circuit/test_circuit_utils.py index 98488c9f4..f58810a36 100644 --- a/tests/st/test_core/test_circuit/test_circuit_utils.py +++ b/tests/st/test_core/test_circuit/test_circuit_utils.py @@ -18,18 +18,18 @@ import numpy as np import pytest -import mindquantum.core.gates as G -from mindquantum.algorithm.library import qft -from mindquantum.core.circuit import AP, CPN, Circuit, add_prefix -from mindquantum.core.circuit import apply as A -from mindquantum.core.circuit import as_ansatz, as_encoder -from mindquantum.core.circuit import controlled as C -from mindquantum.core.circuit import dagger as D -from mindquantum.core.circuit import ( +import quafu.core.gates as G +from quafu.algorithm.library import qft +from quafu.core.circuit import AP, CPN, Circuit, add_prefix +from quafu.core.circuit import apply as A +from quafu.core.circuit import as_ansatz, as_encoder +from quafu.core.circuit import controlled as C +from quafu.core.circuit import dagger as D +from quafu.core.circuit import ( decompose_single_term_time_evolution, pauli_word_to_circuits, ) -from mindquantum.core.operators import QubitOperator +from quafu.core.operators import QubitOperator def test_pauli_word_to_circuits(): diff --git a/tests/st/test_core/test_circuit/test_module_circuit.py b/tests/st/test_core/test_circuit/test_module_circuit.py index 46f8b8b97..a3d4f1a25 100644 --- a/tests/st/test_core/test_circuit/test_module_circuit.py +++ b/tests/st/test_core/test_circuit/test_module_circuit.py @@ -13,8 +13,8 @@ # limitations under the License. # ============================================================================ """Test module_circuit.""" -from mindquantum.core import gates as G -from mindquantum.core.circuit import UN, SwapParts +from quafu.core import gates as G +from quafu.core.circuit import UN, SwapParts def test_un(): diff --git a/tests/st/test_core/test_circuit/test_qfi.py b/tests/st/test_core/test_circuit/test_qfi.py index b58b12801..671407e77 100644 --- a/tests/st/test_core/test_circuit/test_qfi.py +++ b/tests/st/test_core/test_circuit/test_qfi.py @@ -18,15 +18,15 @@ import numpy as np import pytest -from mindquantum.core.circuit import ( +from quafu.core.circuit import ( Circuit, partial_psi_partial_psi, partial_psi_psi, qfi, ) -from mindquantum.core.parameterresolver import ParameterResolver as PR -from mindquantum.simulator import Simulator -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafuparameterresolver import ParameterResolver as PR +from quafuator import Simulator +from quafuator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -43,7 +43,7 @@ def test_qfi(config): """ # pylint: disable=too-many-locals backend, dtype = config - if backend == 'mqmatrix': + if backend == 'quafumatrix': return a = PR('a') b = PR('b') diff --git a/tests/st/test_core/test_gates/test_channel.py b/tests/st/test_core/test_gates/test_channel.py index 7e524c364..1a2e0f02a 100644 --- a/tests/st/test_core/test_gates/test_channel.py +++ b/tests/st/test_core/test_gates/test_channel.py @@ -18,7 +18,7 @@ import numpy as np import pytest -import mindquantum.core.gates.channel as C +import quafu.core.gates.channel as C I = np.array([[1.0 + 0.0j, 0], [0, 1]]) # noqa: E741 X = np.array([[0, 1], [1, 0]]) diff --git a/tests/st/test_core/test_gates/test_gate.py b/tests/st/test_core/test_gates/test_gate.py index a1057e43e..587abe275 100644 --- a/tests/st/test_core/test_gates/test_gate.py +++ b/tests/st/test_core/test_gates/test_gate.py @@ -20,8 +20,8 @@ import pytest from scipy.linalg import expm -import mindquantum.core.gates as G -from mindquantum.core.circuit import UN +import quafu.core.gates as G +from quafu.core.circuit import UN def test_rotate_pauli(): diff --git a/tests/st/test_core/test_gates/test_measurement.py b/tests/st/test_core/test_gates/test_measurement.py index 455f291fc..a2bff9f49 100644 --- a/tests/st/test_core/test_gates/test_measurement.py +++ b/tests/st/test_core/test_gates/test_measurement.py @@ -16,8 +16,8 @@ # pylint: disable=invalid-name """Test gate.""" -from mindquantum.utils import random_circuit -from mindquantum.simulator import Simulator +from quafu.utils import random_circuit +from quafuator import Simulator import numpy as np @@ -29,7 +29,7 @@ def test_measure_result_reverse_endian(): circ = random_circuit(10, 10) circ.measure_all() - sim = Simulator("mqvector", 10) + sim = Simulator("quafuvector", 10) res = sim.sampling(circ, shots=100) original_keys = res.keys.copy() diff --git a/tests/st/test_core/test_operators/test_fermion_ops.py b/tests/st/test_core/test_operators/test_fermion_ops.py index 36339e733..2e3e9baff 100644 --- a/tests/st/test_core/test_operators/test_fermion_ops.py +++ b/tests/st/test_core/test_operators/test_fermion_ops.py @@ -21,7 +21,7 @@ import numpy as np import pytest -from mindquantum.core.operators import FermionOperator +from quafu.core.operators import FermionOperator _HAS_OPENFERMION = True try: @@ -219,9 +219,9 @@ def test_of_fermion_trans(): Expectation: success. """ ofo_ops = OFFermionOperator("1^ 0", 1) - mq_ops = FermionOperator('1^ 0', 1) - assert mq_ops.to_openfermion() == ofo_ops - assert mq_ops == FermionOperator.from_openfermion(ofo_ops) + quafu_ops = FermionOperator('1^ 0', 1) + assert quafu_ops.to_openfermion() == ofo_ops + assert quafu_ops == FermionOperator.from_openfermion(ofo_ops) @pytest.mark.level0 diff --git a/tests/st/test_core/test_operators/test_hamiltonian.py b/tests/st/test_core/test_operators/test_hamiltonian.py index 9a883757b..c21493899 100644 --- a/tests/st/test_core/test_operators/test_hamiltonian.py +++ b/tests/st/test_core/test_operators/test_hamiltonian.py @@ -16,7 +16,7 @@ import numpy as np import pytest -from mindquantum.core.operators import Hamiltonian, QubitOperator +from quafu.core.operators import Hamiltonian, QubitOperator @pytest.mark.level0 diff --git a/tests/st/test_core/test_operators/test_operators_utils.py b/tests/st/test_core/test_operators/test_operators_utils.py index 57038b43b..921df6991 100644 --- a/tests/st/test_core/test_operators/test_operators_utils.py +++ b/tests/st/test_core/test_operators/test_operators_utils.py @@ -15,7 +15,7 @@ """Test operator_utils.""" import pytest -from mindquantum.core.operators import ( +from quafu.core.operators import ( FermionOperator, QubitExcitationOperator, QubitOperator, diff --git a/tests/st/test_core/test_operators/test_polynomial_tensor.py b/tests/st/test_core/test_operators/test_polynomial_tensor.py index 43b845dd9..99ba4230f 100644 --- a/tests/st/test_core/test_operators/test_polynomial_tensor.py +++ b/tests/st/test_core/test_operators/test_polynomial_tensor.py @@ -17,7 +17,7 @@ import numpy as np import pytest -from mindquantum.core.operators import PolynomialTensor +from quafu.core.operators import PolynomialTensor @pytest.mark.level0 diff --git a/tests/st/test_core/test_operators/test_qubit_excitation_ops.py b/tests/st/test_core/test_operators/test_qubit_excitation_ops.py index 044524412..779dd8c37 100644 --- a/tests/st/test_core/test_operators/test_qubit_excitation_ops.py +++ b/tests/st/test_core/test_operators/test_qubit_excitation_ops.py @@ -19,7 +19,7 @@ import pytest -from mindquantum.core.operators import ( +from quafu.core.operators import ( FermionOperator, QubitExcitationOperator, QubitOperator, diff --git a/tests/st/test_core/test_operators/test_qubit_ops.py b/tests/st/test_core/test_operators/test_qubit_ops.py index aaebd5fcc..827f74171 100644 --- a/tests/st/test_core/test_operators/test_qubit_ops.py +++ b/tests/st/test_core/test_operators/test_qubit_ops.py @@ -20,10 +20,10 @@ import numpy as np import pytest -from mindquantum.core.operators import QubitOperator, ground_state_of_sum_zz -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR -from mindquantum.utils.error import DeviceNotSupportedError +from quafu.core.operators import QubitOperator, ground_state_of_sum_zz +from quafu.core.parameterresolver import ParameterResolver +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.utils.error import DeviceNotSupportedError _HAS_OPENFERMION = True AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -203,10 +203,10 @@ def test_qubit_ops_trans(): Expectation: success. """ ofo_ops = OFQubitOperator("X0 Y1 Z2", 1) - mq_ops = QubitOperator("X0 Y1 Z2", 1) + quafu_ops = QubitOperator("X0 Y1 Z2", 1) - assert mq_ops.to_openfermion() == ofo_ops - assert mq_ops == QubitOperator.from_openfermion(ofo_ops) + assert quafu_ops.to_openfermion() == ofo_ops + assert quafu_ops == QubitOperator.from_openfermion(ofo_ops) @pytest.mark.level0 @@ -225,9 +225,9 @@ def test_ground_state_of_sum_zz_cpu(): pass -tmp_sim = ['mqvector'] -if 'mqvector_gpu' in SUPPORTED_SIMULATOR.sims: - tmp_sim.append('mqvector_gpu') +tmp_sim = ['quafuvector'] +if 'quafuvector_gpu' in SUPPORTED_SIMULATOR.sims: + tmp_sim.append('quafuvector_gpu') @pytest.mark.level0 diff --git a/tests/st/test_core/test_operators/test_sparse.py b/tests/st/test_core/test_operators/test_sparse.py index 3b7f95964..62798e75e 100644 --- a/tests/st/test_core/test_operators/test_sparse.py +++ b/tests/st/test_core/test_operators/test_sparse.py @@ -20,10 +20,10 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum.algorithm.nisq import Transform -from mindquantum.core.operators import FermionOperator -from mindquantum.third_party.interaction_operator import InteractionOperator +import quafu +from quafu.algorithm.nisq import Transform +from quafu.core.operators import FermionOperator +from quafu.third_party.interaction_operator import InteractionOperator _HAS_OPENFERMION = True try: @@ -36,7 +36,7 @@ @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64]) @pytest.mark.skipif(not _HAS_OPENFERMION, reason='OpenFermion is not installed') @pytest.mark.skipif(not _FORCE_TEST, reason='set not force test') def test_sparsing_operator(dtype): @@ -56,7 +56,7 @@ def test_sparsing_operator(dtype): ham = Transform(ham_hiq).jordan_wigner() hamiltonian = ham.to_openfermion() - matrix1 = get_sparse_operator(hamiltonian).toarray().astype(mq.to_np_type(dtype)) + matrix1 = get_sparse_operator(hamiltonian).toarray().astype(quafu.to_np_type(dtype)) matrix2 = ham.astype(dtype).matrix().toarray() matrix3 = ham_hiq.astype(dtype).matrix().toarray() eigen_v1 = np.real(np.linalg.eigvals(matrix1)) diff --git a/tests/st/test_core/test_operators/test_time_evolution.py b/tests/st/test_core/test_operators/test_time_evolution.py index ba4e3731b..dede68a52 100644 --- a/tests/st/test_core/test_operators/test_time_evolution.py +++ b/tests/st/test_core/test_operators/test_time_evolution.py @@ -15,9 +15,9 @@ """Test TimeEvolution.""" import pytest -from mindquantum.core import gates as G -from mindquantum.core.circuit import Circuit -from mindquantum.core.operators import QubitOperator, TimeEvolution +from quafu.core import gates as G +from quafu.core.circuit import Circuit +from quafu.core.operators import QubitOperator, TimeEvolution @pytest.mark.level0 diff --git a/tests/st/test_core/test_parameterresolver/test_parameter_resolver.py b/tests/st/test_core/test_parameterresolver/test_parameter_resolver.py index 2d963d03a..b893edd9d 100644 --- a/tests/st/test_core/test_parameterresolver/test_parameter_resolver.py +++ b/tests/st/test_core/test_parameterresolver/test_parameter_resolver.py @@ -17,9 +17,9 @@ import pytest -import mindquantum as mq -from mindquantum.core.parameterresolver import ParameterResolver as PR -from mindquantum.core.parameterresolver import PRGenerator +import quafu +from quafu.core.parameterresolver import ParameterResolver as PR +from quafu.core.parameterresolver import PRGenerator @pytest.mark.level0 @@ -62,7 +62,7 @@ def test_parameter_resolve(): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.float64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.float64]) def test_parameter_resolve_dumps_and_loads(dtype): ''' Description: Test pr dumps to json and json loads to pr @@ -78,7 +78,7 @@ def test_parameter_resolve_dumps_and_loads(dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64, mq.float32, mq.float64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64, quafu.float32, quafu.float64]) def test_parameter_resolve_combination(dtype): """ Description: Test pr combination @@ -91,7 +91,7 @@ def test_parameter_resolve_combination(dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu -@pytest.mark.parametrize('dtype', [mq.complex128, mq.complex64, mq.float32, mq.float64]) +@pytest.mark.parametrize('dtype', [quafu.complex128, quafu.complex64, quafu.float32, quafu.float64]) def test_parameter_resolver_pickle(dtype): """ Description: Test pickle diff --git a/tests/st/test_device/test_topology.py b/tests/st/test_device/test_topology.py index df25bc7a7..ec8c49d2f 100644 --- a/tests/st/test_device/test_topology.py +++ b/tests/st/test_device/test_topology.py @@ -15,7 +15,7 @@ """Test topology of device.""" import pytest -from mindquantum.device import GridQubits, LinearQubits, QubitNode, QubitsTopology +from quafu.device import GridQubits, LinearQubits, QubitNode, QubitsTopology def test_qubit_node_property(): diff --git a/tests/st/test_dtype/test_dtype.py b/tests/st/test_dtype/test_dtype.py index ae104c9ed..fd69cf07e 100644 --- a/tests/st/test_dtype/test_dtype.py +++ b/tests/st/test_dtype/test_dtype.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Test mindquantum dtype.""" +"""Test quafu dtype.""" -import mindquantum as mq -from mindquantum.simulator import Simulator +import quafu +from quafu.simulator import Simulator import numpy as np import pytest @@ -24,15 +24,30 @@ @pytest.mark.platform_x86_gpu_training @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize("error_dtype", ['int', 'float', 'mq.int', 'mq.flaot', 'mq.double', 'mq.complex', 'mq.int32', - 'mq.float31', 'mq.float63', 'mq.complex63', 'mq.complex127', 'np.float32']) +@pytest.mark.parametrize( + "error_dtype", + [ + 'int', + 'float', + 'quafu.int', + 'quafu.flaot', + 'quafu.double', + 'quafu.complex', + 'quafu.int32', + 'quafu.float31', + 'quafu.float63', + 'quafu.complex63', + 'quafu.complex127', + 'np.float32', + ], +) def test_error_dtype(error_dtype): """ Description: test error dtype. Expectation: raise error """ with pytest.raises(ValueError): - Simulator('mqvector', 2, dtype=error_dtype) + Simulator('quafuvector', 2, dtype=error_dtype) @pytest.mark.level0 @@ -41,50 +56,50 @@ def test_error_dtype(error_dtype): @pytest.mark.env_onecard def test_dtype(): """ - Description: test mindquantum dtype. + Description: test quafu dtype. Expectation: success """ - assert mq.dtype.is_double_precision(mq.float64) - assert mq.dtype.is_double_precision(mq.complex128) - assert not mq.dtype.is_double_precision(mq.float32) - assert not mq.dtype.is_double_precision(mq.complex64) + assert quafu.dtype.is_double_precision(quafu.float64) + assert quafu.dtype.is_double_precision(quafu.complex128) + assert not quafu.dtype.is_double_precision(quafu.float32) + assert not quafu.dtype.is_double_precision(quafu.complex64) - assert mq.dtype.is_single_precision(mq.float32) - assert mq.dtype.is_single_precision(mq.complex64) - assert not mq.dtype.is_single_precision(mq.float64) - assert not mq.dtype.is_single_precision(mq.complex128) + assert quafu.dtype.is_single_precision(quafu.float32) + assert quafu.dtype.is_single_precision(quafu.complex64) + assert not quafu.dtype.is_single_precision(quafu.float64) + assert not quafu.dtype.is_single_precision(quafu.complex128) - assert mq.dtype.is_same_precision(mq.float32, mq.complex64) - assert mq.dtype.is_same_precision(mq.float64, mq.complex128) - assert not mq.dtype.is_same_precision(mq.float32, mq.complex128) + assert quafu.dtype.is_same_precision(quafu.float32, quafu.complex64) + assert quafu.dtype.is_same_precision(quafu.float64, quafu.complex128) + assert not quafu.dtype.is_same_precision(quafu.float32, quafu.complex128) - assert mq.dtype.precision_str(mq.float32) == 'single precision' - assert mq.dtype.precision_str(mq.float64) == 'double precision' - assert not mq.dtype.precision_str(mq.complex64) == 'double precision' + assert quafu.dtype.precision_str(quafu.float32) == 'single precision' + assert quafu.dtype.precision_str(quafu.float64) == 'double precision' + assert not quafu.dtype.precision_str(quafu.complex64) == 'double precision' - assert mq.dtype.to_real_type(mq.complex64) == mq.float32 - assert mq.dtype.to_real_type(mq.complex128) == mq.float64 - assert mq.dtype.to_real_type(mq.float64) == mq.float64 + assert quafu.dtype.to_real_type(quafu.complex64) == quafu.float32 + assert quafu.dtype.to_real_type(quafu.complex128) == quafu.float64 + assert quafu.dtype.to_real_type(quafu.float64) == quafu.float64 - assert mq.dtype.to_complex_type(mq.float32) == mq.complex64 - assert mq.dtype.to_complex_type(mq.float64) == mq.complex128 - assert mq.dtype.to_complex_type(mq.complex128) == mq.complex128 + assert quafu.dtype.to_complex_type(quafu.float32) == quafu.complex64 + assert quafu.dtype.to_complex_type(quafu.float64) == quafu.complex128 + assert quafu.dtype.to_complex_type(quafu.complex128) == quafu.complex128 - assert mq.dtype.to_single_precision(mq.float64) == mq.float32 - assert mq.dtype.to_single_precision(mq.complex128) == mq.complex64 - assert mq.dtype.to_single_precision(mq.float32) == mq.float32 + assert quafu.dtype.to_single_precision(quafu.float64) == quafu.float32 + assert quafu.dtype.to_single_precision(quafu.complex128) == quafu.complex64 + assert quafu.dtype.to_single_precision(quafu.float32) == quafu.float32 - assert mq.dtype.to_double_precision(mq.float32) == mq.float64 - assert mq.dtype.to_double_precision(mq.complex64) == mq.complex128 - assert mq.dtype.to_double_precision(mq.float32) == mq.float64 + assert quafu.dtype.to_double_precision(quafu.float32) == quafu.float64 + assert quafu.dtype.to_double_precision(quafu.complex64) == quafu.complex128 + assert quafu.dtype.to_double_precision(quafu.float32) == quafu.float64 - assert mq.dtype.to_precision_like(mq.float32, mq.complex128) == mq.float64 - assert mq.dtype.to_precision_like(mq.complex128, mq.float32) == mq.complex64 + assert quafu.dtype.to_precision_like(quafu.float32, quafu.complex128) == quafu.float64 + assert quafu.dtype.to_precision_like(quafu.complex128, quafu.float32) == quafu.complex64 - assert mq.dtype.to_mq_type(np.float32) == mq.float32 - assert mq.dtype.to_mq_type(np.float64) == mq.float64 - assert mq.dtype.to_mq_type(np.complex64) == mq.complex64 - assert mq.dtype.to_mq_type(np.complex128) == mq.complex128 + assert quafu.dtype.to_quafu_type(np.float32) == quafu.float32 + assert quafu.dtype.to_quafu_type(np.float64) == quafu.float64 + assert quafu.dtype.to_quafu_type(np.complex64) == quafu.complex64 + assert quafu.dtype.to_quafu_type(np.complex128) == quafu.complex128 - assert mq.dtype.to_np_type(mq.float32) == np.float32 - assert mq.dtype.to_np_type(mq.complex128) == np.complex128 + assert quafu.dtype.to_np_type(quafu.float32) == np.float32 + assert quafu.dtype.to_np_type(quafu.complex128) == np.complex128 diff --git a/tests/st/test_engine/test_circuitengine.py b/tests/st/test_engine/test_circuitengine.py index 5c5039841..6c12d8c19 100755 --- a/tests/st/test_engine/test_circuitengine.py +++ b/tests/st/test_engine/test_circuitengine.py @@ -17,10 +17,10 @@ """Test circuitengine.""" -import mindquantum.core.gates as G -from mindquantum.core.circuit import Circuit -from mindquantum.engine import circuit_generator -from mindquantum.engine.circuitengine import CircuitEngine +import quafu.core.gates as G +from quafu.core.circuit import Circuit +from quafu.engine import circuit_generator +from quafu.engine.circuitengine import CircuitEngine def test_allocate_qureg(): diff --git a/tests/st/test_framework/test_layer.py b/tests/st/test_framework/test_layer.py index cc549f7de..8fda59d2a 100644 --- a/tests/st/test_framework/test_layer.py +++ b/tests/st/test_framework/test_layer.py @@ -24,12 +24,12 @@ try: import mindspore as ms - from mindquantum.core import gates as G - from mindquantum.core.circuit import Circuit - from mindquantum.core.operators import Hamiltonian, QubitOperator - from mindquantum.framework import MQLayer, QRamVecLayer - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.core import gates as G + from quafu.core.circuit import Circuit + from quafu.core.operators import Hamiltonian, QubitOperator + from quafu.framework import QUAFULayer, QRamVecLayer + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -48,9 +48,9 @@ def get_supported_simulator(): @pytest.mark.env_onecard @pytest.mark.parametrize('config', AVAILABLE_BACKEND) @pytest.mark.skipif(not _HAS_MINDSPORE, reason='MindSpore is not installed') -def test_mindquantumlayer(config): +def test_quafulayer(config): """ - Description: Test MQLayer + Description: Test QUAFULayer Expectation: """ backend, dtype = config @@ -65,7 +65,7 @@ def test_mindquantumlayer(config): circ = encoder.as_encoder() + ansatz.as_ansatz() sim = Simulator(backend, circ.n_qubits, dtype=dtype) f_g_ops = sim.get_expectation_with_grad(ham, circ) - net = MQLayer(f_g_ops) + net = QUAFULayer(f_g_ops) encoder_data = ms.Tensor(np.array([[0.1, 0.2]]).astype(np.float32)) res = net(encoder_data) assert np.allclose(res.asnumpy()[0, 0], 0.994962, atol=1e-2) @@ -84,7 +84,7 @@ def test_qram_vec_layer(config): Expectation: """ backend, dtype = config - if backend == 'mqmatrix': + if backend == 'quafumatrix': return ms.set_seed(42) ans = Circuit().ry('a', 0).rx('b', 0).as_ansatz() diff --git a/tests/st/test_framework/test_operations.py b/tests/st/test_framework/test_operations.py index a601f3b71..273188fce 100644 --- a/tests/st/test_framework/test_operations.py +++ b/tests/st/test_framework/test_operations.py @@ -22,12 +22,12 @@ try: import mindspore as ms - from mindquantum.core import gates as G - from mindquantum.core.circuit import Circuit - from mindquantum.core.operators import Hamiltonian, QubitOperator - from mindquantum.framework import MQAnsatzOnlyOps - from mindquantum.simulator import Simulator - from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR + from quafu.core import gates as G + from quafu.core.circuit import Circuit + from quafu.core.operators import Hamiltonian, QubitOperator + from quafu.framework import QUAFUAnsatzOnlyOps + from quafu.simulator import Simulator + from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR AVAILABLE_BACKEND = list(filter(lambda x: x != 'stabilizer', SUPPORTED_SIMULATOR)) @@ -46,9 +46,9 @@ def get_supported_simulator(): @pytest.mark.env_onecard @pytest.mark.parametrize('config', AVAILABLE_BACKEND) @pytest.mark.skipif(not _HAS_MINDSPORE, reason='MindSpore is not installed') -def test_mindquantum_ansatz_only_ops(config): +def test_quafu_ansatz_only_ops(config): """ - Description: Test MQAnsatzOnlyOps + Description: Test QUAFUAnsatzOnlyOps Expectation: """ backend, dtype = config @@ -57,6 +57,6 @@ def test_mindquantum_ansatz_only_ops(config): ham = Hamiltonian(QubitOperator('Z0').astype(dtype)) sim = Simulator(backend, circ.n_qubits, dtype=dtype) - evol = MQAnsatzOnlyOps(sim.get_expectation_with_grad(ham, circ)) + evol = QUAFUAnsatzOnlyOps(sim.get_expectation_with_grad(ham, circ)) output = evol(data) assert np.allclose(output.asnumpy(), [[8.77582550e-01]]) diff --git a/tests/st/test_io/test_beauty_print.py b/tests/st/test_io/test_beauty_print.py index a1588a3f7..c7e135cf6 100644 --- a/tests/st/test_io/test_beauty_print.py +++ b/tests/st/test_io/test_beauty_print.py @@ -17,7 +17,7 @@ """Test utils.""" -from mindquantum.io import bprint +from quafu.io import bprint def test_beauty_print(): diff --git a/tests/st/test_io/test_qasm/test_hiqasm.py b/tests/st/test_io/test_qasm/test_hiqasm.py index 833948807..c78c2f7b6 100644 --- a/tests/st/test_io/test_qasm/test_hiqasm.py +++ b/tests/st/test_io/test_qasm/test_hiqasm.py @@ -14,8 +14,8 @@ # ============================================================================ """Test hiqasm.""" -from mindquantum.core.gates import X -from mindquantum.io import HiQASM, random_hiqasm +from quafu.core.gates import X +from quafu.io import HiQASM, random_hiqasm def test_hiqasm(): diff --git a/tests/st/test_io/test_qasm/test_openqasm.py b/tests/st/test_io/test_qasm/test_openqasm.py index e8e103465..96ecf4f88 100644 --- a/tests/st/test_io/test_qasm/test_openqasm.py +++ b/tests/st/test_io/test_qasm/test_openqasm.py @@ -16,10 +16,10 @@ import numpy as np -from mindquantum.core import U3, UN, Circuit, H, X -from mindquantum.io import OpenQASM -from mindquantum.simulator import Simulator -from mindquantum.utils import random_circuit +from quafu.core import U3, UN, Circuit, H, X +from quafu.io import OpenQASM +from quafu.simulator import Simulator +from quafu.utils import random_circuit def test_openqasm(): @@ -122,7 +122,7 @@ def unmaj(a, b, c): exp_circ.measure(b[3]) exp_circ.measure(cout[0]) init = random_circuit(circ.n_qubits, 30, seed=42) - sim = Simulator('mqvector', circ.n_qubits) + sim = Simulator('quafuvector', circ.n_qubits) s_1 = sim.sampling(init + circ, shots=50, seed=42) s_2 = sim.sampling(init + exp_circ, shots=50, seed=42) assert np.all(s_1.samples == s_2.samples) @@ -175,7 +175,7 @@ def test_openqasm_custom_gate2(): ) exp_circ.measure_all() init = random_circuit(circ.n_qubits, 30, seed=42) - sim = Simulator('mqvector', circ.n_qubits) + sim = Simulator('quafuvector', circ.n_qubits) s_1 = sim.sampling(init + circ, shots=50, seed=42) s_2 = sim.sampling(init + exp_circ, shots=50, seed=42) assert np.all(s_1.samples == s_2.samples) diff --git a/tests/st/test_io/test_qasm/test_qcis.py b/tests/st/test_io/test_qasm/test_qcis.py index 241eb6a89..bf38c6fc9 100644 --- a/tests/st/test_io/test_qasm/test_qcis.py +++ b/tests/st/test_io/test_qasm/test_qcis.py @@ -15,9 +15,10 @@ """Test qcis.""" import numpy as np -from mindquantum.core.circuit import Circuit -from mindquantum.core.parameterresolver import ParameterResolver -from mindquantum.io import QCIS +from quafu.core.circuit import Circuit +from quafu.core.parameterresolver import ParameterResolver +from quafu.io import QCIS + def test_qcis(): """ @@ -26,16 +27,16 @@ def test_qcis(): Expectation: """ circ0 = Circuit() - circ0.x(0).z(1,0).rx({"a":-2*np.sqrt(2)}, 0).sx(0).barrier() - circ0.ry(ParameterResolver(data={'theta':-np.pi}, const=np.pi), 1) + circ0.x(0).z(1, 0).rx({"a": -2 * np.sqrt(2)}, 0).sx(0).barrier() + circ0.ry(ParameterResolver(data={'theta': -np.pi}, const=np.pi), 1) string = QCIS().to_string(circ0) circ1 = QCIS().from_string(string) assert circ1 == circ0 assert circ1.x(0) != circ0 - circ2 = Circuit().rx({"a":-2*np.sqrt(2)}, 0) - circ2.ry(ParameterResolver(data={'theta':-np.pi}, const=np.pi/2), 0).rz(0., 0) + circ2 = Circuit().rx({"a": -2 * np.sqrt(2)}, 0) + circ2.ry(ParameterResolver(data={'theta': -np.pi}, const=np.pi / 2), 0).rz(0.0, 0) string = QCIS().to_string(circ2, parametric=False) circ3 = Circuit().from_qcis(string) - circ4 = Circuit().ry(np.pi/2, 0) + circ4 = Circuit().ry(np.pi / 2, 0) assert circ3 == circ4 diff --git a/tests/st/test_io/test_svg.py b/tests/st/test_io/test_svg.py index 7316eb70a..aff215391 100644 --- a/tests/st/test_io/test_svg.py +++ b/tests/st/test_io/test_svg.py @@ -14,9 +14,9 @@ # ============================================================================ """Test svg.""" -from mindquantum.algorithm.library import qft -from mindquantum.core.gates import RX, BarrierGate -from mindquantum.simulator import Simulator +from quafu.algorithm.library import qft +from quafu.core.gates import RX, BarrierGate +from quafu.simulator import Simulator def test_measure_svg(): @@ -25,7 +25,7 @@ def test_measure_svg(): Expectation: success. """ circ = qft(range(3)).measure_all() - sim = Simulator('mqvector', 3) + sim = Simulator('quafuvector', 3) res = sim.sampling(circ, shots=100, seed=42) text = res.svg()._repr_svg_().split('bar') # pylint: disable=protected-access text = "bar".join([text[0]] + ['"'.join(i.split('"')[1:]) for i in text[1:]]) diff --git a/tests/st/test_simulator/test_basic_gate_with_simulator.py b/tests/st/test_simulator/test_basic_gate_with_simulator.py index c77147d8b..a7dde25a1 100644 --- a/tests/st/test_simulator/test_basic_gate_with_simulator.py +++ b/tests/st/test_simulator/test_basic_gate_with_simulator.py @@ -19,13 +19,13 @@ import numpy as np import pytest -import mindquantum as mq -from mindquantum.core import gates as G -from mindquantum.core.circuit import Circuit -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.simulator import Simulator -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR -from mindquantum.utils import random_circuit, random_hamiltonian +import quafu +from quafu.core import gates as G +from quafu.core.circuit import Circuit +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.simulator import Simulator +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.utils import random_circuit, random_hamiltonian none_parameter_gate = [ G.HGate, @@ -86,7 +86,7 @@ def test_none_parameter_gate(config, gate): sim.set_qs(init_state) sim.apply_gate(g) ref_qs = g.matrix() @ (init_state / np.linalg.norm(init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(sim.get_qs(), np.outer(ref_qs, ref_qs.conj())) else: assert np.allclose(sim.get_qs(), ref_qs) @@ -98,7 +98,7 @@ def test_none_parameter_gate(config, gate): c_sim.apply_gate(c_g) m = np.block([[np.eye(dim), np.zeros((dim, dim))], [np.zeros((dim, dim)), g.matrix()]]) c_ref_qs = m @ (c_init_state / np.linalg.norm(c_init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(c_sim.get_qs(), np.outer(c_ref_qs, c_ref_qs.conj()), atol=1e-6) else: assert np.allclose(c_sim.get_qs(), c_ref_qs, atol=1e-6) @@ -126,7 +126,7 @@ def test_parameter_gate(config, gate): # pylint: disable=too-many-locals sim.set_qs(init_state) sim.apply_gate(g) ref_qs = g.matrix() @ (init_state / np.linalg.norm(init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(sim.get_qs(), np.outer(ref_qs, ref_qs.conj()), atol=1e-6) else: assert np.allclose(sim.get_qs(), ref_qs, atol=1e-6) @@ -138,7 +138,7 @@ def test_parameter_gate(config, gate): # pylint: disable=too-many-locals c_sim.apply_gate(c_g) m = np.block([[np.eye(dim), np.zeros((dim, dim))], [np.zeros((dim, dim)), g.matrix()]]) c_ref_qs = m @ (c_init_state / np.linalg.norm(c_init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(c_sim.get_qs(), np.outer(c_ref_qs, c_ref_qs.conj()), atol=1e-6) else: assert np.allclose(c_sim.get_qs(), c_ref_qs, atol=1e-6) @@ -227,7 +227,7 @@ def test_custom_gate(config): # pylint: disable=too-many-locals """ virtual_qc, dtype = config for n in (1, 2, 3): - circ = mq.random_circuit(n, 100) + circ = quafu.random_circuit(n, 100) g = G.UnivMathGate('custom', circ.matrix()) dim = 2 ** (n + 1) g_dim = 2**n @@ -237,7 +237,7 @@ def test_custom_gate(config): # pylint: disable=too-many-locals sim.set_qs(init_state) sim.apply_gate(g) ref_qs = np.kron(np.eye(2), g.matrix()) @ (init_state / np.linalg.norm(init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(sim.get_qs(), np.outer(ref_qs, ref_qs.conj()), atol=1e-6) else: assert np.allclose(sim.get_qs(), ref_qs, atol=1e-6) @@ -249,7 +249,7 @@ def test_custom_gate(config): # pylint: disable=too-many-locals c_sim.apply_gate(c_g) m = np.block([[np.eye(g_dim), np.zeros((g_dim, g_dim))], [np.zeros((g_dim, g_dim)), g.matrix()]]) c_ref_qs = np.kron(np.eye(2), m) @ (c_init_state / np.linalg.norm(c_init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(c_sim.get_qs(), np.outer(c_ref_qs, c_ref_qs.conj()), atol=1e-6) else: assert np.allclose(c_sim.get_qs(), c_ref_qs, atol=1e-6) @@ -342,7 +342,7 @@ def diff_matrix2(theta1, theta2): sim.set_qs(init_state) sim.apply_gate(g, {'a': pr1, 'b': pr2}) ref_qs = np.kron(np.eye(2), g.matrix({'a': pr1, 'b': pr2})) @ (init_state / np.linalg.norm(init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(sim.get_qs(), np.outer(ref_qs, ref_qs.conj()), atol=1e-6) else: assert np.allclose(sim.get_qs(), ref_qs, atol=1e-6) @@ -357,7 +357,7 @@ def diff_matrix2(theta1, theta2): [[np.eye(g_dim), np.zeros((g_dim, g_dim))], [np.zeros((g_dim, g_dim)), g.matrix({'a': pr1, 'b': pr2})]] ) c_ref_qs = np.kron(np.eye(2), m) @ (c_init_state / np.linalg.norm(c_init_state)) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(c_sim.get_qs(), np.outer(c_ref_qs, c_ref_qs.conj()), atol=1e-6) else: assert np.allclose(c_sim.get_qs(), c_ref_qs, atol=1e-6) @@ -670,7 +670,7 @@ def test_rn_expectation_with_grad(config): # pylint: disable=R0914 """ virtual_qc, dtype = config rn = G.Rn('a', 'b', 'c').on(0) - init = mq.random_circuit(1, 10) + init = quafu.random_circuit(1, 10) circ = Circuit([rn]) ham = Hamiltonian(QubitOperator('X0') + QubitOperator('Y0') + QubitOperator('Z0')).astype(dtype) m_ham = ham.hamiltonian.matrix().toarray() @@ -719,7 +719,7 @@ def random_pauli_string(obj_qubits): obj_qubits = qubits[: n_qubits - 1] ctrl_qubits = None if np.random.random() < 0.5 else qubits[-1] circs.append(G.GroupedPauli(random_pauli_string(obj_qubits)).on(obj_qubits, ctrl_qubits)) - if virtual_qc.startswith('mqvector'): + if virtual_qc.startswith('quafuvector'): state = (random_circuit(n_qubits, 10) + G.I.on(n_qubits - 1)).get_qs() sim = Simulator(virtual_qc, n_qubits, dtype=dtype) for g in circs: @@ -730,7 +730,7 @@ def random_pauli_string(obj_qubits): sim.apply_circuit(g.__decompose__()) qs1 = sim.get_qs() assert np.allclose(qs0, qs1) - elif virtual_qc.startswith("mqmatrix"): + elif virtual_qc.startswith("quafumatrix"): qs0 = (random_circuit(n_qubits, 10) + G.I.on(n_qubits - 1)).get_qs() qs1 = (random_circuit(n_qubits, 10) + G.I.on(n_qubits - 1)).get_qs() qs2 = (random_circuit(n_qubits, 10) + G.I.on(n_qubits - 1)).get_qs() @@ -787,7 +787,7 @@ def test_rot_pauli_string_gate(config): # pylint: disable=too-many-locals sim.apply_circuit(rand_circ) sim.apply_circuit(circ) qs2 = sim.get_qs() - if dtype == mq.complex64: + if dtype == quafu.complex64: atol = 1e-4 else: atol = 1e-8 @@ -834,7 +834,7 @@ def test_rot_pauli_string_gate_gradient(config): # pylint: disable=too-many-loc grad_ops2 = sim2.get_expectation_with_grad(ham, circ2) f1, g1 = grad_ops1(p0) f2, g2 = grad_ops2(p0) - if dtype == mq.complex64: + if dtype == quafu.complex64: atol = 1e-4 else: atol = 1e-8 @@ -854,18 +854,18 @@ def test_custom_gate_order(config): # pylint: disable=too-many-locals """ virtual_qc, dtype = config for n in (2, 3, 4): - circ = mq.random_circuit(n, 100, 1.0, 0.0) + circ = quafu.random_circuit(n, 100, 1.0, 0.0) g = G.UnivMathGate('random', circ.matrix()).on(list(reversed(range(n)))) dim = 2**g.n_qubits init_state = np.random.rand(dim) + np.random.rand(dim) * 1j sim = Simulator(virtual_qc, g.n_qubits, dtype=dtype) sim.set_qs(init_state) sim.apply_gate(g) - ref_sim = Simulator("mqvector", g.n_qubits, dtype=dtype) + ref_sim = Simulator("quafuvector", g.n_qubits, dtype=dtype) ref_sim.set_qs(init_state) ref_sim.apply_circuit(circ.reverse_qubits()) ref_qs = ref_sim.get_qs() - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(sim.get_qs(), np.outer(ref_qs, ref_qs.conj()), atol=1e-6) else: assert np.allclose(sim.get_qs(), ref_qs, atol=1e-6) @@ -883,7 +883,7 @@ def test_two_qubit_gate_order(config, gate): # pylint: disable=too-many-locals Expectation: success. """ virtual_qc, dtype = config - if isinstance(gate, mq.NoneParameterGate): + if isinstance(gate, quafu.NoneParameterGate): g = gate() else: n_pr = len(signature(gate).parameters) @@ -896,11 +896,11 @@ def test_two_qubit_gate_order(config, gate): # pylint: disable=too-many-locals sim.set_qs(init_state) sim.apply_gate(g) ref_g = G.UnivMathGate('ref', g.matrix()).on(list(reversed(range(g.n_qubits)))) - ref_sim = Simulator("mqvector", g.n_qubits, dtype=dtype) + ref_sim = Simulator("quafuvector", g.n_qubits, dtype=dtype) ref_sim.set_qs(init_state) ref_sim.apply_gate(ref_g) ref_qs = ref_sim.get_qs() - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): assert np.allclose(sim.get_qs(), np.outer(ref_qs, ref_qs.conj()), atol=1e-6) else: assert np.allclose(sim.get_qs(), ref_qs, atol=1e-6) diff --git a/tests/st/test_simulator/test_channel_with_simulator.py b/tests/st/test_simulator/test_channel_with_simulator.py index ebd30c597..ba12f4f93 100644 --- a/tests/st/test_simulator/test_channel_with_simulator.py +++ b/tests/st/test_simulator/test_channel_with_simulator.py @@ -21,12 +21,12 @@ import pytest from scipy.stats import entropy -import mindquantum as mq -from mindquantum.core import gates as G -from mindquantum.core.circuit import Circuit -from mindquantum.simulator import Simulator -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR -from mindquantum.utils import random_circuit +import quafu +from quafu.core import gates as G +from quafu.core.circuit import Circuit +from quafu.simulator import Simulator +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.utils import random_circuit flip_and_damping_channel = [ G.BitFlipChannel, @@ -55,12 +55,12 @@ def test_flip_and_damping_channel(config, channel): p = np.random.rand() c = channel(p).on(0) tmp = np.outer(init_state, init_state.T.conj()) - ref_qs = np.zeros((2, 2), dtype=mq.to_np_type(dtype)) + ref_qs = np.zeros((2, 2), dtype=quafu.to_np_type(dtype)) for m in c.matrix(): ref_qs += m @ tmp @ m.T.conj() sim = Simulator(virtual_qc, 1, dtype=dtype) sim.set_qs(init_state) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): sim.apply_gate(c) assert np.allclose(sim.get_qs(), ref_qs) else: @@ -84,12 +84,12 @@ def test_pauli_channel(config): px, py, pz = np.random.rand(3) / 3 c = G.PauliChannel(px, py, pz).on(0) tmp = np.outer(init_state, init_state.T.conj()) - ref_qs = np.zeros((2, 2), dtype=mq.to_np_type(dtype)) + ref_qs = np.zeros((2, 2), dtype=quafu.to_np_type(dtype)) for m in c.matrix(): ref_qs += m @ tmp @ m.T.conj() sim = Simulator(virtual_qc, 1, dtype=dtype) sim.set_qs(init_state) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): sim.apply_gate(c) assert np.allclose(sim.get_qs(), ref_qs) else: @@ -115,12 +115,12 @@ def test_depolarizing_channel(config): init_state = np.random.rand(dim) + np.random.rand(dim) * 1j init_state = init_state / np.linalg.norm(init_state) tmp = np.outer(init_state, init_state.T.conj()) - ref_qs = np.zeros((dim, dim), dtype=mq.to_np_type(dtype)) + ref_qs = np.zeros((dim, dim), dtype=quafu.to_np_type(dtype)) for m in c.matrix(): ref_qs += m @ tmp @ m.T.conj() sim = Simulator(virtual_qc, n, dtype=dtype) sim.set_qs(init_state) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): sim.apply_gate(c) assert np.allclose(sim.get_qs(), ref_qs) else: @@ -148,12 +148,12 @@ def test_kraus_channel(config): c2 = G.KrausChannel('gp', [1j * i for i in G.DepolarizingChannel(np.random.rand() * 4 / 3).matrix()]).on(0) for c in (c0, c1, c2): - ref_qs = np.zeros((2, 2), dtype=mq.to_np_type(dtype)) + ref_qs = np.zeros((2, 2), dtype=quafu.to_np_type(dtype)) for m in c.matrix(): ref_qs += m @ tmp @ m.T.conj() sim = Simulator(virtual_qc, 1, dtype=dtype) sim.set_qs(init_state) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): sim.apply_gate(c) assert np.allclose(sim.get_qs(), ref_qs) else: @@ -181,7 +181,7 @@ def test_grouped_pauli_channel(config): sim = Simulator(virtual_qc, n_qubits, dtype=dtype) circ1 = (old + paulis).measure_all() circ2 = (old + grouped).measure_all() - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): sim.apply_circuit(circ1.remove_measure()) qs1 = sim.get_qs() sim.reset() @@ -221,7 +221,7 @@ def test_thermal_relaxation_channel(config): ref_dm = np.array([[mat[0][0] + mat[2][2], mat[0][1] + mat[2][1]], [mat[1][0] + mat[3][2], mat[1][1] + mat[3][3]]]) sim = Simulator(virtual_qc, 1, dtype=dtype) sim.set_qs(init_state) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): sim.apply_gate(c) assert np.allclose(sim.get_qs(), ref_dm) else: diff --git a/tests/st/test_simulator/test_method_of_mqmatrix.py b/tests/st/test_simulator/test_method_of_mqmatrix.py index b2866bd60..95e91c079 100644 --- a/tests/st/test_simulator/test_method_of_mqmatrix.py +++ b/tests/st/test_simulator/test_method_of_mqmatrix.py @@ -14,7 +14,7 @@ # ============================================================================ # pylint: disable=invalid-name -"""Test method of mqmatrix simulator.""" +"""Test method of quafumatrix simulator.""" import numpy as np import pytest @@ -22,20 +22,20 @@ from scipy.sparse import csr_matrix from scipy.stats import entropy -import mindquantum as mq -from mindquantum.core import gates as G -from mindquantum.core.circuit import UN, Circuit -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.simulator import Simulator, fidelity -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR -from mindquantum.utils import random_circuit, random_hamiltonian +import quafu +from quafu.core import gates as G +from quafu.core.circuit import UN, Circuit +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.simulator import Simulator, fidelity +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.utils import random_circuit, random_hamiltonian @pytest.mark.level0 @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize("virtual_qc", ['mqmatrix']) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("virtual_qc", ['quafumatrix']) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_set_qs_and_dm(virtual_qc, dtype): """ Description: test setting density matrix @@ -58,8 +58,8 @@ def test_set_qs_and_dm(virtual_qc, dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize("virtual_qc", ['mqmatrix']) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("virtual_qc", ['quafumatrix']) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_get_partial_trace(virtual_qc, dtype): """ Description: test partial trace of density matrix @@ -79,8 +79,8 @@ def test_get_partial_trace(virtual_qc, dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize("virtual_qc", ['mqmatrix']) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("virtual_qc", ['quafumatrix']) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_purity(virtual_qc, dtype): """ Description: test purity of density matrix @@ -98,8 +98,8 @@ def test_purity(virtual_qc, dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize("virtual_qc", ['mqmatrix']) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("virtual_qc", ['quafumatrix']) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_get_pure_state_vector(virtual_qc, dtype): """ Description: test get pure state vector from density matrix @@ -158,7 +158,7 @@ def test_sampling(config): sim = Simulator(virtual_qc, 2, dtype=dtype) sim.set_qs(qs) res = sim.sampling(Circuit(UN(G.Measure(), [0, 1])), shots=shots) - if virtual_qc.startswith("mqmatrix"): + if virtual_qc.startswith("quafumatrix"): ref_distribution = sim.get_qs().diagonal().real else: ref_distribution = np.abs(qs) ** 2 @@ -262,7 +262,7 @@ def test_get_expectation_with_grad_batch_hams(config): # pylint: disable=too-many-locals virtual_qc, dtype = config init_state_circ = UN(G.H, range(5)) - ansatz = mq.MaxCutAnsatz([(0, 1), (1, 2), (2, 3), (3, 4), (0, 4), (0, 2)], 4).circuit + ansatz = quafu.MaxCutAnsatz([(0, 1), (1, 2), (2, 3), (3, 4), (0, 4), (0, 2)], 4).circuit circ = init_state_circ + ansatz sim = Simulator(virtual_qc, 5, dtype=dtype) @@ -308,7 +308,7 @@ def three_qubits_dm_evolution_in_py(dm, g, dtype): Expectation: success. """ if isinstance(g, G.NoiseGate): - tmp = np.zeros((8, 8), dtype=mq.to_np_type(dtype)) + tmp = np.zeros((8, 8), dtype=quafu.to_np_type(dtype)) for m in g.matrix(): if g.obj_qubits[0] == 0: big_m = np.kron(np.eye(4, 4), m) @@ -332,8 +332,8 @@ def three_qubits_dm_evolution_in_py(dm, g, dtype): @pytest.mark.level0 @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard -@pytest.mark.parametrize("virtual_qc", ['mqmatrix']) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("virtual_qc", ['quafumatrix']) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_noise_get_expectation_with_grad(virtual_qc, dtype): """ Description: test noise circuit get expectation with gradient @@ -391,7 +391,7 @@ def test_entropy(config): sim = Simulator(virtual_qc, 3, dtype=dtype) sim.apply_circuit(circ) e = sim.entropy() - if virtual_qc.startswith('mqvector'): + if virtual_qc.startswith('quafuvector'): ref_entropy = 0 else: dm = sim.get_qs() @@ -420,9 +420,9 @@ def test_fidelity(config1, config2): qs1 = sim1.get_qs() qs2 = sim2.get_qs() f = fidelity(qs1, qs2) - if virtual_qc1.startswith('mqvector'): + if virtual_qc1.startswith('quafuvector'): qs1 = np.outer(qs1, qs1.conj().T) - if virtual_qc2.startswith('mqvector'): + if virtual_qc2.startswith('quafuvector'): qs2 = np.outer(qs2, qs2.conj().T) ref_f = np.trace(sqrtm(sqrtm(qs1) @ qs2 @ sqrtm(qs1))).real ** 2 assert np.allclose(f, ref_f, atol=1e-3) diff --git a/tests/st/test_simulator/test_method_of_mqvector.py b/tests/st/test_simulator/test_method_of_mqvector.py index 3a81c6efd..9685a6231 100644 --- a/tests/st/test_simulator/test_method_of_mqvector.py +++ b/tests/st/test_simulator/test_method_of_mqvector.py @@ -13,18 +13,18 @@ # limitations under the License. # ============================================================================ -"""Test method of mqvector simulator.""" +"""Test method of quafuvector simulator.""" import subprocess import numpy as np import pytest from scipy.sparse import csr_matrix -import mindquantum as mq -from mindquantum.core import gates as G -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.simulator import Simulator -from mindquantum.utils import random_circuit, random_hamiltonian +import quafu +from quafu.core import gates as G +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.simulator import Simulator +from quafu.utils import random_circuit, random_hamiltonian _HAS_GPU = False @@ -53,11 +53,11 @@ @pytest.mark.parametrize( "virtual_qc", [ - 'mqvector', - pytest.param('mqvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), + 'quafuvector', + pytest.param('quafuvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), ], ) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_get_expectation(virtual_qc, dtype): """ Description: test get expectation @@ -121,11 +121,11 @@ def test_get_expectation(virtual_qc, dtype): @pytest.mark.parametrize( "virtual_qc", [ - 'mqvector', - pytest.param('mqvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), + 'quafuvector', + pytest.param('quafuvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), ], ) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_non_hermitian_get_expectation_with_grad(virtual_qc, dtype): """ Description: test get expectation @@ -198,11 +198,11 @@ def test_non_hermitian_get_expectation_with_grad(virtual_qc, dtype): @pytest.mark.parametrize( "virtual_qc", [ - 'mqvector', - pytest.param('mqvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), + 'quafuvector', + pytest.param('quafuvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), ], ) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_parameter_shift_rule(virtual_qc, dtype): # pylint: disable=too-many-locals """ Description: test parameter shift rule @@ -235,11 +235,11 @@ def test_parameter_shift_rule(virtual_qc, dtype): # pylint: disable=too-many-lo @pytest.mark.parametrize( "virtual_qc", [ - 'mqvector', - pytest.param('mqvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), + 'quafuvector', + pytest.param('quafuvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), ], ) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) @pytest.mark.skipif(not _HAS_NUMBA, reason='Numba is not installed') def test_parameter_shift_rule_finite_diff_case(virtual_qc, dtype): # pylint: disable=too-many-locals """ diff --git a/tests/st/test_simulator/test_simulator.py b/tests/st/test_simulator/test_simulator.py index 86d414539..2b203e191 100644 --- a/tests/st/test_simulator/test_simulator.py +++ b/tests/st/test_simulator/test_simulator.py @@ -22,30 +22,30 @@ import pytest from scipy.sparse import csr_matrix -import mindquantum as mq -import mindquantum.core.operators as ops -from mindquantum.algorithm.library import qft -from mindquantum.algorithm.nisq import Ansatz6 -from mindquantum.core import gates as G -from mindquantum.core.circuit import ( +import quafu +import quafu.core.operators as ops +from quafu.algorithm.library import qft +from quafu.algorithm.nisq import Ansatz6 +from quafu.core import gates as G +from quafu.core.circuit import ( UN, BitFlipAdder, Circuit, MeasureAccepter, MixerAdder, ) -from mindquantum.core.operators import Hamiltonian, QubitOperator -from mindquantum.core.parameterresolver import ParameterResolver as PR -from mindquantum.simulator import NoiseBackend, Simulator, inner_product -from mindquantum.simulator.available_simulator import SUPPORTED_SIMULATOR -from mindquantum.utils import random_circuit +from quafu.core.operators import Hamiltonian, QubitOperator +from quafu.core.parameterresolver import ParameterResolver as PR +from quafu.simulator import NoiseBackend, Simulator, inner_product +from quafu.simulator.available_simulator import SUPPORTED_SIMULATOR +from quafu.utils import random_circuit _HAS_MINDSPORE = True try: import mindspore as ms - from mindquantum.framework.layer import ( # pylint: disable=ungrouped-imports - MQAnsatzOnlyLayer, + from quafu.framework.layer import ( # pylint: disable=ungrouped-imports + QUAFUAnsatzOnlyLayer, ) ms.context.set_context(mode=ms.context.PYNATIVE_MODE, device_target="CPU") @@ -77,14 +77,14 @@ @pytest.mark.env_onecard @pytest.mark.skipif(platform.system() != 'Linux', reason='GPU backend only available for linux.') @pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.') -@pytest.mark.parametrize("dtype", [mq.complex128, mq.complex64]) +@pytest.mark.parametrize("dtype", [quafu.complex128, quafu.complex64]) def test_gpu(dtype): """ test gpu Description: to make sure gpu platform was tested. Expectation: gpu backend not available. """ - sim = Simulator('mqvector_gpu', 1, dtype=dtype) + sim = Simulator('quafuvector_gpu', 1, dtype=dtype) sim.apply_circuit(Circuit().h(0)) v = sim.get_qs() assert np.allclose(v, np.ones_like(v) / np.sqrt(2)) @@ -109,7 +109,7 @@ def test_init_reset(config): s1.reset() v3 = s1.get_qs() v = np.array([1, 0, 0, 0], dtype=np.complex128) - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": assert np.allclose(v1, np.outer(v, v.conj())) assert np.allclose(v1, v3) else: @@ -148,7 +148,7 @@ def test_apply_circuit_and_hermitian(config): matrix = G.Rzz(10).matrix() @ matrix matrix = (np.kron(G.I.matrix(), sv0) + np.kron(G.Z.matrix(), sv1)) @ matrix v = matrix[:, 0] - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": m = np.outer(v, v.conj()) assert np.allclose(m, v1) else: @@ -160,7 +160,7 @@ def test_apply_circuit_and_hermitian(config): matrix = np.conj(matrix.T) v1 = s1.get_qs() v = matrix[:, 0] - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": m = np.outer(v, v.conj()) assert np.allclose(m, v1) else: @@ -181,13 +181,13 @@ def test_set_and_get(config): virtual_qc, dtype = config sim = Simulator(virtual_qc, 1, dtype=dtype) qs1 = sim.get_qs() - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": assert np.allclose(qs1, np.array([[1, 0], [0, 0]])) else: assert np.allclose(qs1, np.array([1, 0])) sim.set_qs(np.array([1, 1])) qs2 = sim.get_qs() - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": assert np.allclose(qs2, np.array([[0.5, 0.5], [0.5, 0.5]])) sim.set_qs(np.array([[1, 1], [1, 1]])) qs2 = sim.get_qs() @@ -208,7 +208,7 @@ def test_non_hermitian_grad_ops1(config): Expectation: """ virtual_qc, dtype = config - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': return sim = Simulator(virtual_qc, 1, dtype=dtype) c_r = Circuit().ry('b', 0) @@ -287,7 +287,7 @@ def test_all_gate_with_simulator(config): # pylint: disable=too-many-locals -0.17429908 + 0.27887826j, ] ) - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": assert np.allclose(qs, np.outer(qs_exp, qs_exp.conj())) else: assert np.allclose(qs, qs_exp) @@ -303,7 +303,7 @@ def test_all_gate_with_simulator(config): # pylint: disable=too-many-locals g_a_1 = g1[0, 0, 0] g_a_2 = g2[0, 0, 0] atol = 1e-3 - if dtype == mq.complex64: + if dtype == quafu.complex64: atol = 1e-1 assert np.allclose(g_a, g_a_1, atol=atol) assert np.allclose(g_a, g_a_2, atol=atol) @@ -346,8 +346,8 @@ def _diff_matrix(theta): grad_ops2 = sim.get_expectation_with_grad(ham, circuit2) ms.context.set_context(mode=ms.context.PYNATIVE_MODE, device_target="CPU") init_data = ms.Tensor(np.array([1.2]).astype(np.float32)) - net1 = MQAnsatzOnlyLayer(grad_ops1, weight=init_data) - net2 = MQAnsatzOnlyLayer(grad_ops2, weight=init_data) + net1 = QUAFUAnsatzOnlyLayer(grad_ops1, weight=init_data) + net2 = QUAFUAnsatzOnlyLayer(grad_ops2, weight=init_data) opti1 = ms.nn.Adam(net1.trainable_params(), learning_rate=0.1) opti2 = ms.nn.Adam(net2.trainable_params(), learning_rate=0.1) train1 = ms.nn.TrainOneStepCell(net1, opti1) @@ -369,7 +369,7 @@ def test_fid(config): Expectation: """ virtual_qc, dtype = config - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': return sim1 = Simulator(virtual_qc, 1, dtype=dtype) prep_circ = Circuit().h(0) @@ -393,7 +393,7 @@ def test_non_hermitian_grad_ops2(config): Expectation: success. """ virtual_qc, dtype = config - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': return circuit1 = Circuit([G.RX('a').on(0)]) circuit2 = Circuit([G.RY('b').on(0)]) @@ -426,8 +426,8 @@ def test_csr_ham(config): f_exp = np.conj(circ.matrix(np.array([1, 2])).T) @ ham.sparse_matrix.toarray() @ circ.matrix(np.array([1, 2])) f_exp = f_exp[0, 0] assert np.allclose(f, f_exp) - if virtual_qc == 'mqmatrix': - sim2 = Simulator('mqvector', 1, dtype=dtype) + if virtual_qc == 'quafumatrix': + sim2 = Simulator('quafuvector', 1, dtype=dtype) grad_ops2 = sim2.get_expectation_with_grad(ham, circ) _, g2 = grad_ops2(np.array([1, 2])) assert np.allclose(g, g2) @@ -435,7 +435,7 @@ def test_csr_ham(config): sim.apply_hamiltonian(ham) qs = sim.get_qs() qs_exp = ham.sparse_matrix.toarray() @ circ.matrix(np.array([1, 2])) @ np.array([1, 0]) - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': assert np.allclose(qs, np.outer(qs_exp, qs_exp.conj())) else: assert np.allclose(qs, qs_exp) @@ -452,7 +452,7 @@ def test_inner_product(config): Expectation: success. """ virtual_qc, dtype = config - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': return sim1 = Simulator(virtual_qc, 1, dtype=dtype) sim1.apply_gate(G.RX(1.2).on(0)) @@ -481,7 +481,7 @@ def test_copy(config): sim.reset() qs1 = sim.get_qs() qs2 = sim2.get_qs() - if virtual_qc == 'mqmatrix' and dtype == mq.complex64: + if virtual_qc == 'quafumatrix' and dtype == quafu.complex64: assert np.allclose(qs1, qs2, atol=1.0e-6) else: assert np.allclose(qs1, qs2, atol=1e-6) @@ -499,8 +499,8 @@ def test_univ_order(config): """ virtual_qc, dtype = config r_c = random_circuit(2, 100) - if virtual_qc == 'mqmatrix': - u = r_c.matrix(backend='mqvector', dtype=dtype) + if virtual_qc == 'quafumatrix': + u = r_c.matrix(backend='quafuvector', dtype=dtype) assert np.allclose(r_c.get_qs(backend=virtual_qc, dtype=dtype), np.outer(u[:, 0], np.conj(u[:, 0])), atol=1e-6) else: u = r_c.matrix(backend=virtual_qc, dtype=dtype) @@ -508,7 +508,7 @@ def test_univ_order(config): g = G.UnivMathGate('u', u) c0 = Circuit([g.on([0, 1])]) c1 = Circuit([g.on([1, 0])]) - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': assert np.allclose(c0.get_qs(backend=virtual_qc, dtype=dtype), np.outer(u[:, 0], np.conj(u[:, 0])), atol=1e-6) v_tmp = np.array([u[0, 0], u[2, 0], u[1, 0], u[3, 0]]) assert np.allclose(c1.get_qs(backend=virtual_qc, dtype=dtype), np.outer(v_tmp, np.conj(v_tmp)), atol=1e-6) @@ -536,7 +536,7 @@ def test_multi_params_gate(config): p0 = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) sim.apply_circuit(circ, pr=dict(zip(circ.params_name, p0))) qs_exp = np.array([0.06207773 + 0.0j, 0.12413139 + 0.44906334j, 0.10068061 - 0.05143708j, 0.65995413 + 0.57511569j]) - if virtual_qc == "mqmatrix": + if virtual_qc == "quafumatrix": assert np.allclose(np.outer(qs_exp, qs_exp.conj()), sim.get_qs()) else: assert np.allclose(qs_exp, sim.get_qs()) @@ -599,7 +599,7 @@ def test_cd_term(config): Expectation: """ virtual_qc, dtype = config - if virtual_qc == 'mqmatrix': + if virtual_qc == 'quafumatrix': return cd_term = [G.Rxy, G.Rxz, G.Ryz] for g in cd_term: @@ -684,11 +684,11 @@ def test_mul_qubit_gate(config): @pytest.mark.parametrize( "virtual_qc", [ - 'mqvector', - pytest.param('mqvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), + 'quafuvector', + pytest.param('quafuvector_gpu', marks=pytest.mark.skipif(not _HAS_GPU, reason='Machine does not has GPU.')), ], ) -@pytest.mark.parametrize("dtype", [mq.complex64, mq.complex128]) +@pytest.mark.parametrize("dtype", [quafu.complex64, quafu.complex128]) def test_non_hermitian_expectation(virtual_qc, dtype): """ Description: Test get expectation with non hermitian situation. @@ -727,9 +727,9 @@ def test_noise_simulator(config): ) sim = Simulator(NoiseBackend(virtual_qc, 2, adder=adder, dtype=dtype)) res = sim.sampling(circ, seed=42, shots=5000) - if virtual_qc.startswith('mqvector'): + if virtual_qc.startswith('quafuvector'): assert res.data['00'] == 1701 - elif virtual_qc.startswith('mqmatrix'): + elif virtual_qc.startswith('quafumatrix'): assert res.data['00'] == 1684 @@ -771,8 +771,8 @@ def test_parameter_shift_rule(): else: new_c += i c = new_c - sim1 = Simulator('mqvector', c.n_qubits) - sim2 = Simulator('mqvector', c.n_qubits) + sim1 = Simulator('quafuvector', c.n_qubits) + sim2 = Simulator('quafuvector', c.n_qubits) ham = Hamiltonian(QubitOperator('Z0 Y1 X2')) grad_ops1 = sim1.get_expectation_with_grad(ham, c, parallel_worker=5) noise_c = c + G.AmplitudeDampingChannel(0.0).on(0) diff --git a/tests/st/test_simulator/test_stabilizer.py b/tests/st/test_simulator/test_stabilizer.py index 3dad2ee28..a7d896198 100644 --- a/tests/st/test_simulator/test_stabilizer.py +++ b/tests/st/test_simulator/test_stabilizer.py @@ -17,19 +17,19 @@ from scipy.stats import entropy import pytest -from mindquantum import _mq_vector -from mindquantum.algorithm.error_mitigation import ( +from quafu import _quafu_vector +from quafu.algorithm.error_mitigation import ( query_double_qubits_clifford_elem, query_single_qubit_clifford_elem, ) -from mindquantum.core.circuit import Circuit -from mindquantum.simulator import ( +from quafu.core.circuit import Circuit +from quafu.simulator import ( Simulator, decompose_stabilizer, get_stabilizer_string, get_tableau_string, ) -from mindquantum.utils import random_clifford_circuit, random_hamiltonian +from quafu.utils import random_clifford_circuit, random_hamiltonian @pytest.mark.level0 @@ -39,7 +39,7 @@ def test_stabilizer(): Description: Test stabilizer simulator. Expectation: """ - _mq_vector.stabilizer.verify() # pylint: disable=no-member + _quafu_vector.stabilizer.verify() # pylint: disable=no-member for i in range(11520): clifford = query_double_qubits_clifford_elem(i) @@ -94,7 +94,7 @@ def test_stabilizer_sampling(): clifford = random_clifford_circuit(n_qubits, length).measure_all() sim = Simulator('stabilizer', clifford.n_qubits) res_clifford = sim.sampling(clifford, shots=10000) - res_state_vector = Simulator('mqvector', clifford.n_qubits).sampling(clifford, shots=10000) + res_state_vector = Simulator('quafuvector', clifford.n_qubits).sampling(clifford, shots=10000) keys = set(res_clifford.data.keys()) | set(res_state_vector.data.keys()) dis1 = np.array([res_clifford.data.get(key, 0) for key in keys]) / res_clifford.shots @@ -109,7 +109,7 @@ def test_stabilizer_expectation(): Expectation: """ sim = Simulator('stabilizer', 4) - ref_sim = Simulator('mqvector', 4) + ref_sim = Simulator('quafuvector', 4) rc = random_clifford_circuit(4, 20) rh = random_hamiltonian(4, 20) exp_val = sim.get_expectation(rh, rc) diff --git a/tests/st/test_utils/test_f.py b/tests/st/test_utils/test_f.py index ac6e4b195..e702a8d3c 100755 --- a/tests/st/test_utils/test_f.py +++ b/tests/st/test_utils/test_f.py @@ -16,8 +16,8 @@ import numpy as np -from mindquantum.simulator import Simulator, decompose_stabilizer -from mindquantum.utils import f +from quafu.simulator import Simulator, decompose_stabilizer +from quafu.utils import f def test_mod(): diff --git a/tests/ut/__init__.py b/tests/ut/__init__.py index 88a5822ec..75c770472 100644 --- a/tests/ut/__init__.py +++ b/tests/ut/__init__.py @@ -13,4 +13,4 @@ # limitations under the License. # ============================================================================ -"""MindQuantum ut test module.""" +"""quafu ut test module.""" diff --git a/tests/ut/test_mindquantum.py b/tests/ut/test_quafu.py similarity index 97% rename from tests/ut/test_mindquantum.py rename to tests/ut/test_quafu.py index 05c3087bb..81037faa0 100644 --- a/tests/ut/test_mindquantum.py +++ b/tests/ut/test_quafu.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -"""Test mindquantum.""" +"""Test quafu.""" # test diff --git a/tests/utils/mindquantum/catch2/catch2_fmt_formatter.h b/tests/utils/quafu/catch2/catch2_fmt_formatter.h similarity index 100% rename from tests/utils/mindquantum/catch2/catch2_fmt_formatter.h rename to tests/utils/quafu/catch2/catch2_fmt_formatter.h diff --git a/tests/utils/mindquantum/catch2/complex.h b/tests/utils/quafu/catch2/complex.h similarity index 100% rename from tests/utils/mindquantum/catch2/complex.h rename to tests/utils/quafu/catch2/complex.h diff --git a/third_party/cmake/mindquantumTargetsExternal.cmake.in b/third_party/cmake/quafuTargetsExternal.cmake.in similarity index 100% rename from third_party/cmake/mindquantumTargetsExternal.cmake.in rename to third_party/cmake/quafuTargetsExternal.cmake.in