1616from tencirchem .utils .backend import jit
1717
1818
19+ class QpuConf :
20+ def __init__ (self , device = None , provider = None , initial_mapping = None ):
21+ if device is None :
22+ device = "tianji_s2"
23+ self .device = device
24+ self .privider = provider
25+ self .initial_mapping = initial_mapping
26+
27+
1928@partial (jit , static_argnums = [1 ])
2029def get_statevector (params , get_circuit ):
2130 return get_circuit (params ).state ()
@@ -73,7 +82,7 @@ def get_energy_tensornetwork_noise_shot(params, paulis, coeffs, get_dmcircuit, n
7382 return sample_expectation_pauli (c , paulis , coeffs , shots , noise_conf )
7483
7584
76- def get_energy_qpu (params , paulis , coeffs , get_circuit , shots : int ):
85+ def get_energy_qpu (params , paulis , coeffs , get_circuit , qpu_conf : QpuConf , shots : int ):
7786 c : Circuit = get_circuit (params )
7887 pss = []
7988 symbol_mapping = {"X" : 1 , "Y" : 2 , "Z" : 3 }
@@ -91,7 +100,7 @@ def get_energy_qpu(params, paulis, coeffs, get_circuit, shots: int):
91100 assert len (pss ) == len (coeffs_non_identity )
92101 es = []
93102 for _ in range ((shots - 1 ) // 8192 + 1 ):
94- e = batch_expectation_ps (c , pss , device = "tianji_s2" , ws = coeffs_non_identity , shots = 8192 )
103+ e = batch_expectation_ps (c , pss , device = qpu_conf . device , ws = coeffs_non_identity , shots = 8192 )
95104 es .append (e )
96105 print (paulis )
97106 print (coeffs )
@@ -158,10 +167,3 @@ def get_energy_and_grad_qpu(params, paulis, coeffs, get_circuit, shots: int, gra
158167 shots = shots ,
159168 )
160169 return _get_energy_and_grad (partial_get_energy , params , grad )
161-
162-
163- class QpuConf :
164- def __init__ (self , device = None , provider = None , initial_mapping = None ):
165- self .device = device
166- self .privider = provider
167- self .initial_mapping = initial_mapping
0 commit comments