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

Initial TT-ICE integration #34

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
de6a250
test(inheritance) check parent branch
dorukaks Nov 29, 2022
253fe65
(fix) ignore error E203 to fix #36
dorukaks Nov 29, 2022
83c23dd
(fix) update version of black
dorukaks Nov 29, 2022
071d036
(fix) add doctests flag to flake8
dorukaks Nov 29, 2022
e441852
Automated documentation creation&publishing to GH-pages (#35)
dorukaks Dec 4, 2022
c3c986d
(feat): create init file to create DaMAT pack
dorukaks Dec 13, 2022
95bef29
(feat) create ttObject for Tensor Train objects
dorukaks Dec 13, 2022
a1fade6
(feat) create utils file for helper functions
dorukaks Dec 13, 2022
637504f
(feat) create ttObject and initialization function
dorukaks Dec 13, 2022
bf2bbed
(feat) create coreOccupancy as property
dorukaks Dec 13, 2022
3537e76
(feat) create compressionRatio as property
dorukaks Dec 13, 2022
a82c518
(feat) create changeShape function
dorukaks Dec 13, 2022
efba213
(feat) create computeTranspose function
dorukaks Dec 13, 2022
8f81c12
(feat) create save function for trained TT-cores
dorukaks Dec 13, 2022
ee03113
(feat) create load function for trained TT-cores
dorukaks Dec 13, 2022
ae95951
(feat) create projectTensor function
dorukaks Dec 13, 2022
fbcfe78
(feat) create reconstruct function
dorukaks Dec 13, 2022
a228dab
(feat) create updateRanks function
dorukaks Dec 13, 2022
85d52e9
(feat) create computeRelError function
dorukaks Dec 13, 2022
056ab67
(feat) create computeRecError function
dorukaks Dec 13, 2022
742e821
(feat) create ttsvd helper function
dorukaks Dec 13, 2022
8453873
(feat) create ttdecomp function
dorukaks Dec 13, 2022
b7475a2
(feat) create deltasvd helper function
dorukaks Dec 13, 2022
e39bcd4
(feat) create ttICE function
dorukaks Dec 13, 2022
c1f13d1
(feat) create ttICEstar function
dorukaks Dec 13, 2022
6c0be5b
(feat) create compression pipeline
dorukaks Dec 13, 2022
cb1993f
(fix) remove unused files
dorukaks Dec 13, 2022
ca789b3
(refactor) relocate TTICE pack
dorukaks Dec 13, 2022
5d311c1
(CI) merge branch 'dev' into feat/doruk/8_11_13
dorukaks Dec 13, 2022
005b158
(fix) check docstrings
dorukaks Dec 13, 2022
77ed77e
(fix) test docstring creation
dorukaks Dec 13, 2022
350b903
(fix) experiment to create docstrings as intended
dorukaks Dec 13, 2022
b933c74
(fix) experiment to create docstrings as intended
dorukaks Dec 13, 2022
54b98a9
(fix) attempt hopelessly to create documentation
dorukaks Dec 13, 2022
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
103 changes: 103 additions & 0 deletions compressionPipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import os
import time

import numpy as np
import TTICE as ttice

method = "ttsvd"
heuristics = ["skip", "occupancy"]
occThreshold = 1
compMetrFile = "compressionMetrics.txt" # This file is for me
lines2Print = []
"""
Don't modify those 3 lines above they are settings to the compression algorithm.
"""

cwd = os.getcwd()
epsilon = 0.05 # This is the relative approximation error threshold
nTrainingRuns = 640 # Modify this number accordingly
stpIdx = (
300 # If you downsample before saving data, change this to an appropriate number
)
step = 10 # If you downsample before saving data, change this to 1
iterStep = 1

dataDir = "./" # Folder that the 2048x1528x3x300 numpy arrays are stored
# I suggest you to put all the training runs in one folder
saveDir = "./" # Folder that you will save the TT-cores
saveName = "trainedCore" # Name of the saved TT-core files
dataName = "run_" # I assumed that you name all the run files "run_<runIdx>"

"""
Pick one of the two loops below and proceed
"""
# OPTION 1
# If you use the following loop, have all the train runs at one place
for runIdx in os.listdir():
data = np.load(dataDir + runIdx, mmap_mode="r")
# OPTION 2
# If you use the following loop, name the training runs with consecutive
# numbers starting from 0
for runIdx in range(nTrainingRuns):
print(f"Run: {runIdx}")
data = np.load(dataDir + dataName + f"{runIdx}", mmap_mode="r")

# After you pick one of the loops above, comment the other.
# The rest should be in the same loop since we are compressing.

stIdx = 0
if runIdx == 0:
# I'm checking here if we are at the first run. Please modify this if
# statement accordingly
dataSet = ttice.ttObject(
data[:, :, :, stIdx][:, :, :, None],
epsilon=epsilon,
keepData=False,
samplesAlongLastDimension=True,
method=method,
)
dataSet.changeShape([16, 32, 32, 191, 3, 1])
dataSet.ttDecomp()
lines2Print.append(f"{0}")
lines2Print.append(f"{dataSet.compressionTime}")
lines2Print.append(f"{dataSet.compressionRatio}")
lines2Print.append(" ".join(map(str, dataSet.ttRanks)))
lines2Print.append("\n")

# If you end up downsampling the timesteps before saving the data, change
# this to 1
stIdx = 9
else:
stIdx = 0

for iterIdx in range(stIdx, stpIdx, step):
stTime = time.time()
streamedTensor = data[:, :, :, iterIdx][:, :, :, None].reshape(
dataSet.reshapedShape[:-1] + [-1]
)
dataSet.ttICEstar(
streamedTensor,
epsilon=epsilon,
heuristicsToUse=heuristics,
occupancyThreshold=occThreshold,
)
stepTime = time.time() - stTime
lines2Print.append(f"{iterStep}")
lines2Print.append(f"{stepTime}")
lines2Print.append(f"{dataSet.compressionRatio}")
lines2Print.append(" ".join(map(str, dataSet.ttRanks)))
lines2Print.append("\n")
print(
f"Run {runIdx} timestep {iterIdx} (overall: {iterStep})\
done in {round(stepTime,4)}s"
)
with open(compMetrFile, "a") as txt:
txt.writelines(" ".join(lines2Print))
lines2Print = []
iterStep += 1
"""
I'm saving after each simulation here, it will slow down compression time a little
bit but it will save us a lot of valuable time if compression fails prematurely for
some reason
"""
dataSet.saveData(saveName, directory=saveDir, justCores=True, outputType="npy")
19 changes: 10 additions & 9 deletions src/TTICE/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
def testFcn(a):
"""This is a test function to check if docstrings are working
"""
Welcome to TTICE documentation!

Args:
a (float): random value
This python package currently offers support for multidimensional tensors
in Tensor-Train format.We use the TT-SVD algorithm proposed by Ivan Oseledets
and TT-ICE algorithm proposed by Doruk Aksoy.

Returns:
(float): input plus 2
"""
a += 2
return a
In future releases, the coverage may be extended to other tensor decomposition formats
such as CP and/or Tucker.
"""

from .ttObject import ttObject # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ def templateFunction(arg1, arg2):
return m


def main():
"""This is the main function (TT-ICE)"""
print(templateFunction(1, 2))


if __name__ == "__main__":
main()
class main:
def __init__(
self,
data,
epsilon: float = None,
keepData: bool = False,
samplesAlongLastDimension: bool = True,
method: str = "ttsvd",
):
"""This is the main function (TTICE)"""
print(templateFunction(1, 2))
File renamed without changes.
Loading