From 907e455d46b3726053680fa565ef1e586900bf54 Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Tue, 5 Oct 2021 02:08:47 +0800 Subject: [PATCH 1/5] Update circuit.py --- paddle_quantum/circuit.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/paddle_quantum/circuit.py b/paddle_quantum/circuit.py index 2eba39f..dc4e8b9 100644 --- a/paddle_quantum/circuit.py +++ b/paddle_quantum/circuit.py @@ -59,6 +59,15 @@ def __init__(self, n): paddle.to_tensor(np.array([math.pi / 4])), paddle.to_tensor(np.array([-math.pi / 4]))] # Record history of adding gates to the circuit self.__history = [] + + def expand(self,new_n): + """ + 为原来的量子电路进行比特数扩展 + + Args: + new_n(int):扩展后的量子比特数 + """ + self.n = new_n def __add__(self, cir): r"""重载加法 ‘+’ 运算符,用于拼接两个维度相同的电路 From 70a3e5aec1ef0ad03895c45909a7e7a5761de578 Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Sun, 10 Oct 2021 21:16:40 +0800 Subject: [PATCH 2/5] Update utils.py --- paddle_quantum/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle_quantum/utils.py b/paddle_quantum/utils.py index a314ca4..74e6b10 100644 --- a/paddle_quantum/utils.py +++ b/paddle_quantum/utils.py @@ -914,14 +914,14 @@ def decompose_pauli_words(self): pass return self.coefficients, self.__pauli_words - def construct_h_matrix(self): + def construct_h_matrix(self,n_qubit): r"""构建 Hamiltonian 在 Z 基底下的矩阵。 Returns: np.ndarray: Z 基底下的哈密顿量矩阵形式 """ coefs, pauli_words, sites = self.decompose_with_sites() - n_qubit = 1 + assert n_qubit>=self.num_qubit,"输入的量子数不小于哈密顿量表达式中所对应的量子比特数" for site in sites: if type(site[0]) is int: n_qubit = max(n_qubit, max(site) + 1) From 89f1803706b9c4a9aa2a12349da42fb79f4afde3 Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:15:52 +0800 Subject: [PATCH 3/5] Update utils.py --- paddle_quantum/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/paddle_quantum/utils.py b/paddle_quantum/utils.py index 74e6b10..76718dd 100644 --- a/paddle_quantum/utils.py +++ b/paddle_quantum/utils.py @@ -914,14 +914,17 @@ def decompose_pauli_words(self): pass return self.coefficients, self.__pauli_words - def construct_h_matrix(self,n_qubit): + def construct_h_matrix(self): r"""构建 Hamiltonian 在 Z 基底下的矩阵。 Returns: np.ndarray: Z 基底下的哈密顿量矩阵形式 """ coefs, pauli_words, sites = self.decompose_with_sites() - assert n_qubit>=self.num_qubit,"输入的量子数不小于哈密顿量表达式中所对应的量子比特数" + n_qubit = 1 + for site in sites: + if type(site[0]) is int: + n_qubit = max(n_qubit, max(site) + 1) for site in sites: if type(site[0]) is int: n_qubit = max(n_qubit, max(site) + 1) From 71a17d570bf2686155dc28ac0806f085a9a572ea Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Fri, 15 Oct 2021 09:17:53 +0800 Subject: [PATCH 4/5] Update utils.py --- paddle_quantum/utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/paddle_quantum/utils.py b/paddle_quantum/utils.py index 76718dd..a314ca4 100644 --- a/paddle_quantum/utils.py +++ b/paddle_quantum/utils.py @@ -922,9 +922,6 @@ def construct_h_matrix(self): """ coefs, pauli_words, sites = self.decompose_with_sites() n_qubit = 1 - for site in sites: - if type(site[0]) is int: - n_qubit = max(n_qubit, max(site) + 1) for site in sites: if type(site[0]) is int: n_qubit = max(n_qubit, max(site) + 1) From 01665cb0ae6cae14c8a09f66fb2161dd326bdff6 Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Wed, 27 Oct 2021 13:51:52 +0800 Subject: [PATCH 5/5] Update circuit.py --- paddle_quantum/circuit.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/paddle_quantum/circuit.py b/paddle_quantum/circuit.py index dc4e8b9..2eba39f 100644 --- a/paddle_quantum/circuit.py +++ b/paddle_quantum/circuit.py @@ -59,15 +59,6 @@ def __init__(self, n): paddle.to_tensor(np.array([math.pi / 4])), paddle.to_tensor(np.array([-math.pi / 4]))] # Record history of adding gates to the circuit self.__history = [] - - def expand(self,new_n): - """ - 为原来的量子电路进行比特数扩展 - - Args: - new_n(int):扩展后的量子比特数 - """ - self.n = new_n def __add__(self, cir): r"""重载加法 ‘+’ 运算符,用于拼接两个维度相同的电路