|
| 1 | +--- |
| 2 | +name: implement-method |
| 3 | +description: Implements a new method (scalarizer or aggregator) in TorchJD, starting from the research produced by the research-method skill and following the established file-by-file conventions. Use when a contributor wants to add the actual implementation of a scalarizer or aggregator that has already been investigated and listed in the tracking issues. |
| 4 | +--- |
| 5 | + |
| 6 | +# Implement new method |
| 7 | + |
| 8 | +This skill implements a new method by recovering its research, comparing the paper against the |
| 9 | +existing implementations, settling the non-standard parts of its interface, and producing the full |
| 10 | +set of TorchJD files (class, docs, tests, changelog) that match the established conventions. |
| 11 | + |
| 12 | +It is the companion of the `research-method` skill: that one investigates a method and records a row |
| 13 | +in a tracking issue; this one turns that row into a merged implementation. |
| 14 | + |
| 15 | +**For agents:** invoke as `/implement-method method-name (paper-name)` (e.g. |
| 16 | +`/implement-method stch (Smooth Tchebycheff Scalarization for Multi-objective Optimization)`). |
| 17 | +If no method name is provided, ask the user for the name of the method and the title of the paper. |
| 18 | + |
| 19 | +**For humans:** follow the numbered steps below to guide your development. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Instructions |
| 24 | + |
| 25 | +### Step 1: Recover the research context |
| 26 | + |
| 27 | +Determine whether the method should be a **scalarizer** or an **aggregator**, then read everything |
| 28 | +the `research-method` skill already found about it: |
| 29 | + |
| 30 | +- Scalarizers are tracked in https://github.com/SimplexLab/TorchJD/issues/667, aggregators in |
| 31 | + https://github.com/SimplexLab/TorchJD/issues/665. Fetch the relevant issue and find the row for |
| 32 | + this method. Read every column: |
| 33 | + - **Ref** — the paper (open it; you will need the exact equations / algorithm). |
| 34 | + - **Stateful** — whether and how the method holds state. |
| 35 | + - **Existing implementations** — links to the official repo (if any) and the best-known |
| 36 | + third-party ones (LibMTL, libmoon, pymoo, ...), ideally with the exact file(s) and line(s). |
| 37 | + - **Special Remarks** — may link to a full research write-up (e.g. a `claude.ai` share produced by |
| 38 | + `research-method`). Read it if present. |
| 39 | +- The most valuable inputs are the **non-standard interface aspects** uncovered during research: |
| 40 | + statefulness, trainable parameters, randomness, warm-up / history buffers, statistics beyond the |
| 41 | + `forward` values (e.g. per-task losses for an aggregator), and preconditions. If these are not |
| 42 | + fully captured in the issue, **ask the user to share the `research-method` findings** before |
| 43 | + continuing. Do not guess them. |
| 44 | + |
| 45 | +If the method is not in the tracking issue yet, run `research-method` first. |
| 46 | + |
| 47 | +### Step 2: Load the implementation reference for this method type |
| 48 | + |
| 49 | +Read only the reference matching the method type, to keep context focused: |
| 50 | + |
| 51 | +- **Scalarizer** → read `references/scalarizers.md`. |
| 52 | +- **Aggregator** → read `references/aggregators.md`. |
| 53 | + |
| 54 | +Each reference lists the exact files to create/edit and the TorchJD-specific conventions, with the |
| 55 | +closest existing methods to mirror. |
| 56 | + |
| 57 | +### Step 3: Compare the paper with the existing implementations |
| 58 | + |
| 59 | +Always do this — it is the step we invariably end up needing. Read the relevant equations / the |
| 60 | +algorithm box in the paper, then read the official and best-known third-party implementations at the |
| 61 | +exact files/lines from the tracking row. |
| 62 | + |
| 63 | +Reconcile any discrepancies between them. The ones that most often bite: |
| 64 | + |
| 65 | +- **Minimization vs maximization.** TorchJD minimizes losses; much MOO/evolutionary work is written |
| 66 | + for maximization, with the minimization form buried in a footnote. Find it, and check the sign of |
| 67 | + every reference / ideal-point subtraction. |
| 68 | +- **Normalization.** A direction or weight vector may be normalized (`w / ‖w‖`) in the code but not |
| 69 | + the paper, or vice versa. |
| 70 | +- **Dead arguments.** An impl may accept a parameter (e.g. a reference point) yet silently ignore it. |
| 71 | +- **Droppable terms.** An `abs` / `clamp` / `max(0, ·)` in the paper may be unnecessary under the |
| 72 | + method's preconditions (e.g. non-negative weights); drop it only with a justification. |
| 73 | +- **Other:** an extra factor, an init value, a stabilization / epsilon trick. |
| 74 | + |
| 75 | +Decide which to follow, note **why**, and surface the disagreement to the user — the implementation |
| 76 | +should be faithful to a clearly-stated source, not an unexplained blend. |
| 77 | + |
| 78 | +### Step 4: Settle the interface and design decisions |
| 79 | + |
| 80 | +Using the research findings (Step 1) and the comparison (Step 3), map each non-standard aspect onto |
| 81 | +the closest existing pattern from the reference loaded in Step 2 (statefulness, trainable parameters, |
| 82 | +an internal optimizer, a preference/reference vector, ...). Then settle, for any method type: |
| 83 | + |
| 84 | +- **Preconditions** (e.g. positivity): enforce them (raise `ValueError`) or only document them, and |
| 85 | + how `nan`/`inf` should propagate. |
| 86 | +- Which constructor arguments are **required vs optional**, and their **defaults**. |
| 87 | + |
| 88 | +List the non-standard parts and your proposed handling, and **confirm the design with the user |
| 89 | +before writing code.** This is where most of the maintainer review happens, so settle it up front. |
| 90 | + |
| 91 | +### Step 5: Implement the method |
| 92 | + |
| 93 | +Follow the file-by-file checklist in the reference loaded at Step 2. Match the style, naming, and |
| 94 | +conventions of the closest existing method. If you adapt code from a third-party repository, add the |
| 95 | +license header to the source file and an entry to `NOTICES` (see the reference). |
| 96 | + |
| 97 | +### Step 6: Verify |
| 98 | + |
| 99 | +Run the checks listed in the reference (unit tests with `-W error`, lint, and the docs |
| 100 | +build/doctest). GPU tests require a CUDA device; if you cannot run them, provide the exact commands |
| 101 | +for the user to run on their GPU and report back the results. |
| 102 | + |
| 103 | +### Step 7: Self-review the code you produced |
| 104 | + |
| 105 | +Before opening anything, re-read your own diff against the requirements and improve what can be |
| 106 | +improved. Check that: |
| 107 | + |
| 108 | +- The class follows the closest existing method's conventions (the reference's checklist): correct |
| 109 | + base class(es), `forward(self, values, /)` returning a 0-dim scalar, shape validation, `reset()` |
| 110 | + for stateful methods, a correct `__repr__`, and the docstring conventions (`r"""` only with LaTeX, |
| 111 | + `:class:` cross-ref, `.. math::` + bullet list, a usage doctest, `:param:` for each argument). |
| 112 | +- The design decisions settled in Step 4 are actually reflected in the code, and any discrepancy |
| 113 | + between the paper and the existing implementations (Step 3) is resolved deliberately, with a |
| 114 | + comment or docstring note where it is non-obvious. |
| 115 | +- The tests cover the documented edge cases and contracts, not just the happy path. |
| 116 | +- All six files are present and consistent (class, `__init__.py`, `.rst`, toctree, test, |
| 117 | + `CHANGELOG.md`), plus `NOTICES` + a license header if you adapted code. |
| 118 | + |
| 119 | +Apply the fixes you find, then re-run the relevant checks from Step 6. |
| 120 | + |
| 121 | +### Step 8: Open a draft PR |
| 122 | + |
| 123 | +Create a new branch, commit, and open a **draft** pull request targeting `main`, following the |
| 124 | +repository's PR conventions (a `CHANGELOG.md` entry under `[Unreleased] > ### Added`; when asked for |
| 125 | +a PR description, output raw GitHub-flavored markdown in a fenced code block, with GitHub math syntax |
| 126 | +`$...$` / `$$...$$` and no em dashes). Keep it a draft so the contributor can read the code |
| 127 | +themselves before requesting maintainer review. Return the PR URL when done. |
| 128 | + |
| 129 | +--- |
0 commit comments