Skip to content

Commit 43088d8

Browse files
committed
fix marcus jupyter tutorial and add qubit mapping for hea
1 parent 2d4a09d commit 43088d8

File tree

6 files changed

+63
-34
lines changed

6 files changed

+63
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ h4 = M(atom=[["H", 0, 0, d * i] for i in range(4)])
3333

3434
# configuration
3535
uccsd = UCCSD(h4)
36-
# calculate
36+
# calculate and returns energy
3737
uccsd.kernel()
3838
# analyze result
3939
uccsd.print_summary(include_circuit=True)

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ h4 = M(atom=[["H", 0, 0, d * i] for i in range(4)])
3131

3232
# 配置
3333
uccsd = UCCSD(h4)
34-
# 计算
34+
# 计算并返回能量
3535
uccsd.kernel()
3636
# 分析结果
3737
uccsd.print_summary(include_circuit=True)

docs/source/tutorial_jupyter/marcus.ipynb

Lines changed: 45 additions & 26 deletions
Large diffs are not rendered by default.

example/ucc_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# setup
1010
uccsd = UCCSD(m)
11-
# calculate
11+
# calculate and returns energy
1212
uccsd.kernel()
1313
# analyze result
1414
uccsd.print_summary(include_circuit=True)

tencirchem/static/hea.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
get_energy_and_grad_tensornetwork_noise_shot,
4141
)
4242
from tencirchem.static.hamiltonian import get_hop_from_integral
43-
from tencirchem.utils.misc import reverse_fop_idx, scipy_opt_wrap
43+
from tencirchem.utils.misc import reverse_fop_idx, scipy_opt_wrap, reverse_qop_idx
4444
from tencirchem.utils.circuit import get_circuit_dataframe
4545

4646
logger = logging.getLogger(__file__)
@@ -153,11 +153,13 @@ def get_ry_circuit(params: Tensor, n_qubits: int, n_layers: int) -> Circuit:
153153
params = params.reshape(n_layers + 1, n_qubits)
154154
for i in range(n_qubits):
155155
c.ry(i, theta=params[0, i])
156+
c.barrier_instruction(*range(n_qubits))
156157
for l in range(n_layers):
157158
for i in range(n_qubits - 1):
158159
c.cnot(i, (i + 1))
159160
for i in range(n_qubits):
160161
c.ry(i, theta=params[l + 1, i])
162+
c.barrier_instruction(*range(n_qubits))
161163
return c
162164

163165

@@ -176,6 +178,7 @@ def ry(
176178
e_core: float,
177179
n_layers: int,
178180
init_circuit: Circuit = None,
181+
mapping: str = "parity",
179182
**kwargs,
180183
):
181184
"""
@@ -198,6 +201,8 @@ def ry(
198201
init_circuit: Circuit
199202
The initial circuit before the :math:`R_y` ansatz. Defaults to None,
200203
which creates an HF initial state.
204+
mapping: str
205+
The fermion to qubit mapping. Supported mappings are ``"parity"`` and ``"jordan-wigner"``.
201206
202207
kwargs:
203208
Other arguments to be passed to the :func:`__init__` function such as ``engine``.
@@ -208,7 +213,13 @@ def ry(
208213
An HEA instance
209214
"""
210215
n_sorb = 2 * len(int1e)
211-
n_qubits = n_sorb - 2
216+
if mapping == "parity":
217+
n_qubits = n_sorb - 2
218+
elif mapping == "jordan-wigner":
219+
n_qubits = n_sorb
220+
else:
221+
raise ValueError(f"Unknown mapping: {mapping}")
222+
212223
init_guess = np.random.random((n_layers + 1, n_qubits)).ravel()
213224

214225
def get_circuit(params):
@@ -218,7 +229,7 @@ def get_circuit(params):
218229
c = Circuit.from_qir(init_circuit.to_qir(), init_circuit.circuit_param)
219230
return c.append(get_ry_circuit(params, n_qubits, n_layers))
220231

221-
return cls.from_integral(int1e, int2e, n_elec, e_core, "parity", get_circuit, init_guess, **kwargs)
232+
return cls.from_integral(int1e, int2e, n_elec, e_core, mapping, get_circuit, init_guess, **kwargs)
222233

223234
@classmethod
224235
def from_integral(
@@ -266,7 +277,7 @@ def from_integral(
266277
if mapping == "parity":
267278
h_qubit_op = parity(hop, n_sorb, n_elec)
268279
elif mapping == "jordan-wigner":
269-
h_qubit_op = jordan_wigner(hop)
280+
h_qubit_op = reverse_qop_idx(jordan_wigner(hop))
270281
else:
271282
raise ValueError(f"Unknown mapping: {mapping}")
272283

tests/static/test_hea.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ def test_qiskit_circuit():
4343
e = hea.kernel()
4444
np.testing.assert_allclose(e, uccsd.e_fci, atol=1e-5)
4545
hea.print_summary()
46-

0 commit comments

Comments
 (0)