From 67e594f6056be62024c0a99bfd558e4edfddf44e Mon Sep 17 00:00:00 2001 From: PabloAndresCQ Date: Wed, 31 Jul 2024 12:33:05 +0100 Subject: [PATCH] Renamed cutn_attributes back to attributes --- .../backends/cutensornet_backend.py | 8 ++--- .../general_state/tensor_network_state.py | 31 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/pytket/extensions/cutensornet/backends/cutensornet_backend.py b/pytket/extensions/cutensornet/backends/cutensornet_backend.py index ecbea9a7..b09d33c0 100644 --- a/pytket/extensions/cutensornet/backends/cutensornet_backend.py +++ b/pytket/extensions/cutensornet/backends/cutensornet_backend.py @@ -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_ } @@ -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] = { @@ -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_ } @@ -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 diff --git a/pytket/extensions/cutensornet/general_state/tensor_network_state.py b/pytket/extensions/cutensornet/general_state/tensor_network_state.py index d2cffc0e..bedfc0f2 100644 --- a/pytket/extensions/cutensornet/general_state/tensor_network_state.py +++ b/pytket/extensions/cutensornet/general_state/tensor_network_state.py @@ -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. @@ -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: @@ -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. @@ -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: @@ -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. @@ -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: