Skip to content

Fix reversed anode/cathode polarity on battery/generator - #90

Open
pangwangshu wants to merge 1 commit into
allenai:mainfrom
pangwangshu:wapang/issue50
Open

Fix reversed anode/cathode polarity on battery/generator#90
pangwangshu wants to merge 1 commit into
allenai:mainfrom
pangwangshu:wapang/issue50

Conversation

@pangwangshu

Copy link
Copy Markdown

Summary

Fixes #50.

Generator.tick() assigned voltage to the anode and ground to the cathode, but PolarizedElectricalComponent.tick() (inherited by LightBulb, ElectricMotor, ElectricBuzzer) only activates a load when its anode connects to ground and its cathode connects to voltage. Because Terminal.connectsToGround() stops traversal as soon as it reaches a generator terminal, this mismatch meant wiring a battery "naturally" (anode-to-anode, cathode-to-cathode, as the issue describes) never completed a circuit — only the crossed wiring (anode-to-cathode) worked. This is exactly why the gold-agent action sequences had been wiring devices crossed as a workaround.

  • Swap the terminal voltage assignment in Generator.tick() (simulator/.../Generator.scala) so activation now requires natural, same-name wiring. This fixes Battery and every other source that extends Generator (GasGenerator, NuclearGenerator, SolarPanel, WindGenerator) without touching the load side.
  • Update the gold action sequences in TaskElectricCircuit, TaskElectricalConductivity, and TaskElectricalConductivity2 to wire devices naturally instead of crossed, matching the fixed polarity.
  • Rebuild scienceworld/scienceworld.jar.

The issue also asks to "regenerate training data" — that refers to the separately-built goldpaths-all.zip archive produced by an external/offline process outside this repo, out of scope for this change.

Test plan

  • ./simulator/package.sh — builds cleanly; rebuilt jar is byte-identical to the committed one
  • Replayed the gold action sequence for all 4 affected tasks via the Python API — each now wires anode-to-anode/cathode-to-cathode and reaches score 100: task-2-power-component, task-2-power-component-(renewable-vs-nonrenewable-energy), task-2a-test-conductivity, task-2a-test-conductivity-of-unknown-substances
  • pytest tests/test_scienceworld.py — 7 passed
  • tox -e flake8 — clean
  • tox -e precommit — clean on all hooks that apply to the changed files (the shellcheck hook itself can't run in this sandbox due to a CPU-architecture mismatch in the downloaded binary, unrelated to this change — no shell scripts were touched)
  • Full OS × Python CI matrix — relies on GitHub Actions, which will run on this PR

🤖 Generated with Claude Code

Generator.tick() put voltage on the anode and ground on the cathode,
but every polarized load (LightBulb, ElectricMotor, ElectricBuzzer)
only activates when its anode connects to ground and its cathode
connects to voltage. This mismatch meant wiring a battery "naturally"
(anode-to-anode, cathode-to-cathode) never completed a circuit; only
the crossed wiring worked, which is why the gold-agent action
sequences had been wiring devices crossed as a workaround.

Swap the Generator's terminal assignment so natural, same-name wiring
works as expected, and update the gold action sequences in
TaskElectricCircuit, TaskElectricalConductivity, and
TaskElectricalConductivity2 to match. Rebuild scienceworld.jar.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anode/Cathode on battery appears reversed

1 participant