Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface to "high-level" API (State, NetworkOperator and Expectation) #84

Merged
merged 68 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
034af98
Moved modules dealing with exact TN circuit representation to s separ…
yapolyak Jan 26, 2024
0c05f1f
Started drafting `TensorNetworkState` constructor (converter).
yapolyak Jan 26, 2024
00c5b21
Finished drafting `TensorNetworkState` constructor (converter).
yapolyak Jan 30, 2024
acdf958
Subtle changes to CuTensorNetHandle (untested).
yapolyak Jan 31, 2024
657740a
Some refurbishment. Renamed `TensorNetworkState` into `GeneralState`.…
yapolyak Feb 2, 2024
73a0e20
Merged `develop` in.
yapolyak Feb 2, 2024
94d7019
Refactoring folder name: exact -> general_state
yapolyak Feb 2, 2024
3516303
Started drafting `GeneralOperator`.
yapolyak Feb 2, 2024
6695940
Finished drafting `GeneralOperator` class.
yapolyak Feb 5, 2024
2df1abb
Started drafting `GeneralExpectationValue` class.
yapolyak Feb 5, 2024
c670749
Finished drafting `GeneralExpectationValue` class.
yapolyak Feb 7, 2024
bce7c95
Added `.configure()`, `.prepare()` and drafted `compute()` in `Genera…
yapolyak Feb 7, 2024
8a6dccf
Imports additions/refactor.
yapolyak Feb 18, 2024
b1d7295
Fix in `cutn` attributes.
yapolyak Feb 18, 2024
c196e4d
Fix a bug in `GeneralState.configure()`.
yapolyak Feb 18, 2024
0faf65a
Handle device aliasing bug fix.
yapolyak Feb 18, 2024
e4defcd
Corrected `cutn.state_compute()` arguments list.
yapolyak Feb 20, 2024
4cdb622
Fixed `cutn.state_compute()`.
yapolyak Feb 23, 2024
9e64915
Factored our configure and prepare steps for `GeneralExpectationValue`.
yapolyak Feb 23, 2024
c5df6df
Fixes to `GeneralState` after debugging.
yapolyak Feb 29, 2024
5cd6936
Fixes to `GeneralOperator` after debugging.
yapolyak Feb 29, 2024
fb34305
Fixes to `GeneralExpectationValue` after debugging.
yapolyak Feb 29, 2024
1eb091f
Added `state` and `operator` properties to corresponding classes.
yapolyak Mar 1, 2024
71aff80
Enabled chaining of some methods.
yapolyak Mar 1, 2024
627d475
`GeneralOperator` now accepts `QubitPauliOperator` as parameter.
yapolyak Mar 4, 2024
106b87d
Added statevector test.
yapolyak Mar 4, 2024
3d12261
Added gate unitary transpose to account for the way cuTN stores tensors
yapolyak Mar 6, 2024
cf30aa3
Added overlap test.
yapolyak Mar 7, 2024
3d477ad
Added a toffoli box with implicit swaps test and corresponding fix to…
yapolyak Mar 7, 2024
5a0f418
Added `test_generalised_toffoli_box`.
yapolyak Mar 11, 2024
f6fce3b
A couple of bug fixes.
yapolyak Mar 11, 2024
1f35487
Merge branch 'develop' into feature/exact_state
yapolyak Mar 11, 2024
be22f4c
Updated public API docs.
yapolyak Mar 11, 2024
4d72fa1
Addressed some of mypy issues.
yapolyak Mar 11, 2024
61efd3b
Some more types fixes (some are backwards).
yapolyak Mar 11, 2024
93e8601
More mypy tweaks.
yapolyak Mar 11, 2024
4b60441
Attempt to silence pytket mypy complains.
yapolyak Mar 11, 2024
6f42404
Merge branch 'develop' into feature/exact_state
PabloAndresCQ May 29, 2024
74a1037
Removed duplicated definition of destroy
PabloAndresCQ May 29, 2024
61995ec
Fixed broken import
PabloAndresCQ Jun 4, 2024
7c46299
Applying changes from comments
PabloAndresCQ Jun 4, 2024
b2d65a4
Fixing slip-up
PabloAndresCQ Jun 4, 2024
53162e4
Removing type ignores from imports
PabloAndresCQ Jun 4, 2024
c6b1c72
Removing more type ignores from imports
PabloAndresCQ Jun 4, 2024
3954fec
Removed invalid import
PabloAndresCQ Jun 4, 2024
26f848a
Moving CuTensorNetHandle to the general.py at the root of the module
PabloAndresCQ Jun 4, 2024
600568d
Fixing mypy complaints: removing top level init files
PabloAndresCQ Jun 4, 2024
7fc94cc
Made use of library handler safer
PabloAndresCQ Jun 4, 2024
f749bfd
Renamed test file
PabloAndresCQ Jun 4, 2024
074192c
Made changes on test
PabloAndresCQ Jun 4, 2024
ee64c55
Removing dead code from example
PabloAndresCQ Jun 4, 2024
1c6f5c9
Removed outdated comment
PabloAndresCQ Jun 5, 2024
2b12bce
Refactor of GeneralState so that it adheres to the upcoming format of…
PabloAndresCQ Jun 6, 2024
0e9526b
Fixed small bugs
PabloAndresCQ Jun 6, 2024
1ab3fe6
Removed _scratch_space and _work_desc attributes from GeneralState, b…
PabloAndresCQ Jun 6, 2024
301c9f0
Updated tests so that libhandle is reused and state.destroy() is call…
PabloAndresCQ Jun 6, 2024
b6108f3
Merge pull request #126 from CQCL/refactor/exact_state
PabloAndresCQ Jun 6, 2024
b8b713c
Applying overall phase on state vector. Copying circuit when passed t…
PabloAndresCQ Jun 7, 2024
9867c46
Fixing bug due to not using local copy of circuit
PabloAndresCQ Jun 7, 2024
d2b6e25
Adding more tests and fixing some issues
PabloAndresCQ Jun 7, 2024
4aeb976
Added a test for expectation values. Changed the name of some tests
PabloAndresCQ Jun 7, 2024
44f7d6b
Allowing complex expectation value
PabloAndresCQ Jun 7, 2024
bd8d512
Updated docs
PabloAndresCQ Jun 7, 2024
608df86
Fixing a complaint from pylint
PabloAndresCQ Jun 7, 2024
dfcdcf3
Updated changelog
PabloAndresCQ Jun 7, 2024
704c9dc
Removed default choice of NUM_HYPER_SAMPLES
PabloAndresCQ Jun 7, 2024
5ef76f5
Adding copyright notice to new files
PabloAndresCQ Jun 7, 2024
7186c63
Adding error message if circuit contains non-unitary gates
PabloAndresCQ Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Started drafting GeneralOperator.
  • Loading branch information
yapolyak committed Feb 2, 2024
commit 3516303a0cc12a1449d721a16a31d5ca34ba641b
PabloAndresCQ marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
except ImportError:
warnings.warn("local settings failed to import cupy", ImportWarning)
from pytket.circuit import Circuit # type: ignore
from pytket.pauli import QubitPauliString # type: ignore
from pytket.extensions.cutensornet.general import set_logger
from pytket.extensions.cutensornet.structured_state import CuTensorNetHandle

@@ -103,3 +104,40 @@ def update_gates(self, gates_update_map: dict) -> None:
cutn.state_update_tensor(
self._handle, self._state, gate_id, gate_tensor.data.ptr, 0, 1
)

def destroy(self):
"""Destroys tensor network state."""
cutn.destroy_state(self._state)


class GeneralOperator:
"""Handles tensor network operator."""
PabloAndresCQ marked this conversation as resolved.
Show resolved Hide resolved

def __init__(
self,
operator: list[tuple[float, QubitPauliString]],
num_qubits: int,
libhandle: CuTensorNetHandle,
loglevel: int = logging.INFO,
) -> None:
"""Constructs a tensor network operator.

From a list of Pauli strings and corresponding coefficients.

Args:
operator: List of tuples, containing a Paulistring and a corresponding
numeric coefficient.
num_qubits: Number of qubits in a circuit for which operator is to be defined.
libhandle: cuTensorNet handle.
loglevel: Internal logger output level.
"""
self._logger = set_logger("GeneralOperator", loglevel)
self._handle = libhandle.handle
qubits_dims = (2,) * num_qubits
data_type = cq.cudaDataType.CUDA_C_64F # TODO: implement a config class?
PabloAndresCQ marked this conversation as resolved.
Show resolved Hide resolved
self._operator = cutn.create_network_operator(
self._handle, num_qubits, qubits_dims, data_type
)

def append_pauli_string(self, pauli_string: QubitPauliString, coeff: float) -> None:
pass
7 changes: 5 additions & 2 deletions pytket/extensions/cutensornet/structured_state/general.py
PabloAndresCQ marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -69,8 +69,7 @@ def __enter__(self) -> CuTensorNetHandle:
return self

def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None:
cutn.destroy(self.handle)
self._is_destroyed = True
self.destroy()

def print_device_properties(self, logger: Logger):
"""Prints local GPU properties."""
@@ -84,6 +83,10 @@ def print_device_properties(self, logger: Logger):
logger.debug("GPU-minor:", device_props["minor"])
logger.debug("========================")

def destroy(self):
cutn.destroy(self.handle)
self._is_destroyed = True


class Config:
"""Configuration class for simulation using ``StructuredState``."""