4040 get_energy_and_grad_tensornetwork_noise_shot ,
4141)
4242from 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
4444from tencirchem .utils .circuit import get_circuit_dataframe
4545
4646logger = 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
0 commit comments