Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
NVIDIA
GitHub Repository: NVIDIA/cuda-q-academic
Path: blob/main/chemistry-simulations/aux_files/qmmm/qchem/particle_operator.py
1165 views
1
import numpy as np
2
from cudaq import spin
3
4
5
def one_particle_op(p, q):
6
7
if p == q:
8
qubit_op_dm = 0.5 * spin.i(p)
9
qubit_op_dm -= 0.5 * spin.z(p)
10
11
else:
12
coef = 1.0j
13
m = -0.25
14
if p > q:
15
p, q = q, p
16
coef = np.conj(coef)
17
18
# Compute the parity string (Z_{p+1}^{q-1})
19
z_indices = [i for i in range(p + 1, q)]
20
parity_string = 1.0
21
for i in z_indices:
22
parity_string *= spin.z(i)
23
24
qubit_op_dm = m * spin.x(p) * parity_string * spin.x(q)
25
qubit_op_dm += m * spin.y(p) * parity_string * spin.y(q)
26
qubit_op_dm -= coef * m * spin.y(p) * parity_string * spin.x(q)
27
qubit_op_dm += coef * m * spin.x(p) * parity_string * spin.y(q)
28
29
return qubit_op_dm
30
31