Skip to content

Fixes to migration from cals by block. #405

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

Merged
merged 46 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4c426af
Fixes to migration from cals by block.
cmccully Feb 12, 2025
4b58555
Moved codestyle back to setup.cfg because that's all they support.
cmccully Feb 12, 2025
975b7bf
More reversions to setup.cfg because not all tools deal with pyprojec…
cmccully Feb 12, 2025
f3f6552
Updates to unit tests python versions to use currently supported vers…
cmccully Feb 12, 2025
fc7f46b
Fixes to weird sqlite failure in dockerfile.
cmccully Feb 13, 2025
ef22f9c
Minor bugfixes for alembic migrations.
cmccully Feb 13, 2025
98dd074
Switching to poetry.
cmccully Feb 20, 2025
1589654
Added poetry file.
cmccully Feb 20, 2025
e970bdb
Install the cpu only version of pytorch to keep the docker image much…
cmccully Feb 21, 2025
efc633e
Removed tox. Poetry now manages all deps and the matrix stuff is all …
cmccully Feb 22, 2025
1f4d10c
Updated poetry.lock.
cmccully Feb 22, 2025
22b46b4
More github actions fixes.
cmccully Feb 22, 2025
fcd4b7e
More poetry fun to get cython to build.
cmccully Feb 24, 2025
9ac0c9f
Removed deprecated pkg_resources.
cmccully Feb 24, 2025
a9747d3
Typo fix.
cmccully Feb 24, 2025
0648a90
Change user that runs docker commands to try to deal with poetry.
cmccully Feb 24, 2025
e184332
Updates to work with python 3.13
cmccully Feb 24, 2025
75f89b6
Took poetry installs out of a virtual env to make the paths work.
cmccully Feb 24, 2025
fb2c661
More fixes to e2e tests.
cmccully Feb 24, 2025
0fe5e43
more e2e fixes.
cmccully Feb 24, 2025
aa84526
Added the ps command to the docker container.
cmccully Feb 24, 2025
eb65f56
Fixes to broken tests.
cmccully Feb 25, 2025
251e9bb
Added a comment to the dockerfile.
cmccully Feb 25, 2025
d697251
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
bc249e3
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
0086740
Added path to sphinx config for readthedocs.
cmccully Feb 25, 2025
167f3dc
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
7e72308
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
b8acbbc
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
55d69bf
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
e95a055
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
bdd2e4d
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
eec149b
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
b8843f0
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
dd56aa0
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
d9af071
Attempt at a fix for readthedocs.
cmccully Feb 25, 2025
d822dd0
Fixes to logging when an exception happens. Added a token so we stop …
cmccully Feb 26, 2025
7944032
Style fix.
cmccully Feb 26, 2025
9a631c2
Restructured k8s deployment of e2e tests to add an auth token.
cmccully Feb 28, 2025
372eb7a
Fixes to gh action labels.
cmccully Feb 28, 2025
02b5729
Added labels to make sure resources get selected.
cmccully Feb 28, 2025
997fbf5
Added timeouts to readiness probes
cmccully Feb 28, 2025
6d66dac
Added a pvc now that e2e tests are split across pods.
cmccully Feb 28, 2025
d453a42
Revert to single pod architecture because shared pvcs don't really wo…
cmccully Feb 28, 2025
9e7c955
Typo fix in raise for status
cmccully Feb 28, 2025
01f29ce
typo fix.
cmccully Feb 28, 2025
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ distribute-*.tar.gz
*.xml

*.iml

.tmp

.tox
24 changes: 24 additions & 0 deletions .github/workflows/codestyle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Code Style

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest # Or macos-latest if needed

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12' # Specify your desired version
- name: Install Poetry
run: pip install poetry
- name: Set up project
run: poetry install -E cpu -E style
- name: Code Style
run: poetry run pycodestyle --count --max-line-length=120
24 changes: 24 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Coverage

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest # Or macos-latest if needed

steps:
- uses: actions/checkout@v3
- name: Set up
uses: actions/setup-python@v4
with:
python-version: '3.12' # Specify your desired version
- name: Install Poetry
run: pip install poetry
- name: Set up project
run: poetry install -E cpu -E test
- name: Run coverage
run: poetry run pytest --pyargs banzai.tests -m "not e2e" --cov banzai --cov-config="setup.cfg"
25 changes: 25 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docs

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest # Or macos-latest if needed

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12' # Specify your desired version
- name: Install dependencies
run: pip install poetry
- name: Set up project
run: poetry install -E cpu -E docs
- name: Build Docs
run: poetry run sphinx-build -W -b html docs docs/_build/html

81 changes: 32 additions & 49 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,41 @@
name: Build/Test

on:
# Run this workflow for pushes on all branches
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests:
name: ${{ matrix.name }} (${{ matrix.os }}, ${{ matrix.toxenv }})
runs-on: ${{ matrix.os }}
linuxtest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:

- name: Documentation build
os: ubuntu-latest
python-version: 3.9
toxenv: build_docs

- name: Python 3.9 with minimal dependencies
os: ubuntu-latest
python-version: '3.9'
toxenv: py39-test

- name: Python 3.10 with minimal dependencies
os: ubuntu-latest
python-version: '3.10'
toxenv: py310-test

- name: Python 3.11 with minimal dependencies
os: ubuntu-latest
python-version: '3.11'
toxenv: py311-test

- name: Code style checks
os: ubuntu-latest
python-version: 3.9
toxenv: codestyle

python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: pip install poetry
- name: Set up project
run: poetry install -E cpu -E test
- name: Run tests
run: poetry run pytest --pyargs banzai.tests -m "not e2e"
macos: # New macOS job
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.12']
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Install graphviz dependency
if: "endsWith(matrix.toxenv, 'build_docs')"
run: sudo apt-get -y install graphviz
- name: Run tests
run: |
tox -e ${{ matrix.toxenv }}
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: pip install poetry
- name: Set up project
run: poetry install -E cpu -E test
- name: Run tests
run: poetry run pytest --pyargs banzai.tests -m "not e2e"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ a.out
*/version.py
*/cython_version.py
htmlcov
.coverage
.coverage*
MANIFEST
.ipynb_checkpoints
env
Expand Down Expand Up @@ -75,3 +75,4 @@ distribute-*.tar.gz
*.iml

.coverage.subprocess
test.db
12 changes: 0 additions & 12 deletions .rtd-environment.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.20.2 (2025-02-10)
-------------------
- Bugfix to logging on reduction stopped
- Updated the alembic scripts because the migration was taking too long

1.20.1 (2025-02-05)
-------------------
- Added tso proposals to be instantly public
Expand Down
29 changes: 15 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
FROM continuumio/miniconda3:23.5.2-0

# In principle I could remove the gcc to shrink the image, but pytorch is already so large it doesn't make much difference
RUN apt-get -y update && apt-get -y install gcc && \
apt-get autoclean && \
rm -rf /var/lib/apt/lists/*
FROM python:3.12-slim

RUN mkdir /home/archive && /usr/sbin/groupadd -g 10000 "domainusers" \
&& /usr/sbin/useradd -g 10000 -d /home/archive -M -N -u 10087 archive \
&& chown -R archive:domainusers /home/archive

USER archive
RUN pip install poetry --no-cache

ENV HOME=/home/archive
RUN apt-get -y update && apt-get -y install gcc procps && \
apt-get autoclean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /home/archive
RUN poetry config virtualenvs.create false

COPY environment.yaml .
COPY --chown=10087:10000 pyproject.toml poetry.lock /lco/banzai/

RUN . /opt/conda/etc/profile.d/conda.sh && conda config --set remote_read_timeout_secs 900 && conda env create -p /home/archive/envs/banzai -f environment.yaml --solver=libmamba
RUN poetry install --directory=/lco/banzai -E cpu --no-root --no-cache

COPY --chown=10087:10000 . /lco/banzai

ENV PATH=/home/archive/envs/banzai/bin:$PATH

RUN /home/archive/envs/banzai/bin/pip install --no-cache-dir /lco/banzai/
RUN poetry install --directory /lco/banzai -E cpu --no-cache

RUN cp /lco/banzai/pytest.ini /home/archive/pytest.ini

USER archive

ENV HOME=/home/archive

WORKDIR /home/archive
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Migration of past data for blockid, public-date, and proposalid

Revision ID: 51b98e26cc50
Revises: 8e35c490a971
Create Date: 2025-02-10 11:08:49.733571

"""
from typing import Sequence, Union

from alembic import op
from sqlalchemy.sql import text
import os
import requests
import datetime

# revision identifiers, used by Alembic.
revision: str = '51b98e26cc50'
down_revision: Union[str, None] = '8e35c490a971'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = '8e35c490a971'


def parse_date(date_to_parse):
date_formats = ['%Y-%m-%dT%H:%M:%S.%fZ', '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%d %H:%M:%S.%f']
for date_format in date_formats:
try:
parsed_date = datetime.datetime.strptime(date_to_parse, date_format)
break
except ValueError:
continue
return parsed_date


def upgrade() -> None:
if os.getenv("AUTH_TOKEN") is not None:
auth_header = {'Authorization': f'Token {os.environ["AUTH_TOKEN"]}'}
else:
auth_header = None

connection = op.get_bind()

query_str = "SELECT id, frameid, filename,type, dateobs FROM calimages"
# Get all of the frames from all of the cameras for all obstypes in this batch
rows = connection.execute(text(query_str)).fetchall()
for row in rows:
basename = row.filename.replace('.fits', '').replace('.fz', '')
if row.frameid is not None:
request_results = requests.get(f'https://archive-api.lco.global/frames/{row.frameid}', headers=auth_header)
request_results = request_results.json()
else:
params = {'basename_exact': basename, 'start': parse_date(row.dateobs) - datetime.timedelta(days=1),
'end': parse_date(row.dateobs) + datetime.timedelta(days=1)}
request_results = requests.get('https://archive-api.lco.global/frames/', params=params, headers=auth_header)
if len(request_results.json()['results']) == 0:
continue
request_results = request_results.json()['results'][0]

values = {'id': row.id,
'public_date': parse_date(request_results['public_date']),
'proposal': request_results['proposal_id'],
'blockid': request_results['BLKUID']}
query_str = 'blockid = :blockid, proposal = :proposal, public_date = :public_date'
if row.frameid is None:
query_str += ', frameid = :frameid'
values['frameid'] = request_results['id']
connection.execute(text(f"UPDATE calimages SET {query_str} WHERE id = :id"), values)


def downgrade() -> None:
pass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Add calibrations block info, proposal id, and public date to CalibrationImage

Revision ID: 8e35c490a971
Revises:
Revises:
Create Date: 2025-01-31 12:19:03.407606

"""
Expand All @@ -10,10 +10,6 @@
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect
from sqlalchemy.sql import text
import requests
import os
import datetime


# revision identifiers, used by Alembic.
Expand All @@ -34,38 +30,6 @@ def upgrade() -> None:
op.add_column('calimages', sa.Column('proposal', sa.String(50), nullable=True))
if 'public_date' not in columns:
op.add_column('calimages', sa.Column('public_date', sa.DateTime(), nullable=True))
if os.getenv("AUTH_TOKEN") is not None:
auth_header = {'Authorization': f'Token {os.environ["AUTH_TOKEN"]}'}
else:
auth_header = None

connection = op.get_bind()
rows = connection.execute(text("SELECT id, frameid, filename FROM calimages"))
for row in rows:
params = {'basename_exact': row.filename.replace('.fz', '').replace('.fits', '')}
request_results = requests.get('https://archive-api.lco.global/frames/', params=params, headers=auth_header)
request_results = request_results.json()['results']
if len(request_results) == 0:
continue

blockid = request_results[0]['BLKUID']
proposal = request_results[0]['proposal_id']
date_formats = ['%Y-%m-%dT%H:%M:%S.%fZ', '%Y-%m-%dT%H:%M:%SZ']
for date_format in date_formats:
try:
public_date = datetime.datetime.strptime(request_results[0]['public_date'], date_format)
break
except ValueError:
continue
values = {'id': row.id, 'public_date': public_date, 'proposal': proposal, 'blockid': blockid}
query_str = 'blockid = :blockid, proposal = :proposal, public_date = :public_date'
if row.frameid is None:
query_str += ', frameid = :frameid'
values['frameid'] = request_results[0]['id']
connection.execute(
text(f"UPDATE calimages SET {query_str} WHERE id = :id"),
values
)


def downgrade() -> None:
Expand Down
Loading