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

Basic TTN simulation #41

Merged
merged 93 commits into from
Feb 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
19273db
Created new general.py file for logger and cutensornet handle. Update…
PabloAndresCQ Sep 25, 2023
2fde81a
Setting logger at MPS. Also changed my mind and restored CuTensornetH…
PabloAndresCQ Sep 25, 2023
beded34
Added debugging and info logging messages.
PabloAndresCQ Sep 26, 2023
fd362e1
Forgot to add the general.py file
PabloAndresCQ Sep 26, 2023
6ebe2d0
Improved messages
PabloAndresCQ Sep 26, 2023
b348f14
Fixed a bug on simulate I just found.
PabloAndresCQ Sep 26, 2023
cc92c04
Fixed linting and failing test
PabloAndresCQ Sep 26, 2023
82bc9ed
Merge branch 'develop' into feature/mps_logger
PabloAndresCQ Sep 27, 2023
f8b41d6
Updated Jupyter notebook with example of logger.
PabloAndresCQ Sep 27, 2023
deee46e
Now using a ConfigMPS object to provide the simulation settings.
PabloAndresCQ Sep 27, 2023
75358db
Merge branch 'feature/mps_logger' into refactor/mps_arguments
PabloAndresCQ Sep 27, 2023
b8ee244
Added value_of_zero parameter.
PabloAndresCQ Sep 28, 2023
14353fc
Small changes
PabloAndresCQ Sep 28, 2023
460736c
Fixing docs
PabloAndresCQ Sep 28, 2023
7ef38b5
Merge branch 'develop' into refactor/mps_arguments
PabloAndresCQ Sep 29, 2023
5b620d9
Fixed some issues when merging
PabloAndresCQ Sep 29, 2023
0d0af5c
Updated Jupyter notebook
PabloAndresCQ Oct 3, 2023
2517ab5
Warning now using warnings module
PabloAndresCQ Oct 3, 2023
a16ec7e
Moved MPS code to make room for TTN.
PabloAndresCQ Oct 10, 2023
0647c39
Restoring source code in /states folder
PabloAndresCQ Oct 10, 2023
1760257
Moved ConfigMPS to Config in general
PabloAndresCQ Oct 10, 2023
014a173
Some fixes
PabloAndresCQ Oct 10, 2023
3b71b65
Some more fixes
PabloAndresCQ Oct 10, 2023
a465474
Moving some more things around
PabloAndresCQ Oct 10, 2023
47fd903
Began implementation of TTN
PabloAndresCQ Oct 10, 2023
b86a545
Added single-qubit gate support and some basic tests.
PabloAndresCQ Oct 11, 2023
68401ce
Fixed some bugs
PabloAndresCQ Oct 11, 2023
de3dccb
Added vdot to TTN
PabloAndresCQ Oct 12, 2023
c00f975
Some bugs fixed
PabloAndresCQ Oct 12, 2023
eeab27c
Implemented get_amplitude and get_statevector. Current tests passing.
PabloAndresCQ Oct 12, 2023
fd79ef9
Implemented canonicalisation
PabloAndresCQ Oct 12, 2023
ff1dbf9
Renamed module states to tnstate
PabloAndresCQ Oct 12, 2023
ba6c4e8
Some basic fixes
PabloAndresCQ Oct 13, 2023
4528898
In the process of debugging canonicalisation
PabloAndresCQ Oct 17, 2023
2fbc559
Canonicalisation debugged
PabloAndresCQ Oct 18, 2023
13fffe3
In the process of implementing _apply_2q_gate
PabloAndresCQ Oct 18, 2023
1e907da
Exact 2-qubit gate application implemented. Not debugged yet.
PabloAndresCQ Oct 19, 2023
cfb15a6
Exact apply 2q gate implemented and debugged
PabloAndresCQ Oct 19, 2023
e1ca882
Added truncation by chi and value_of_zero
PabloAndresCQ Oct 19, 2023
19fea04
Small changes to debugging messages
PabloAndresCQ Oct 19, 2023
d38451e
Approximate sim under chi implemented and tested.
PabloAndresCQ Oct 20, 2023
f839f15
Added some more computationally intensive tests
PabloAndresCQ Oct 20, 2023
c2cd8ce
Unified TTN and MPS via TNState abstract class
PabloAndresCQ Oct 22, 2023
7ded611
_get_qubit_partition now does recursive balanced bisections.
PabloAndresCQ Nov 1, 2023
c2c47f9
Merged develop into branch
PabloAndresCQ Nov 1, 2023
4161474
Updated cq.contract providing handles and contraction path when known
PabloAndresCQ Nov 1, 2023
bc9298a
Changed default leaf size
PabloAndresCQ Nov 1, 2023
b295937
Changed the leaf_size parameter of the explicit_ttn test
PabloAndresCQ Nov 1, 2023
ca2fab8
Removing unused imports and pleasing linter.
PabloAndresCQ Nov 1, 2023
5f5453a
Changed docstrings of Config
PabloAndresCQ Nov 1, 2023
8f551bd
Updated docs
PabloAndresCQ Nov 1, 2023
df9db66
Updated the _get_sorted_gates algorithm so that it's compatible with …
PabloAndresCQ Nov 2, 2023
405f951
Fidelity slightly improved in one of the tests
PabloAndresCQ Nov 2, 2023
5d4edf2
Changes suggested by Iakov.
PabloAndresCQ Nov 7, 2023
9d0a284
Removed unused imports
PabloAndresCQ Nov 7, 2023
9308bfe
Changes suggested by Iakov
PabloAndresCQ Nov 14, 2023
193aed9
Jupyter notebook updated
PabloAndresCQ Nov 15, 2023
f1c9678
Updated MPI example
PabloAndresCQ Nov 16, 2023
b2a0b48
Replacing KL partitioner with KaHyPar
PabloAndresCQ Jan 10, 2024
aa3df63
Bugfixes
PabloAndresCQ Jan 10, 2024
df01841
Update copyright message
PabloAndresCQ Jan 12, 2024
f5cdc34
Bugfix on bounded chi truncation due to towards_root flag not being u…
PabloAndresCQ Jan 13, 2024
6c7592c
Fixing small mistake from previous commit
PabloAndresCQ Jan 13, 2024
5e8216d
Code readability improvement. Moved chi truncation implementation to …
PabloAndresCQ Jan 15, 2024
acd39a4
Added truncation_fidelity approach to TTNxGate
PabloAndresCQ Jan 15, 2024
4395cc1
Updated tests
PabloAndresCQ Jan 15, 2024
f420268
Removed NotImplementedError exception and updated the fidelity of app…
PabloAndresCQ Jan 15, 2024
4390ecb
Linting
PabloAndresCQ Jan 16, 2024
d934184
Implemented a different approach for gate fidelity truncation.
PabloAndresCQ Jan 23, 2024
ec5c2cb
Update fidelity test
PabloAndresCQ Jan 23, 2024
924146c
Added some extra debug messages to logger
PabloAndresCQ Jan 23, 2024
f8777cc
Refactored the code to avoid the use of funnel tensors.
PabloAndresCQ Jan 27, 2024
c9fa77f
Some minor fixes and refactoring
PabloAndresCQ Jan 27, 2024
2035091
Fixing a leaf_size in tests so that we test on TTNs of height >2
PabloAndresCQ Jan 27, 2024
10e04b0
Added some logger messages
PabloAndresCQ Jan 27, 2024
d5008b7
Merge pull request #69 from CQCL/feature/ttn_kahypar
PabloAndresCQ Feb 1, 2024
240d9c0
Fixing typo in comment
PabloAndresCQ Feb 1, 2024
c357532
Updated docstring.
PabloAndresCQ Feb 1, 2024
943f9f3
Merge branch 'feature/ttn' into feature/ttn_gate_fidelity
PabloAndresCQ Feb 1, 2024
6c0fcb4
Merge pull request #74 from CQCL/feature/ttn_gate_fidelity
PabloAndresCQ Feb 1, 2024
f35fcc3
Fixed an unfinished comment
PabloAndresCQ Feb 1, 2024
7619bcd
Merge branch 'feature/ttn' into feature/ttn_no_funnels
PabloAndresCQ Feb 1, 2024
2f86a77
Merge pull request #78 from CQCL/feature/ttn_no_funnels
PabloAndresCQ Feb 1, 2024
96cca32
Cleaned up code around bonds_from_q0_to_ancestor
PabloAndresCQ Feb 1, 2024
6416d5b
Merge branch 'develop' into feature/ttn
PabloAndresCQ Feb 1, 2024
3f1a946
Applying lint, mypy and updating explicit fidelity in test
PabloAndresCQ Feb 1, 2024
1221eac
Renamed tnstate to structured_state
PabloAndresCQ Feb 2, 2024
9043661
Linting and mypy
PabloAndresCQ Feb 2, 2024
bdab46a
Updated module docstring
PabloAndresCQ Feb 2, 2024
4b0ae27
Changed kahypar to strict version requirement
PabloAndresCQ Feb 2, 2024
94b03fe
Removed kahypar dependency
PabloAndresCQ Feb 2, 2024
0206d17
Flexible kahypar import
PabloAndresCQ Feb 2, 2024
d96e37f
Linter being pedantic
PabloAndresCQ Feb 2, 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
Added vdot to TTN
PabloAndresCQ committed Oct 12, 2023
commit de3dccb4e574e05f45b24c9f4f54c3623e59803b
2 changes: 1 addition & 1 deletion pytket/extensions/cutensornet/states/mps.py
Original file line number Diff line number Diff line change
@@ -315,7 +315,7 @@ def vdot(self, other: MPS) -> complex:
The state that is conjugated is ``self``.

Args:
other: The other MPS to compare against.
other: The other MPS.

Returns:
The resulting complex number.
94 changes: 94 additions & 0 deletions pytket/extensions/cutensornet/states/ttn.py
Original file line number Diff line number Diff line change
@@ -224,6 +224,7 @@ def is_valid(self) -> bool:
for path in self.nodes.keys()
if len(path) != 0
)
shape_ok = shape_ok and self.get_dimension((), DirTTN.PARENT) == 1

# Debugger logging
self._logger.debug(
@@ -274,6 +275,99 @@ def apply_gate(self, gate: Command) -> TTN:

return self

def vdot(self, other: TTN) -> complex:
"""Obtain the inner product of the two TTN: ``<self|other>``.

It can be used to compute the squared norm of a TTN ``ttn`` as
``ttn.vdot(ttn)``. The tensors within the TTN are not modified.

Note:
The state that is conjugated is ``self``.

Args:
other: The other TTN.

Returns:
The resulting complex number.

Raises:
RuntimeError: If the two TTNs do not have the same qubits.
RuntimeError: If the ``CuTensorNetHandle`` is out of scope.
"""
if self._lib._is_destroyed:
raise RuntimeError(
"The cuTensorNet library handle is out of scope.",
"See the documentation of update_libhandle and CuTensorNetHandle.",
)

if len(self.qubit_position) != len(other.qubit_position):
raise RuntimeError("Number of qubits do not match.")
if self.get_qubits != other.get_qubits:
raise RuntimeError(
"The sets of qubits are not the same."
"\n\tself has {self.get_qubits()}"
"\n\tother has {other.get_qubits()}"
)
if len(self.qubit_position) == 0:
raise RuntimeError("There are no qubits in the TTN.")

self._logger.debug("Applying vdot between two TTNs.")

# We convert both TTNs to their interleaved representation and
# contract them using cuQuantum. A single sample is enough for
# contraction path optimisation, since there is little to optimise.
ttn1 = self.get_interleaved_representation(conj=True)
ttn2 = other.get_interleaved_representation(conj=False)
interleaved_rep = tt1 + tt2 + [[]] # Discards dim=1 bonds with []
result = cq.contract(
*interleaved_rep,
options={"handle": self._lib.handle, "device_id": self._lib.device_id},
optimize={"samples": 1}
)

self._logger.debug(f"Result from vdot={result}")
return complex(result)

def get_interleaved_representation(self, conj: bool = False) -> list[Union[Tensor, str]]:
"""Returns the interleaved representation of the TTN used by cuQuantum.

Args:
conj: If True, all tensors are conjugated and bonds IDs are prefixed
with * (except physical bonds). Defaults to False.
"""
self._logger.debug("Creating interleaved representation...")

# Auxiliar dictionary of physical bonds to qubit IDs
qubit_id = {location: str(qubit) for qubit, location in self.qubit_position.items()}

interleaved_rep = []
for path, node in self.nodes.items():

# Append the tensor
if conj:
interleaved_rep.append(node.tensor.conj())
else:
interleaved_rep.append(node.tensor)

# Create the ID for the parent bond
parentID = "".join(str(int(d)) for d in path)
if conj:
parentID = "*" + parentID

# Append the bonds
if node.isleaf:
bonds = []
for b in range(len(node.tensor.shape) - 1):
bonds.append(qubit_id[(path,b)])
bonds.append(parentID)
else:
bonds = [parentID+"0", parentID+"1", parentID]

interleaved_rep.append(bonds)
self._logger.debug(f"Bond IDs: {bonds}")

return interleaved_rep

def get_qubits(self) -> set[Qubit]:
"""Returns the set of qubits that this TTN is defined on."""
return set(self.qubit_position.keys())