Skip to content

Commit

Permalink
Don't push to pypi if tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasahle committed Feb 24, 2025
1 parent 08bbf3f commit 61979c7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build and Publish to PyPI

on:
push:
paths:
- 'pyproject.toml'
# Trigger when the python-tests workflow completes.
workflow_run:
workflows: ["python-tests"]
types: [completed]
# Also allow manual triggering.
workflow_dispatch:
inputs:
force:
Expand All @@ -13,17 +15,21 @@ on:

jobs:
build-and-publish:
# Only run if the triggering workflow (python-tests) succeeded.
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# Check out the commit that triggered the tests.
ref: ${{ github.event.workflow_run.head_sha }}

- name: Check if new version compared to PyPI
- name: Check if new version compared to PyPI or force publish
id: version_check
run: |
# Define your package name as published on PyPI.
PACKAGE_NAME="tensorgrad" # Change this if your PyPI package name differs.
PACKAGE_NAME="tensorgrad" # Update this if your PyPI package name is different.
FORCE="${{ github.event.inputs.force }}"
if [ "$FORCE" = "true" ]; then
echo "Force publish enabled."
Expand All @@ -32,16 +38,14 @@ jobs:
# Extract the version from pyproject.toml (expects a line like: version = "1.2.3")
current_version=$(grep '^version' pyproject.toml | head -n 1 | cut -d'"' -f2)
echo "Current version in pyproject.toml: $current_version"
# Query PyPI for the latest published version.
# Get the latest version from PyPI using its JSON API.
latest_pypi_version=$(curl -s "https://pypi.org/pypi/${PACKAGE_NAME}/json" | jq -r '.info.version')
# If the package isn’t found or no version exists, default to 0.0.0.
# Default to 0.0.0 if nothing is returned.
if [ "$latest_pypi_version" = "null" ] || [ -z "$latest_pypi_version" ]; then
latest_pypi_version="0.0.0"
fi
echo "Latest version on PyPI: $latest_pypi_version"
# Compare versions using dpkg's version comparison.
# Compare versions using dpkg (ensures proper version ordering).
if dpkg --compare-versions "$current_version" gt "$latest_pypi_version"; then
echo "New version detected, ready to publish."
echo "version_changed=true" >> $GITHUB_OUTPUT
Expand Down
42 changes: 38 additions & 4 deletions examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,16 @@ def main18():
expr = expr / Y
save_steps(expr)

def main19():
def main19(n=2, symmetric=True):
i = symbols("i")
M = Variable("M", i, j=i).with_symmetries("i j")
M = Variable("M", i, j=i)
if symmetric:
M = M.with_symmetries("i j")
u = Variable("u", i)
U = Delta(i, "i", "j") - u @ u.rename(i="j") / Delta(i)
#TrUMs = F.graph("*1 -i- U1 -j-i- M1 -j-i- U2 -j-i- M2 -j- *1",
#U1=U, U2=U, M1=M, M2=M)
UMs = F.multi_dot([U, M]*4, dims=("i", "j"))
UMs = F.multi_dot([U, M]*n, dims=("i", "j"))
TrUMs = F.trace(UMs)
expr = Expectation(TrUMs, u)
save_steps(expr.full_simplify())
Expand Down Expand Up @@ -343,5 +345,37 @@ def main21():
e = Expectation(expr, g)
save_steps(e)


def main22(signature:str):
i = symbols("i")
M = Variable("M", i, j=i)
T = M.rename(i="j", j="i")
u = Variable("u", i)
U = Delta(i, "i", "j") - u @ u.rename(i="j") / Delta(i)
cycles = [[]]
for s in signature:
assert s in 'MT|'
if s == 'M':
cycles[-1] += [U, M]
elif s == 'T':
cycles[-1] += [T, U]
elif s == '|':
cycles.append([])
print(cycles)
traces = [F.trace(F.multi_dot(cycle, dims=("i", "j"))) for cycle in cycles]
prod = Product(traces)
expr = Expectation(prod, u)
save_steps(expr.full_simplify())

def main23(n:int, m:int):
# n is the number of cycles, m is the number of indep. variables
i = symbols("i")
us = [Variable(f"u{k}", i) for k in range(m)]
Us = [Delta(i, "i", "j") - u @ u.rename(i="j") / Delta(i) for u in us]
tr = F.trace(F.multi_dot(Us * n, dims=("i", "j"))) / Delta(i)
for u in us:
tr = Expectation(tr, u)
save_steps(tr.full_simplify())

if __name__ == "__main__":
main21()
main23(3, 2)

0 comments on commit 61979c7

Please # to comment.