Allow user to specify Pauli string pattern for expecation calculation [skip CI]
This commit is contained in:
@@ -12,12 +12,35 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
||||
super().__init__()
|
||||
import cuquantum # pylint: disable=import-error
|
||||
from cuquantum import cutensornet as cutn # pylint: disable=import-error
|
||||
|
||||
|
||||
self.pauli_string_pattern = "XXXZ"
|
||||
if runcard is not None:
|
||||
self.MPI_enabled = runcard.get("MPI_enabled", False)
|
||||
self.MPS_enabled = runcard.get("MPS_enabled", False)
|
||||
self.NCCL_enabled = runcard.get("NCCL_enabled", False)
|
||||
self.expectation_enabled = runcard.get("expectation_enabled", False)
|
||||
|
||||
expectation_enabled_value = runcard.get('expectation_enabled')
|
||||
|
||||
if expectation_enabled_value is True:
|
||||
self.expectation_enabled = True
|
||||
|
||||
print("expectation_enabled is",self.expectation_enabled)
|
||||
elif expectation_enabled_value is False:
|
||||
self.expectation_enabled = False
|
||||
|
||||
print("expectation_enabled is",self.expectation_enabled)
|
||||
elif isinstance(expectation_enabled_value, dict):
|
||||
self.expectation_enabled = True
|
||||
expectation_enabled_dict = runcard.get('expectation_enabled', {})
|
||||
|
||||
self.pauli_string_pattern = expectation_enabled_dict.get('pauli_string_pattern', None)
|
||||
|
||||
print("expectation_enabled is a dictionary",self.expectation_enabled,self.pauli_string_pattern )
|
||||
else:
|
||||
raise TypeError("expectation_enabled has an unexpected type")
|
||||
|
||||
|
||||
|
||||
else:
|
||||
self.MPI_enabled = False
|
||||
self.MPS_enabled = False
|
||||
@@ -144,7 +167,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
||||
if initial_state is not None:
|
||||
raise_error(NotImplementedError, "QiboTN cannot support initial state.")
|
||||
|
||||
state = eval.expectation_pauli_tn(circuit, self.dtype)
|
||||
state = eval.expectation_pauli_tn(circuit, self.dtype, self.pauli_string_pattern)
|
||||
|
||||
elif (
|
||||
self.MPI_enabled == True
|
||||
@@ -155,7 +178,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
||||
if initial_state is not None:
|
||||
raise_error(NotImplementedError, "QiboTN cannot support initial state.")
|
||||
|
||||
state, rank = eval.expectation_pauli_tn_MPI(circuit, self.dtype, 32)
|
||||
state, rank = eval.expectation_pauli_tn_MPI(circuit, self.dtype, self.pauli_string_pattern, 32)
|
||||
|
||||
if rank > 0:
|
||||
state = np.array(0)
|
||||
@@ -169,7 +192,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
||||
if initial_state is not None:
|
||||
raise_error(NotImplementedError, "QiboTN cannot support initial state.")
|
||||
|
||||
state, rank = eval.expectation_pauli_tn_nccl(circuit, self.dtype, 32)
|
||||
state, rank = eval.expectation_pauli_tn_nccl(circuit, self.dtype, self.pauli_string_pattern, 32)
|
||||
|
||||
if rank > 0:
|
||||
state = np.array(0)
|
||||
|
||||
Reference in New Issue
Block a user