-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Restructed Christoffel to use dictonary * Wrote test for Christoffel * created setup.py * Restructed all imports to refect that we have a library now * moved tests in seperate folder
- Loading branch information
1 parent
a3411d0
commit a9739de
Showing
10 changed files
with
172 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def FOR1(): | ||
return range(3) | ||
|
||
|
||
def FOR2(): | ||
return ((i, j) for i in FOR1() for j in FOR1()) | ||
|
||
|
||
def FOR3(): | ||
return ((i, j, k) for i in FOR1() for j in FOR1() for k in FOR1()) | ||
|
||
|
||
def FOR4(): | ||
return ( | ||
(i, j, k, l) for i in FOR1() for j in FOR1() for k in FOR1() for l in FOR1() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from setuptools import setup | ||
from setuptools import find_packages | ||
|
||
|
||
def readme(): | ||
with open("README.md") as f: | ||
return f.read() | ||
|
||
|
||
setup( | ||
name="GeneralRelativity", | ||
version="0.1", | ||
description="HBA with GPR and PCA", | ||
long_description=readme(), | ||
classifiers=[ | ||
"Development Status :: 3 - Alpha", | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python :: 3.8", | ||
"Topic :: Machine learning :: Physics :: Simulation :: General Relativity", | ||
], | ||
keywords="Machine learning, Physics, Simulation, General Relativity", | ||
author="ThomasHelfer", | ||
author_email="thomashelfer@live.de", | ||
license="MIT", | ||
packages=find_packages(exclude=["tests"]), | ||
install_requires=["torch", "black", "pre-commit", "pytest", "numpy"], | ||
python_requires=">=3.5 ", | ||
include_package_data=True, | ||
zip_safe=False, | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import torch | ||
from GeneralRelativity.FourthOrderDerivatives import diff1, diff2 | ||
from GeneralRelativity.Utils import ( | ||
get_box_format, | ||
TensorDict, | ||
cut_ghosts, | ||
keys, | ||
keys_all, | ||
) | ||
from GeneralRelativity.TensorAlgebra import ( | ||
compute_christoffel, | ||
compute_christoffel_fast, | ||
) | ||
import os | ||
import sys | ||
|
||
|
||
def test_chris(): | ||
""" | ||
Test function to validate the computation of Christoffel symbols. | ||
This function reads tensor data from files, computes Christoffel symbols using two different | ||
implementations (compute_christoffel and compute_christoffel_fast), and then compares the results | ||
to ensure they are consistent with each other. It also checks the symmetry property of the Christoffel | ||
symbols. Assertions are used to ensure that the differences are within a specified tolerance. | ||
""" | ||
# Define the path to the test data files for variable X | ||
filenamesX = os.path.dirname(__file__) + "/TestData/Xdata_level0_step*" | ||
|
||
# Number of variables in the data | ||
num_varsX = 100 | ||
|
||
# Read the data in a box format | ||
dataX = get_box_format(filenamesX, num_varsX) | ||
|
||
# Tolerance for comparison | ||
tol = 1e-10 | ||
|
||
# Compute the differential value | ||
oneoverdx = 64.0 / 4.0 | ||
|
||
# Prepare the data and compute derivatives using TensorDict | ||
vars = TensorDict(cut_ghosts(dataX), keys_all) | ||
d1 = TensorDict(diff1(dataX, oneoverdx), keys_all) | ||
h_UU = torch.inverse(vars["h"]) | ||
chris = compute_christoffel(d1["h"], h_UU) | ||
chris_2nd_implementation = compute_christoffel_fast(d1["h"], h_UU) | ||
|
||
# Compare two versions of Christoffel symbols | ||
assert torch.mean(torch.abs(chris["LLL"] - chris_2nd_implementation["LLL"])) < tol | ||
assert torch.mean(torch.abs(chris["ULL"] - chris_2nd_implementation["ULL"])) < tol | ||
|
||
# Check symmetry of Christoffel symbols | ||
for i in range(3): | ||
for j in range(i, 3): | ||
assert ( | ||
torch.mean( | ||
torch.abs(chris["ULL"][..., i, j]) | ||
- torch.abs(chris["ULL"][..., j, i]) | ||
) | ||
== 0 | ||
) | ||
assert ( | ||
torch.mean( | ||
torch.abs(chris_2nd_implementation["ULL"][..., i, j]) | ||
- torch.abs(chris_2nd_implementation["ULL"][..., j, i]) | ||
) | ||
== 0 | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_chris() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters