Skip to content

Commit

Permalink
Renamed cutn_attributes back to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloAndresCQ committed Jul 31, 2024
1 parent 07de8c2 commit 67e594f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
8 changes: 4 additions & 4 deletions pytket/extensions/cutensornet/backends/cutensornet_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def process_circuits(
Results handle objects.
"""
scratch_fraction = float(kwargs.get("scratch_fraction", 0.75)) # type: ignore
cutn_attributes = {
attributes = {
k: v for k, v in kwargs.items() if k in StateAttribute._member_names_
}

Expand All @@ -230,7 +230,7 @@ def process_circuits(
with CuTensorNetHandle() as libhandle:
for circuit in circuit_list:
tn = GeneralState(circuit, libhandle)
sv = tn.get_statevector(cutn_attributes, scratch_fraction)
sv = tn.get_statevector(attributes, scratch_fraction)
res_qubits = [qb for qb in sorted(circuit.qubits)]
handle = ResultHandle(str(uuid4()))
self._cache[handle] = {
Expand Down Expand Up @@ -297,7 +297,7 @@ def process_circuits(
Results handle objects.
"""
scratch_fraction = float(kwargs.get("scratch_fraction", 0.75)) # type: ignore
cutn_attributes = {
attributes = {
k: v for k, v in kwargs.items() if k in SamplerAttribute._member_names_
}

Expand Down Expand Up @@ -326,7 +326,7 @@ def process_circuits(
tn = GeneralState(circuit, libhandle)
handle = ResultHandle(str(uuid4()))
self._cache[handle] = {
"result": tn.sample(circ_shots, cutn_attributes, scratch_fraction)
"result": tn.sample(circ_shots, attributes, scratch_fraction)
}
handle_list.append(handle)
return handle_list
Expand Down
31 changes: 15 additions & 16 deletions pytket/extensions/cutensornet/general_state/tensor_network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def __init__(

def get_statevector(
self,
cutn_attributes: Optional[dict] = None,
attributes: Optional[dict] = None,
scratch_fraction: float = 0.75,
on_host: bool = True,
) -> Union[cp.ndarray, np.ndarray]:
"""Contracts the circuit and returns the final statevector.
Args:
cutn_attributes: Optional. A dict of cuTensorNet `StateAttribute` keys and
attributes: Optional. A dict of cuTensorNet `StateAttribute` keys and
their values.
scratch_fraction: Optional. Fraction of free memory on GPU to allocate as
scratch space.
Expand All @@ -136,10 +136,10 @@ def get_statevector(
####################################
# Configure the TN for contraction #
####################################
if cutn_attributes is None:
cutn_attributes = dict()
if attributes is None:
attributes = dict()
attribute_pairs = [
(getattr(cutn.StateAttribute, k), v) for k, v in cutn_attributes.items()
(getattr(cutn.StateAttribute, k), v) for k, v in attributes.items()
]

for attr, val in attribute_pairs:
Expand Down Expand Up @@ -228,14 +228,14 @@ def get_statevector(
def expectation_value(
self,
operator: QubitPauliOperator,
cutn_attributes: Optional[dict] = None,
attributes: Optional[dict] = None,
scratch_fraction: float = 0.75,
) -> complex:
"""Calculates the expectation value of the given operator.
Args:
operator: The operator whose expectation value is to be measured.
cutn_attributes: Optional. A dict of cuTensorNet `ExpectationAttribute` keys
attributes: Optional. A dict of cuTensorNet `ExpectationAttribute` keys
and their values.
scratch_fraction: Optional. Fraction of free memory on GPU to allocate as
scratch space.
Expand Down Expand Up @@ -310,11 +310,10 @@ def expectation_value(
self._lib.handle, self._state, tn_operator
)

if cutn_attributes is None:
cutn_attributes = dict()
if attributes is None:
attributes = dict()
attribute_pairs = [
(getattr(cutn.ExpectationAttribute, k), v)
for k, v in cutn_attributes.items()
(getattr(cutn.ExpectationAttribute, k), v) for k, v in attributes.items()
]

for attr, val in attribute_pairs:
Expand Down Expand Up @@ -407,14 +406,14 @@ def expectation_value(
def sample(
self,
n_shots: int,
cutn_attributes: Optional[dict] = None,
attributes: Optional[dict] = None,
scratch_fraction: float = 0.75,
) -> BackendResult:
"""Obtains samples from the measurements at the end of the circuit.
Args:
n_shots: The number of samples to obtain.
cutn_attributes: Optional. A dict of cuTensorNet `SamplerAttribute` keys and
attributes: Optional. A dict of cuTensorNet `SamplerAttribute` keys and
their values.
scratch_fraction: Optional. Fraction of free memory on GPU to allocate as
scratch space.
Expand Down Expand Up @@ -447,10 +446,10 @@ def sample(
modes_to_sample=measured_modes,
)

if cutn_attributes is None:
cutn_attributes = dict()
if attributes is None:
attributes = dict()
attribute_pairs = [
(getattr(cutn.SamplerAttribute, k), v) for k, v in cutn_attributes.items()
(getattr(cutn.SamplerAttribute, k), v) for k, v in attributes.items()
]

for attr, val in attribute_pairs:
Expand Down

0 comments on commit 67e594f

Please sign in to comment.