Skip to content
tyh0123Public

About

RL STEM

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STEM auto aberration correction — quick start

Current variant: multi_agent_correction_evolving_test7_80kV (80 kV). Other multi_agent_correction* folders work the same way.

0. Environment (every terminal)

conda activate RL_STEM          # bare `python` is the Store stub; base Anaconda is numpy-2 broken
cd multi_agent_correction_evolving_test7_80kV

0b. Claude API access

Normally you set nothing. Opening a PowerShell terminal loads the profile, which exports the CBORG credential and endpoint:

Variable Set by Purpose
ANTHROPIC_AUTH_TOKEN profile, from d:\user_data\ercius\.cborg_key.txt the CBORG key
ANTHROPIC_BASE_URL profile (and config.py) https://api.cborg.lbl.gov
ANTHROPIC_API_KEY persisted at User scope fallback credential

config.py sets the endpoint and model itself (USE_CBORG = True, amazon/claude-opus-4-8) rather than trusting the shell, and picks the credential in this order — exactly one survives, because the SDK refuses to build a client with two set:

CBORG_API_KEY  ->  ANTHROPIC_AUTH_TOKEN  ->  ANTHROPIC_API_KEY

To supply the key yourself, use CBORG_API_KEY — it has top precedence, so it works whether or not the profile loaded. (A key placed in ANTHROPIC_API_KEY is last and gets ignored while the profile's token is present.)

$env:CBORG_API_KEY = "sk-..."                                           # this terminal only
[Environment]::SetEnvironmentVariable('CBORG_API_KEY','sk-...','User')  # persistent

The persistent form does not affect the terminal you type it in — open a new one. It also stores the key in plaintext in the registry, so prefer the session-only form unless the profile route is failing.

Set USE_CBORG = False in config.py for native Anthropic instead, with a sk-ant-... key in ANTHROPIC_API_KEY.

python -u check_claude.py prints which credential, endpoint and model are in play. Three things that go wrong:

  • "key not set" in a terminal that used to work — environment variables are inherited from the parent process, not re-read, so a setx or profile change is invisible to terminals already open. Open a new one, or for a single run: $env:ANTHROPIC_API_KEY = [Environment]::GetEnvironmentVariable('ANTHROPIC_API_KEY','User')
  • 401 from CBORG — a native sk-ant-... key reached CBORG. Check the credential line check_claude.py prints.
  • Do not set CLAUDE_MODEL — it overrides the model chosen in config.py.

ANTHROPIC_MODEL and ANTHROPIC_SMALL_FAST_MODEL in the profile configure the Claude Code CLI only; the Python SDK ignores them.

1. Start the instrument server

On the microscope PC, from the repo root:

python microscope_server.py --serverport 7001

2. Preflight (read-only, commands nothing)

python -u check_claude.py            # endpoint + model + one tiny call
python -u check_instrument.py        # ping, kV, fast C1A1

Put the stage on a flat, crystalline area first — the verify agent images a lattice at 3.6 Mx and fails over vacuum.

3. Run the agent

python -u orchestrator.py --mock --max-iters 3   # simulator, no hardware
python -u orchestrator.py --max-iters 5          # supervised first real run
python -u orchestrator.py                        # full session

Each iteration: C1A1 gate → measure → decide → apply. Logs land in logs/.

4. Learn from the session

python -u run_analysis.py            # reads logs/, updates skills/decision_rules.md

Changes are recorded in skills/CHANGELOG.md; the previous rules are kept in skills/archive/.

5. Optional — run without the agent

Once the rules are settled, compile them into a standalone program that makes the same decisions with no LLM calls:

cd ..\rule_compiler
python compile_rules.py --variant ..\multi_agent_correction_evolving_test7_80kV
cd generated
python correct_test7_80kV_<stamp>.py --dry-run   # what the rules say it will do
python correct_test7_80kV_<stamp>.py --mock      # simulator
python correct_test7_80kV_<stamp>.py             # the instrument

It stops and hands back if it hits a state the rules do not cover (today: B2 and S3, whose signs are not yet established). Then run step 3 for those.

About

RL STEM

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages