Skip to content

Commit 0c6a760

Browse files
committed
add qpu conf
1 parent 08b2794 commit 0c6a760

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

tencirchem/static/engine_hea.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
from 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])
2029
def 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

tencirchem/static/hea.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from tensorcircuit.noisemodel import NoiseConf, circuit_with_noise
3232

3333
from tencirchem.static.engine_hea import (
34+
QpuConf,
3435
get_statevector,
3536
get_densitymatrix,
3637
get_energy_tensornetwork,
@@ -436,7 +437,7 @@ def __init__(
436437
circuit: Union[Callable, QuantumCircuit],
437438
init_guess: Union[List[float], np.ndarray],
438439
engine: str = None,
439-
engine_conf: NoiseConf = None,
440+
engine_conf: [NoiseConf, QpuConf] = None,
440441
):
441442
"""
442443
Construct the HEA class from Hamiltonian in :class:`QubitOperator` form and the ansatz.
@@ -463,8 +464,11 @@ def __init__(
463464
engine = "tensornetwork"
464465
if engine == "tensornetwork" and engine_conf is not None:
465466
raise ValueError("Tensornetwork engine does not have engine configuration")
466-
if engine.startswith("tensornetwork-noise") and engine_conf is None:
467-
engine_conf = get_noise_conf()
467+
if engine_conf is None:
468+
if engine.startswith("tensornetwork-noise"):
469+
engine_conf = get_noise_conf()
470+
if engine.startswith("qpu"):
471+
engine_conf = QpuConf()
468472

469473
init_guess = np.array(init_guess)
470474

@@ -738,6 +742,7 @@ def energy(self, params: Tensor = None, engine: str = None) -> float:
738742
tuple(self.h_qubit_op.terms.keys()),
739743
list(self.h_qubit_op.terms.values()),
740744
self.get_circuit,
745+
self.engine_conf,
741746
self.shots,
742747
)
743748
return e

0 commit comments

Comments
 (0)