Add your description here
Project description
torch-relativistic
A PyTorch extension that implements neural network components inspired by relativistic physics, particularly the Terrell-Penrose effect.
Overview
RelativisticTorch provides neural network modules that incorporate concepts from special relativity into machine learning. The key insight is that the Terrell-Penrose effect, where rapidly moving objects appear rotated rather than contracted, can inspire novel information processing paradigms in neural networks.
This library includes:
- Relativistic Graph Neural Networks (GNNs)
- Relativistic Spiking Neural Networks (SNNs)
- Relativistic attention mechanisms
- Transformations inspired by special relativity
Installation
pip install -e .
Components
Relativistic Graph Neural Networks
GNN modules that process information as if affected by relativistic phenomena:
import torch
from relativistic_torch.gnn import RelativisticGraphConv, MultiObserverGNN
# Create a simple graph
num_nodes = 10
feature_dim = 16
edge_index = torch.tensor([[0, 1, 1, 2, 2, 3, 3, 4, 4, 0],
[1, 0, 2, 1, 3, 2, 4, 3, 0, 4]], dtype=torch.long)
node_features = torch.randn(num_nodes, feature_dim)
# Create a relativistic GNN layer
conv = RelativisticGraphConv(
in_channels=feature_dim,
out_channels=32,
max_relative_velocity=0.8
)
# Process the graph
output_features = conv(node_features, edge_index)
print(f\"Output shape: {output_features.shape}\") # [10, 32]
# Multi-observer GNN processes the graph from multiple relativistic perspectives
multi_observer_gnn = MultiObserverGNN(
feature_dim=feature_dim,
hidden_dim=32,
output_dim=8,
num_observers=4
)
output = multi_observer_gnn(node_features, edge_index)
print(f\"Multi-observer output shape: {output.shape}\") # [10, 8]
Relativistic Spiking Neural Networks
SNN components that incorporate relativistic time dilation:
import torch
from relativistic_torch.snn import RelativisticLIFNeuron, TerrellPenroseSNN
# Create input spikes (batch_size=32, input_size=10)
input_spikes = torch.bernoulli(torch.ones(32, 10) * 0.3)
# Create a relativistic LIF neuron
neuron = RelativisticLIFNeuron(
input_size=10,
threshold=1.0,
beta=0.9
)
# Initialize neuron state
initial_state = neuron.init_state(batch_size=32)
# Process input spikes
output_spikes, new_state = neuron(input_spikes, initial_state)
print(f\"Output spikes shape: {output_spikes.shape}\") # [32]
# Create a complete SNN
snn = TerrellPenroseSNN(
input_size=10,
hidden_size=20,
output_size=5,
simulation_steps=100
)
# Process input
output = snn(input_spikes)
print(f\"SNN output shape: {output.shape}\") # [32, 5]
# Get spike history for visualization
spike_history = snn.get_spike_history(input_spikes)
print(f\"Hidden spike history shape: {spike_history['hidden_spikes'].shape}\") # [32, 100, 20]
Relativistic Attention Mechanism
Attention where different heads operate in different reference frames:
import torch
from relativistic_torch.attention import RelativisticSelfAttention
# Create input sequence (batch_size=16, seq_len=24, feature_dim=64)
seq = torch.randn(16, 24, 64)
# Create relativistic self-attention module
attention = RelativisticSelfAttention(
hidden_dim=64,
num_heads=8,
dropout=0.1,
max_velocity=0.9
)
# Optional: Create positions for spacetime distances
positions = torch.randn(16, 24, 3) # 3D positions for each token
# Process sequence
output = attention(seq, positions=positions)
print(f\"Output shape: {output.shape}\") # [16, 24, 64]
Relativistic Transformations
Apply transformations inspired by special relativity to feature vectors:
import torch
from relativistic_torch.transforms import TerrellPenroseTransform, LorentzBoost
# Create feature vectors (batch_size=8, feature_dim=64)
features = torch.randn(8, 64)
# Apply Terrell-Penrose inspired transformation
transform = TerrellPenroseTransform(
feature_dim=64,
max_velocity=0.9,
mode=\"rotation\"
)
transformed = transform(features)
print(f\"Transformed shape: {transformed.shape}\") # [8, 64]
# For spacetime features (batch_size=8, feature_dim=8 including 4D spacetime)
spacetime_features = torch.randn(8, 8)
# Apply Lorentz boost
boost = LorentzBoost(
feature_dim=8,
time_dim=0, # First dimension is time
max_velocity=0.8
)
boosted = boost(spacetime_features)
print(f\"Boosted shape: {boosted.shape}\") # [8, 8]
Examples
Classification with Relativistic GNN
import torch
import torch.nn as nn
import torch.nn.functional as F
from relativistic_torch.gnn import RelativisticGraphConv
PyPI Veröffentlichung mit GitHub Actions
Setup
- Erstelle ein PyPI API-Token auf pypi.org
- Füge das Token als GitHub Secret hinzu:
- Gehe zu deinem Repository auf GitHub
- Navigiere zu "Settings" > "Secrets and variables" > "Actions"
- Klicke auf "New repository secret"
- Name:
PYPI_API_TOKEN - Value: Dein PyPI API-Token
Veröffentlichungsprozess
Das Paket wird automatisch veröffentlicht, wenn:
- Ein neuer Release auf GitHub erstellt wird
- Der Workflow manuell über die GitHub Actions-Oberfläche ausgelöst wird
Lokales Testen
# Paket bauen
uv build
# Paket auf TestPyPI veröffentlichen (optional)
uv pip install twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/* --username __token__ --password "DEIN_TEST_PYPI_TOKEN"
Konfiguration
Die GitHub Action verwendet UV statt pip für alle Vorgänge und veröffentlicht das Paket auf PyPI mit dem konfigurierten API-Token.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_relativistic-0.1.0.tar.gz.
File metadata
- Download URL: torch_relativistic-0.1.0.tar.gz
- Upload date:
- Size: 79.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5eb86e6eeda9dadbaf0a9be8300aef0889eefc812a6312e634a860a72dd53810
|
|
| MD5 |
02aab8dbf9f559ad6ee0f00f95b7184f
|
|
| BLAKE2b-256 |
47a379803af0ef4a3002ac85927386275b424a85aeba13af15d3cf256f55c935
|
Provenance
The following attestation bundles were made for torch_relativistic-0.1.0.tar.gz:
Publisher:
python-publish.yml on bjoernbethge/torch-relativistic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_relativistic-0.1.0.tar.gz -
Subject digest:
5eb86e6eeda9dadbaf0a9be8300aef0889eefc812a6312e634a860a72dd53810 - Sigstore transparency entry: 213318636
- Sigstore integration time:
-
Permalink:
bjoernbethge/torch-relativistic@23636bbd27636f87140c0099166628212e926f25 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bjoernbethge
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@23636bbd27636f87140c0099166628212e926f25 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file torch_relativistic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torch_relativistic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e550dc424ffd2ec571f8988c4b2c8b5e8f990733734c468cc649ff30d3555005
|
|
| MD5 |
deebe32b222b051743abfbf2906ef5cd
|
|
| BLAKE2b-256 |
fcccdee1372714feba4e42efb567acad4c7e2ab3f8ee67567a41d33058921563
|
Provenance
The following attestation bundles were made for torch_relativistic-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on bjoernbethge/torch-relativistic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_relativistic-0.1.0-py3-none-any.whl -
Subject digest:
e550dc424ffd2ec571f8988c4b2c8b5e8f990733734c468cc649ff30d3555005 - Sigstore transparency entry: 213318638
- Sigstore integration time:
-
Permalink:
bjoernbethge/torch-relativistic@23636bbd27636f87140c0099166628212e926f25 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bjoernbethge
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@23636bbd27636f87140c0099166628212e926f25 -
Trigger Event:
workflow_dispatch
-
Statement type: