From c9373b1e25f6e2cb5225a2b2277ae01739ca7e9c Mon Sep 17 00:00:00 2001 From: Adambomb210 Date: Thu, 26 Nov 2026 11:24:02 -0500 Subject: [PATCH] Let teams ask for CPU-only compute, and price it - The application form's estimators get "CPU only, no GPU": the team gives the cores (1-512) and the hours. It is priced at Krater's CPU price per core-hour, or at the team's own price per machine-hour. - Admins set the CPU price per core-hour under Organization limits on /admin/compute (0 means not set; teams then give their own price). - Partner grants value core-hours from jobs that used no GPU at that price, next to GPU-hours. Each day keeps the price it was first valued at; days imported before this are read again once. - The funder packet's "GPU estimate" is now "Compute estimate". Migrations d3f8b1c5e7a2 and e6a2c9d4f1b8 only add columns. Co-Authored-By: Claude Opus 5.5 --- .../d3f8b1c5e7a2_add_cpu_core_hour_price.py | 34 ++++++++ .../e6a2c9d4f1b8_value_cpu_only_core_hours.py | 36 ++++++++ docs/SPEC.md | 14 +++- docs/dev/pricing.md | 9 ++ docs/guides/ospool-grants.md | 5 +- docs/guides/reviewing-and-admin.md | 1 + docs/guides/share-with-ospool.md | 2 +- docs/guides/using-krater.md | 3 +- krater/models/compute_settings.py | 3 + krater/models/ospool_grant.py | 18 +++- krater/ospool/accounting.py | 26 +++++- krater/services/compute_settings.py | 16 +++- krater/services/funder_packet.py | 11 ++- krater/services/ospool_grants.py | 73 +++++++++++++--- krater/services/pricing.py | 51 +++++++++++- krater/web/estimator_form.py | 60 +++++++++++++- krater/web/routers/pricing.py | 2 + krater/web/routers/projects.py | 2 + krater/web/static/js/budget-estimator.js | 12 ++- .../web/templates/projects/_application.html | 38 +++++++-- krater/web/templates/projects/_ospool.html | 10 ++- .../web/templates/projects/_ospool_admin.html | 3 +- krater/web/templates/projects/edit.html | 2 +- krater/web/templates/projects/new.html | 2 +- tests/ospool/test_accounting.py | 20 ++++- tests/services/test_funder_packet.py | 8 ++ tests/services/test_ospool_grants.py | 83 ++++++++++++++++++- tests/web/test_application_form.py | 78 ++++++++++++++++- tests/web/test_budget_estimator.py | 26 ++++++ tests/web/test_compute_guards_web.py | 22 +++++ tests/web/test_funder_export.py | 2 +- tests/web/test_ospool_grants_web.py | 10 ++- 32 files changed, 619 insertions(+), 63 deletions(-) create mode 100644 alembic/versions/d3f8b1c5e7a2_add_cpu_core_hour_price.py create mode 100644 alembic/versions/e6a2c9d4f1b8_value_cpu_only_core_hours.py diff --git a/alembic/versions/d3f8b1c5e7a2_add_cpu_core_hour_price.py b/alembic/versions/d3f8b1c5e7a2_add_cpu_core_hour_price.py new file mode 100644 index 00000000..6c2d595d --- /dev/null +++ b/alembic/versions/d3f8b1c5e7a2_add_cpu_core_hour_price.py @@ -0,0 +1,34 @@ +"""add compute_settings.cpu_core_hour_microusd: Krater's price for a CPU core-hour + +Revision ID: d3f8b1c5e7a2 +Revises: a8d3f1c6e2b9 +Create Date: 2026-11-25 22:00:00.000000 + +An org setting an admin sets on /admin/compute: what one CPU core costs per hour, in micro-dollars. The application +form prices a CPU-only estimate with it (cores x hours x this). The server default 0 means no price is set, and teams +give their own as before. +""" + +from collections.abc import Sequence + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "d3f8b1c5e7a2" +down_revision: str | Sequence[str] | None = "a8d3f1c6e2b9" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + """Upgrade schema.""" + op.add_column( + "compute_settings", sa.Column("cpu_core_hour_microusd", sa.Integer(), nullable=False, server_default="0") + ) + + +def downgrade() -> None: + """Downgrade schema.""" + op.drop_column("compute_settings", "cpu_core_hour_microusd") diff --git a/alembic/versions/e6a2c9d4f1b8_value_cpu_only_core_hours.py b/alembic/versions/e6a2c9d4f1b8_value_cpu_only_core_hours.py new file mode 100644 index 00000000..f480dbf7 --- /dev/null +++ b/alembic/versions/e6a2c9d4f1b8_value_cpu_only_core_hours.py @@ -0,0 +1,36 @@ +"""value CPU-only core-hours on partner grant days + +Revision ID: e6a2c9d4f1b8 +Revises: d3f8b1c5e7a2 +Create Date: 2026-11-25 23:30:00.000000 + +Each usage day also keeps the core-hours of jobs that used no GPU, the CPU price per core-hour that values them, and +their value. All three are nullable: a day imported before this has no CPU-only figure yet (`NULL`), and the next import +reads the grant's whole history again to fill it in. +""" + +from collections.abc import Sequence + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "e6a2c9d4f1b8" +down_revision: str | Sequence[str] | None = "d3f8b1c5e7a2" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + """Upgrade schema.""" + op.add_column("ospool_usage_days", sa.Column("cpu_core_hours", sa.Numeric(14, 4), nullable=True)) + op.add_column("ospool_usage_days", sa.Column("core_rate_microusd", sa.BigInteger(), nullable=True)) + op.add_column("ospool_usage_days", sa.Column("core_value_cents", sa.BigInteger(), nullable=True)) + + +def downgrade() -> None: + """Downgrade schema.""" + op.drop_column("ospool_usage_days", "core_value_cents") + op.drop_column("ospool_usage_days", "core_rate_microusd") + op.drop_column("ospool_usage_days", "cpu_core_hours") diff --git a/docs/SPEC.md b/docs/SPEC.md index 1de5b45b..9803edaa 100644 --- a/docs/SPEC.md +++ b/docs/SPEC.md @@ -137,7 +137,7 @@ Rules (`krater.services.funder_packet`; how-to in [guides/share-with-ospool.md]( - **Which fields.** The admin ticks them on the page too (`funder_packet.FIELDS`); the title always goes. Ticked when the page opens: summary (the one sentence), how the compute is used, where the training data comes from, status (with the funding hold, if any), the amount requested (the approved revision's, not an amendment in review; for a - project never approved, its newest revision's), the amount granted (the ledger ceiling), the GPU estimate (card, + project never approved, its newest revision's), the amount granted (the ledger ceiling), the compute estimate (card or CPU-only cores, count, hours, interruptible or on-demand), the team's names and size, and whether every team member is a verified US resident, and the OSPool usage of a project with an OSPool grant (see "OSPool grants"). Unticked until the admin ticks them: the write-up, the experience answer, the contest or professor, @@ -232,8 +232,11 @@ The proposal form (`projects/_application.html`) asks, in three parts: Submission Criteria ask applicants to name their data sources), then two estimates priced at Vast's current rates: the **proof of concept** and the **finished product**. Each is a card and about how many hours (plus rental type and safety margin), and each can be overridden twice over: the team can give its own price per card-hour (also how a card - Krater has no price for is estimated), and can request a different amount than the estimate. Reviewers see the - estimate, Krater's own price when the team gave theirs, and the amount requested, flagged when they differ a lot. + Krater has no price for is estimated), and can request a different amount than the estimate. Instead of a card, the + team can pick **CPU only** with a number of cores, priced at the admins' **CPU price per core-hour** + (`/admin/compute`); until an admin sets one, the team gives the machine's price per hour (Krater Compute can't + run CPU-only jobs yet either: this only lets a proposal ask for them). Reviewers see the estimate, Krater's own price when the team gave theirs, and the amount requested, flagged + when they differ a lot. Only the proof of concept is approved at first: its amount is `budget_requested_cents`. The finished product's amount is information for reviewers and never enters the budget ledger; the team asks for more with an amendment, which @@ -549,7 +552,10 @@ values the usage at what renting the GPU would have cost. - **Value.** Each day is valued at the grant's price, else Krater's own on-demand price for the GPU (its Vast samples, else the catalog). A day keeps the price it was first valued at; a day without a price gets one when Krater has one. An admin changes the GPU or price from the project page (`admin_change_ospool_valuation`), for later days only. - OSG doesn't record which GPU a job used, so the value is an estimate, shown as one. + OSG doesn't record which GPU a job used, so the value is an estimate, shown as one. Core-hours of jobs that used no + GPU (the summary records with no GPU-hours) are valued the same way at Krater's CPU price per core-hour + (`/admin/compute`), each day keeping its first CPU price too; a GPU job's cores come with its GPU's price, so they + aren't counted twice. Days imported before Krater read the CPU-only part are read again from the start, once. - **Display.** The project shows *Approved · Partner grant*. Its page has a *Partner grant* card (totals, worth, the last 30 days with usage, when it was last read), seen by anyone who can see the project. - **Not named outside admin pages.** What members and reviewers see (the badge, the card, the project's Slack diff --git a/docs/dev/pricing.md b/docs/dev/pricing.md index 60aff39f..27fc3f9b 100644 --- a/docs/dev/pricing.md +++ b/docs/dev/pricing.md @@ -155,6 +155,15 @@ summary says "the team's own hourly price; Krater's typical is $X/hr". The amoun differ from the estimate's total; it starts as the total, and the project page flags a large difference (`budget_estimate_flag_threshold_percent`). Both estimates are always stored when filled in, whatever was requested. +**CPU only.** The card `` value for a card Krater has no price for; the team names it and gives its hourly price. OTHER_GPU = "other" +#: The ` {% if errors[f ~ 'gpu'] %}

{{ errors[f ~ 'gpu'] }}

{% endif %} @@ -74,7 +77,21 @@ -
+
+
+ + +

+ {%- if cpu_only.core_price %}Priced at Krater's CPU price, {{ cpu_only.core_price }} per core-hour. You can give + your own price for the whole machine below. + {%- else %}Krater has no CPU price yet: give the whole machine's price per hour below.{% endif -%} +

+ {% if errors[f ~ 'cpu_cores'] %}

{{ errors[f ~ 'cpu_cores'] }}

{% endif %} +
+
+ +
Rental, your own price, margin
@@ -86,7 +103,10 @@

Interruptible machines cost much less and can pause when outbid; Krater resumes them.

- +

Leave blank to use Krater's current price. Reviewers see both.

@@ -120,7 +140,7 @@ {% endmacro %} -{% macro application_fields(values, errors, summaries, gpu_options, applicant, word_limits, summary_max, other_gpu, kind="proposal", team=none, base_cents=0) %} +{% macro application_fields(values, errors, summaries, gpu_options, applicant, word_limits, summary_max, other_gpu, cpu_only, kind="proposal", team=none, base_cents=0) %}
You
@@ -210,18 +230,18 @@ "The card and hours the next stage needs, on top of what's approved. It starts as your finished-product estimate.", "New total budget (USD)", "The project's whole budget if this amendment is approved: the " ~ (base_cents | dollars) ~ " approved so far plus the estimate. Type a different total if you need one; it can be lower, too.", - values, errors, summaries.poc, gpu_options, other_gpu, base_cents=base_cents) }} + values, errors, summaries.poc, gpu_options, other_gpu, cpu_only, base_cents=base_cents) }} {% else %} {{ estimator("poc", "Proof of concept", "How much compute a proof of concept needs: which card, and about how many hours. This is what gets approved first.", "Budget to request (USD)", "Filled in from the estimate. Change it if you need a different amount; reviewers see both.", - values, errors, summaries.poc, gpu_options, other_gpu) }} + values, errors, summaries.poc, gpu_options, other_gpu, cpu_only) }} {% endif %} {{ estimator("full", "Finished product", "Roughly how much the finished product would need. A rough guess is fine; it isn't approved now, and you can ask for it later with an amendment.", "Rough total (USD)", "For reviewers' information only.", - values, errors, summaries.full, gpu_options, other_gpu) }} + values, errors, summaries.full, gpu_options, other_gpu, cpu_only) }}
{% endmacro %} diff --git a/krater/web/templates/projects/_ospool.html b/krater/web/templates/projects/_ospool.html index cf48060f..774734e4 100644 --- a/krater/web/templates/projects/_ospool.html +++ b/krater/web/templates/projects/_ospool.html @@ -15,9 +15,11 @@

Partner grant

Worth at rent prices
{{ totals.value_cents | dollars }}

- Counted from {{ ospool_grant.counted_from.isoformat() }}. Valued at {{ ospool_rate_text }}: what renting the GPU - on demand would have cost, not what anyone paid. Each day keeps the price it was first valued at. - {%- if totals.unvalued_days %} {{ totals.unvalued_days }} day{{ "s" if totals.unvalued_days != 1 }} with GPU-hours + Counted from {{ ospool_grant.counted_from.isoformat() }}. GPU-hours are valued at {{ ospool_rate_text }}, and + the {{ "{:,.1f}".format(totals.cpu_core_hours) }} core-hours of jobs that used no GPU at {{ ospool_cpu_rate_text }}: + what renting them on demand would have cost, not what anyone paid. A GPU job's cores come with its GPU. Each day + keeps the prices it was first valued at. + {%- if totals.unvalued_days %} {{ totals.unvalued_days }} day{{ "s" if totals.unvalued_days != 1 }} with usage {{ "have" if totals.unvalued_days != 1 else "has" }} no price yet, so {{ "they're" if totals.unvalued_days != 1 else "it's" }} left out.{% endif %}

@@ -47,7 +49,7 @@

Last {{ totals.recent | length }} days with usage

{{ "{:,.1f}".format(day.gpu_hours) }} {{ "{:,.1f}".format(day.core_hours) }} {{ "{:,}".format(day.jobs) }} - {{ day.value_cents | dollars if day.value_cents is not none else "No price" }} + {{ day.worth_cents | dollars if day.worth_cents is not none else "No price" }} {% endfor %} diff --git a/krater/web/templates/projects/_ospool_admin.html b/krater/web/templates/projects/_ospool_admin.html index c2119382..b09a422a 100644 --- a/krater/web/templates/projects/_ospool_admin.html +++ b/krater/web/templates/projects/_ospool_admin.html @@ -62,7 +62,8 @@

Record an OSPool grant

{% set mine = error_form == "ospool_valuation" %}

OSPool valuation

-

Now {{ ospool_rate_text }}. A change values later days only: days already valued keep their price.

+

Now {{ ospool_rate_text }}; CPU-only jobs' core-hours at {{ ospool_cpu_rate_text }} (set on the + compute settings page). A change values later days only: days already valued keep their price.

{{ gpu_and_rate("ospool_valuation", "ospool-value", diff --git a/krater/web/templates/projects/edit.html b/krater/web/templates/projects/edit.html index e1c2c811..24407e5c 100644 --- a/krater/web/templates/projects/edit.html +++ b/krater/web/templates/projects/edit.html @@ -91,7 +91,7 @@

Edit draft

{% else %} - {{ application.application_fields(values, errors, summaries, gpu_options, applicant, word_limits, summary_max, other_gpu, kind=draft.kind.value, team=team, base_cents=base_cents) }} + {{ application.application_fields(values, errors, summaries, gpu_options, applicant, word_limits, summary_max, other_gpu, cpu_only, kind=draft.kind.value, team=team, base_cents=base_cents) }} {% endif %} {% if draft.kind.value == "completion" %} diff --git a/krater/web/templates/projects/new.html b/krater/web/templates/projects/new.html index 0e0d925c..398e1978 100644 --- a/krater/web/templates/projects/new.html +++ b/krater/web/templates/projects/new.html @@ -18,7 +18,7 @@

New proposal

- {{ application.application_fields(values, errors, summaries, gpu_options, applicant, word_limits, summary_max, other_gpu) }} + {{ application.application_fields(values, errors, summaries, gpu_options, applicant, word_limits, summary_max, other_gpu, cpu_only) }}

Nothing is checked until you submit.

diff --git a/tests/ospool/test_accounting.py b/tests/ospool/test_accounting.py index cfd165fe..0892ca93 100644 --- a/tests/ospool/test_accounting.py +++ b/tests/ospool/test_accounting.py @@ -18,8 +18,14 @@ def _ms(day: date) -> int: return int(datetime(day.year, day.month, day.day, tzinfo=UTC).timestamp() * 1000) -def _bucket(day: date, gpu: float, core: float, jobs: float) -> dict: - return {"key": _ms(day), "gpu": {"value": gpu}, "core": {"value": core}, "jobs": {"value": jobs}} +def _bucket(day: date, gpu: float, core: float, jobs: float, cpu_core: float = 0) -> dict: + return { + "key": _ms(day), + "gpu": {"value": gpu}, + "core": {"value": core}, + "jobs": {"value": jobs}, + "cpu_only": {"core": {"value": cpu_core}}, + } def _client(handler) -> LiveAccounting: @@ -32,12 +38,12 @@ def test_it_asks_for_the_projects_user_jobs_per_utc_day() -> None: def handler(request: httpx.Request) -> httpx.Response: seen.append(json.loads(request.content)) assert str(request.url) == f"{URL}?pre_filter_shard_size=1" - body = {"aggregations": {"days": {"buckets": [_bucket(date(2026, 11, 3), 10.123456, 84.0, 12.0)]}}} + body = {"aggregations": {"days": {"buckets": [_bucket(date(2026, 11, 3), 10.123456, 84.0, 12.0, 64.0)]}}} return httpx.Response(200, json=body) days = _client(handler).daily_usage("PatchworkLabs_Ganymede01", date(2026, 11, 1), date(2026, 11, 5)) - assert days == [DayUsage(date(2026, 11, 3), Decimal("10.1235"), Decimal("84.0000"), 12)] + assert days == [DayUsage(date(2026, 11, 3), Decimal("10.1235"), Decimal("84.0000"), 12, Decimal("64.0000"))] query = seen[0] assert query["size"] == 0 filters = query["query"]["bool"]["filter"] @@ -47,6 +53,12 @@ def handler(request: httpx.Request) -> httpx.Response: assert {"range": {"EndTime": {"gte": "2026-11-01", "lt": "2026-11-05"}}} in filters histogram = query["aggs"]["days"]["date_histogram"] assert histogram == {"field": "EndTime", "calendar_interval": "day", "time_zone": "UTC"} + # CPU-only jobs' cores: the records with no GPU-hours. + cpu_only = query["aggs"]["days"]["aggs"]["cpu_only"] + assert cpu_only == { + "filter": {"bool": {"must_not": [{"range": {"GPUHours": {"gt": 0}}}]}}, + "aggs": {"core": {"sum": {"field": "CoreHours"}}}, + } def test_empty_days_are_left_out() -> None: diff --git a/tests/services/test_funder_packet.py b/tests/services/test_funder_packet.py index ba72054d..7545034b 100644 --- a/tests/services/test_funder_packet.py +++ b/tests/services/test_funder_packet.py @@ -359,3 +359,11 @@ def test_a_held_project_says_so_in_its_status( [row] = funder_packet.build(db_session, weave, admin, project_ids=[project.id]).rows assert row.status_label == "Approved, awaiting 3rd party review" + + +def test_a_cpu_only_estimate_reads_as_cores_not_a_card() -> None: + gpu = funder_packet._gpu( + {"accelerator_name": "CPU only", "accelerator_count": 1, "cpu_cores": 16, "hours": 40, "basis": "on_demand"} + ) + + assert gpu is not None and gpu.text == "CPU only, 16 cores × 40h, on-demand" diff --git a/tests/services/test_ospool_grants.py b/tests/services/test_ospool_grants.py index 71b42862..1273b306 100644 --- a/tests/services/test_ospool_grants.py +++ b/tests/services/test_ospool_grants.py @@ -13,6 +13,7 @@ from krater.models import ( AuditEvent, BudgetEntry, + ComputeSettings, FundingHold, GpuPrice, OspoolUsageDay, @@ -23,7 +24,16 @@ ReviewSource, ) from krater.ospool.accounting import AccountingError, FakeAccounting -from krater.services import budget, funder_packet, funding_holds, grants, ospool_grants, pricing, projects +from krater.services import ( + budget, + compute_settings, + funder_packet, + funding_holds, + grants, + ospool_grants, + pricing, + projects, +) from krater.services.actor import Actor from krater.services.errors import InvalidState, NotAllowed, UsResidencyRequired, ValidationFailed from krater.weave import StubWeaveClient @@ -330,6 +340,77 @@ def test_a_day_without_a_price_gets_one_later(db_session, member, reviewer, admi assert ospool_grants.summary(grant).unvalued_days == 0 +def _set_cpu_price(session: Session, microusd: int) -> None: + compute_settings.org_limits(session) # makes sure the settings row exists + session.get(ComputeSettings, 1).cpu_core_hour_microusd = microusd + session.flush() + + +def test_cpu_only_core_hours_are_valued_at_krater_s_cpu_price(db_session, held_project, admin, weave) -> None: + grant = _record(db_session, admin, held_project, weave) + _set_cpu_price(db_session, 6_000) + client = FakeAccounting() + # A GPU day: its 84 core-hours come with the GPU's price; 20 of them were CPU-only jobs. + client.set_day(NAME, date(2026, 11, 3), gpu_hours="10", core_hours="84", cpu_core_hours="20", jobs=5) + client.set_day(NAME, date(2026, 11, 4), core_hours="1000", jobs=40) + + ospool_grants.import_usage(db_session, grant, client, now=NOW) + + gpu_day, cpu_day = _days(grant)[date(2026, 11, 3)], _days(grant)[date(2026, 11, 4)] + assert (gpu_day.value_cents, gpu_day.core_rate_microusd, gpu_day.core_value_cents) == (600, 6_000, 12) + assert gpu_day.worth_cents == 612 + assert (cpu_day.cpu_core_hours, cpu_day.value_cents, cpu_day.core_value_cents) == (Decimal("1000"), 0, 600) + totals = ospool_grants.summary(grant) + assert (totals.cpu_core_hours, totals.value_cents, totals.unvalued_days) == (Decimal("1020"), 1_212, 0) + assert "and 1,020.0 core-hours of CPU-only jobs at Krater's CPU price" in ospool_grants.usage_text(grant) + + # A new CPU price values later days only. + _set_cpu_price(db_session, 10_000) + client.set_day(NAME, date(2026, 11, 20), core_hours="100") + ospool_grants.import_usage(db_session, grant, client, now=NOW + timedelta(hours=1)) + + assert _days(grant)[date(2026, 11, 4)].core_value_cents == 600 + assert _days(grant)[date(2026, 11, 20)].core_value_cents == 100 + assert ospool_grants.cpu_rate_text(db_session) == "Krater's CPU price, $0.01 per core-hour" + + +def test_cpu_only_core_hours_without_a_cpu_price_wait_for_one(db_session, held_project, admin, weave) -> None: + grant = _record(db_session, admin, held_project, weave) + client = FakeAccounting() + client.set_day(NAME, date(2026, 11, 4), core_hours="500") + ospool_grants.import_usage(db_session, grant, client, now=NOW) + assert _days(grant)[date(2026, 11, 4)].worth_cents == 0 # the GPU side is priced, at 0 GPU-hours + assert ospool_grants.summary(grant).unvalued_days == 1 + assert ospool_grants.cpu_rate_text(db_session) == "no CPU price yet" + + _set_cpu_price(db_session, 6_000) + # Weeks later, outside the window the import reads again. + ospool_grants.import_usage(db_session, grant, FakeAccounting(), now=NOW + timedelta(days=60)) + + assert _days(grant)[date(2026, 11, 4)].core_value_cents == 300 + assert ospool_grants.summary(grant).unvalued_days == 0 + + +def test_days_imported_before_the_cpu_split_are_read_again_once(db_session, held_project, admin, weave) -> None: + grant = _record(db_session, admin, held_project, weave) + client = FakeAccounting() + client.set_day(NAME, date(2026, 11, 3), core_hours="50") + ospool_grants.import_usage(db_session, grant, client, now=NOW) + _days(grant)[date(2026, 11, 3)].cpu_core_hours = None # as the migration leaves an older day + later = NOW + timedelta(days=60) + + ospool_grants.import_usage(db_session, grant, client, now=later) + ospool_grants.import_usage(db_session, grant, client, now=later + timedelta(days=1)) + + assert _days(grant)[date(2026, 11, 3)].cpu_core_hours == Decimal("50") + # The whole history once, then only the recent window again. + assert [call[1] for call in client.calls] == [ + date(2026, 11, 1), + date(2026, 11, 1), + (later + timedelta(days=1)).date() - timedelta(days=ospool_grants.REIMPORT_DAYS), + ] + + def test_a_failed_import_is_recorded_and_keeps_the_last_usage(db_session, held_project, admin, weave) -> None: grant = _record(db_session, admin, held_project, weave) client = FakeAccounting() diff --git a/tests/web/test_application_form.py b/tests/web/test_application_form.py index b9f579a0..e4018be1 100644 --- a/tests/web/test_application_form.py +++ b/tests/web/test_application_form.py @@ -10,8 +10,8 @@ from fastapi.testclient import TestClient from sqlalchemy.orm import Session -from krater.models import GpuPrice, Project, ProjectMember, ProjectRevision, ProjectStatus -from krater.services import budget +from krater.models import ComputeSettings, GpuPrice, Project, ProjectMember, ProjectRevision, ProjectStatus +from krater.services import budget, compute_settings from krater.services import projects as project_service from tests.conftest import MEMBER_SUB, OTHER_MEMBER_SUB, REVIEWER_SUB, get_csrf_token from tests.factories import estimate @@ -158,6 +158,80 @@ def test_another_card_needs_its_price(client: TestClient, login_as) -> None: assert "Give this card's price per hour." in response.text +def test_the_team_can_ask_for_a_cpu_only_machine(client: TestClient, login_as, db_session: Session) -> None: + login_as(MEMBER_SUB) + + response = _create( + client, + poc_gpu="cpu", + poc_cpu_cores="16", + poc_rate="0.09", + poc_basis="on_demand", + full_gpu="cpu", + full_cpu_cores="32", + full_rate="0.15", + ) + + assert response.status_code == 303 + revision = _revision(db_session, response) + estimate = revision.budget_estimate + assert (estimate["accelerator_name"], estimate["accelerator_count"], estimate["cpu_cores"]) == ("CPU only", 1, 16) + assert estimate["rate_source"] == "member" and estimate["market_rate_cents"] is None + # $0.09 a machine-hour x 40h, whatever the core count + assert estimate["total_cents"] == 360 + assert revision.full_budget_estimate["cpu_cores"] == 32 + detail = client.get(response.headers["location"]).text + assert "CPU only, 16 cores × 40h at $0.09/hr (on-demand)" in detail + # The edit form comes back on "CPU only" with the cores and price filled in. + project_id = response.headers["location"].removeprefix("/projects/") + edit = client.get(f"/projects/{project_id}/edit").text + assert re.search(r'