Skip to content

Commit

Permalink
add gate method in circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdsdshe committed Oct 8, 2023
1 parent 034bce9 commit 61b5141
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 1 deletion.
84 changes: 83 additions & 1 deletion docs/api_python/mindquantum.core.circuit.Circuit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ mindquantum.core.circuit.Circuit
参数:
- **gates** (Union[Circuit, list[BasicGate]]) - `Circuit` 或 `BasicGate` 的list。

.. py:method:: fsim(theta, phi, obj_qubits, ctrl_qubits=None)
在电路中添加 `FSim` 门。

参数:
- **theta** (Union[dict, ParameterResolver]) - `FSim` 门的第一个参数。
- **phi** (Union[dict, ParameterResolver]) - `FSim` 门的第二个参数。
- **obj_qubits** (Union[int, list[int]]) - `FSim` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `FSim` 门的控制量子比特。默认值: ``None`` 。

.. py:method:: get_cpp_obj(hermitian=False)
获取线路的cpp object。
Expand All @@ -92,9 +102,18 @@ mindquantum.core.circuit.Circuit
- **seed** (int) - 模拟器的随机种子。默认值: ``None``。
- **dtype** (mindquantum.dtype) - 模拟器的数据类型。默认值: ``None``。

.. py:method:: global_phase(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `GlobalPhase` 门。

参数:
- **para** (Union[dict, ParameterResolver]) - `GlobalPhase` 门的参数。
- **obj_qubits** (Union[int, list[int]]) - `GlobalPhase` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `GlobalPhase` 门的控制量子比特。默认值: ``None`` 。

.. py:method:: h(obj_qubits, ctrl_qubits=None)
添加一个hadamard门
在电路中添加 `H` 门

参数:
- **obj_qubits** (Union[int, list[int]]) - `H` 门的目标量子比特。
Expand Down Expand Up @@ -136,6 +155,14 @@ mindquantum.core.circuit.Circuit
返回:
bool,线路是否有噪声信道。

.. py:method:: iswap(obj_qubits, ctrl_qubits=None)
在电路中添加 `ISWAP` 门。

参数:
- **obj_qubits** (Union[int, list[int]]) - `ISWAP` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `ISWAP` 门的控制量子比特。默认值: ``None``。

.. py:method:: matrix(pr=None, big_end=False, backend='mqvector', seed=None, dtype=None)
获取线路的矩阵表示。
Expand Down Expand Up @@ -255,6 +282,24 @@ mindquantum.core.circuit.Circuit
- **obj_qubits** (Union[int, list[int]]) - `Rxx` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `Rxx` 门的控制量子比特。默认值: ``None``。

.. py:method:: rxy(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `Rxy` 门。

参数:
- **para** (Union[dict, ParameterResolver]) - `Rxy` 门的参数。
- **obj_qubits** (Union[int, list[int]]) - `Rxy` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `Rxy` 门的控制量子比特。默认值: ``None``。

.. py:method:: rxz(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `Rxz` 门。

参数:
- **para** (Union[dict, ParameterResolver]) - `Rxz` 门的参数。
- **obj_qubits** (Union[int, list[int]]) - `Rxz` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `Rxz` 门的控制量子比特。默认值: ``None``。

.. py:method:: ry(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `RY` 门。
Expand All @@ -273,6 +318,15 @@ mindquantum.core.circuit.Circuit
- **obj_qubits** (Union[int, list[int]]) - `Ryy` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `Ryy` 门的控制量子比特。默认值: ``None``。

.. py:method:: ryz(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `Ryz` 门。

参数:
- **para** (Union[dict, ParameterResolver]) - `Ryz` 门的参数。
- **obj_qubits** (Union[int, list[int]]) - `Ryz` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `Ryz` 门的控制量子比特。默认值: ``None``。

.. py:method:: rz(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `RZ` 门。
Expand Down Expand Up @@ -322,6 +376,34 @@ mindquantum.core.circuit.Circuit
- **obj_qubits** (Union[int, list[int]]) - `SWAP` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `SWAP` 门的控制量子比特。默认值: ``None``。

.. py:method:: swap_alpha(para, obj_qubits, ctrl_qubits=None)
在电路中添加 `SWAPalpha` 门。

参数:
- **para** (Union[dict, ParameterResolver]) - `SWAPalpha` 门的参数。
- **obj_qubits** (Union[int, list[int]]) - `SWAPalpha` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `SWAPalpha` 门的控制量子比特。默认值: ``None`` 。

.. py:method:: t(obj_qubits, ctrl_qubits=None)
在电路中添加 `T` 门。

参数:
- **obj_qubits** (Union[int, list[int]]) - `T` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `T` 门的控制量子比特。默认值: ``None``。

.. py:method:: u3(theta, phi, lamda, obj_qubits, ctrl_qubits=None)
在电路中添加 `U3` 门。

参数:
- **theta** (Union[dict, ParameterResolver]) - `U3` 门的第一个参数。
- **phi** (Union[dict, ParameterResolver]) - `U3` 门的第二个参数。
- **lamda** (Union[dict, ParameterResolver]) - `U3` 门的第三个参数。
- **obj_qubits** (Union[int, list[int]]) - `U3` 门的目标量子比特。
- **ctrl_qubits** (Union[int, list[int]]) - `U3` 门的控制量子比特。默认值: ``None`` 。

.. py:method:: un(gate, maps_obj, maps_ctrl=None)
将量子门作用于多个目标量子比特和控制量子比特,详见类 :class:`~.core.circuit.UN` 。
Expand Down
109 changes: 109 additions & 0 deletions mindquantum/core/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,17 @@ def s(self, obj_qubits, ctrl_qubits=None):
self.append(mq_gates.S.on(obj_qubits, ctrl_qubits))
return self

def t(self, obj_qubits, ctrl_qubits=None):
"""
Add a T gate.
Args:
obj_qubits (Union[int, list[int]]): The object qubits of `T` gate.
ctrl_qubits (Union[int, list[int]]): the control qubits of `T` gate. Default: ``None``.
"""
self.append(mq_gates.T.on(obj_qubits, ctrl_qubits))
return self

def swap(self, obj_qubits, ctrl_qubits=None):
"""
Add a SWAP gate.
Expand All @@ -947,6 +958,29 @@ def swap(self, obj_qubits, ctrl_qubits=None):
self.append(mq_gates.SWAP.on(obj_qubits, ctrl_qubits))
return self

def iswap(self, obj_qubits, ctrl_qubits=None):
"""
Add a ISWAP gate.
Args:
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))
return self

def swap_alpha(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a SWAPalpha gate.
Args:
para (Union[dict, ParameterResolver]): The parameter for `SWAPalpha` gate.
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))
return self

def rx(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a RX gate.
Expand Down Expand Up @@ -995,6 +1029,32 @@ def phase_shift(self, para, obj_qubits, ctrl_qubits=None):
self.append(mq_gates.PhaseShift(para).on(obj_qubits, ctrl_qubits))
return self

def global_phase(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a Global Phase gate.
Args:
para (Union[dict, ParameterResolver]): The parameter for `GlobalPhase` gate.
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))
return self

def u3(self, theta, phi, lamda, obj_qubits, ctrl_qubits=None):
"""
Add a U3 gate.
Args:
theta (Union[dict, ParameterResolver]): First parameter for `U3` gate.
phi (Union[dict, ParameterResolver]): Second parameter for `U3` gate.
lamda (Union[dict, ParameterResolver]): Third parameter for `U3` gate.
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))
return self

def xx(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a XX gate.
Expand Down Expand Up @@ -1067,6 +1127,30 @@ def rxx(self, para, obj_qubits, ctrl_qubits=None):
self.append(mq_gates.Rxx(para).on(obj_qubits, ctrl_qubits))
return self

def rxy(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a Rxy gate.
Args:
para (Union[dict, ParameterResolver]): The parameter for `Rxy` gate.
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))
return self

def rxz(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a Rxz gate.
Args:
para (Union[dict, ParameterResolver]): The parameter for `Rxz` gate.
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))
return self

def ryy(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a Ryy gate.
Expand All @@ -1079,6 +1163,18 @@ def ryy(self, para, obj_qubits, ctrl_qubits=None):
self.append(mq_gates.Ryy(para).on(obj_qubits, ctrl_qubits))
return self

def ryz(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a Ryz gate.
Args:
para (Union[dict, ParameterResolver]): The parameter for `Ryz` gate.
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))
return self

def rzz(self, para, obj_qubits, ctrl_qubits=None):
"""
Add a Rzz gate.
Expand All @@ -1091,6 +1187,19 @@ def rzz(self, para, obj_qubits, ctrl_qubits=None):
self.append(mq_gates.Rzz(para).on(obj_qubits, ctrl_qubits))
return self

def fsim(self, theta, phi, obj_qubits, ctrl_qubits=None):
"""
Add a FSim gate.
Args:
theta (Union[dict, ParameterResolver]): First parameter for `FSim` gate.
phi (Union[dict, ParameterResolver]): Second parameter for `FSim` gate.
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))
return self

def measure(self, key, obj_qubit=None):
"""
Add a measure gate.
Expand Down

0 comments on commit 61b5141

Please sign in to comment.