文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

mindquantum.utils

Utils

mindquantum.utils.ket_string(state, tol=1e-07)[source]

Get the ket format of the quantum state.

Parameters
  • state (numpy.ndarray) – The input quantum state.

  • tol (float) – The ignore tolence for small amplitude. Default: 1e-7.

Returns

str, the ket format of the quantum state.

Examples

>>> import numpy as np
>>> from mindquantum.utils import ket_string
>>> state = np.array([1, -1j])/np.sqrt(2)
>>> print(ket_string(state))
['√2/2¦0⟩', '-√2/2j¦1⟩']
mindquantum.utils.mod(vec_in, axis=0)[source]

Calculate the mod of input vectors.

Parameters
Returns

numpy.ndarray, The mod of input vector.

Examples

>>> from mindquantum.utils import mod
>>> vec_in = np.array([[1, 2, 3], [4, 5, 6]])
>>> mod(vec_in)
array([[4.12310563, 5.38516481, 6.70820393]])
>>> mod(vec_in, 1)
array([[3.74165739],
       [8.77496439]])
mindquantum.utils.normalize(vec_in, axis=0)[source]

Normalize the input vectors based on specified axis.

Parameters
  • vec_in (Union[list[number], numpy.ndarray]) – Vector you want to normalize.

  • axis (int) – Along which axis you want to normalize your vector. Default: 0.

Returns

numpy.ndarray, Vector after normalization.

Examples

>>> from mindquantum.utils import normalize
>>> vec_in = np.array([[1, 2, 3], [4, 5, 6]])
>>> normalize(vec_in)
array([[0.24253563, 0.37139068, 0.4472136 ],
       [0.9701425 , 0.92847669, 0.89442719]])
>>> normalize(vec_in, 1)
array([[0.26726124, 0.53452248, 0.80178373],
       [0.45584231, 0.56980288, 0.68376346]])
mindquantum.utils.random_circuit(n_qubits, gate_num, sd_rate=0.5, ctrl_rate=0.2, seed=None)[source]

Generate a random circuit.

Parameters
  • n_qubits (int) – Number of qubits of random circuit.

  • gate_num (int) – Number of gates in random circuit.

  • sd_rate (float) – The rate of single qubit gate and double qubits gates.

  • ctrl_rate (float) – The possibility that a gate has a control qubit.

  • seed (int) – Random seed to generate random circuit.

Examples

>>> from mindquantum.utils import random_circuit
>>> random_circuit(3, 4, 0.5, 0.5, 100)
q1: ──Z────RX(0.944)────────●────────RX(-0.858)──
      │        │            │            │
q2: ──●────────●────────RZ(-2.42)────────●───────
mindquantum.utils.random_state(shapes, norm_axis=0, comp=True, seed=None)[source]

Generate some random quantum state.

Parameters
  • shapes (tuple) – shapes = (m, n) means m quantum states with each state formed by log2(n) qubits.

  • norm_axis (int) – which axis you want to apply normalization. Default: 0.

  • comp (bool) – if True, each amplitude of the quantum state will be a complex number. Default: True.

  • seed (int) – the random seed. Default: None.

Returns

numpy.ndarray, A normalized random quantum state.

Examples

>>> from mindquantum.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]])