Skip to content

Hotfix/style cleanup - #38

Merged
Tinitto merged 5 commits into
sopherapps:mainfrom
ch-ahindura:hotfix/style-cleanup
Aug 5, 2026
Merged

Hotfix/style cleanup#38
Tinitto merged 5 commits into
sopherapps:mainfrom
ch-ahindura:hotfix/style-cleanup

Conversation

@ch-ahindura

Copy link
Copy Markdown
Collaborator

Why

Just cleaning up some python code smells.

check_docs.py carried its three checks in one 387-line file, separated by banner
comments — the kind future contributors read past. Each check is now its own
module under scripts/_check_docs, named after what it checks, and check_docs.py is
the entry point that walks the documents and calls them. The module docstring
still lists the three, now pointing at the module each lives in. `make
test-docs-static` invokes it the same way and reports the same 151 claims across
20 documents.

document.py holds what all three need: the Line/Report types, reading a document's
code spans, and finding the documents. Its EXCLUDED comment said "see the module
docstring" for why CHANGELOG.md is skipped, which was true in the old single file
and dangling here, so it states the reason itself.

Four functions renamed while they moved, since they are the ones the split made
awkward: cli_flags() shadowed the module it now lives in, and makefile_targets(),
documents() and a bare read() were nouns for things that go and fetch. They are
read_cli_flags, read_makefile_targets, find_documents and read_lines.

check_cli_flags opened with an assignment that the loop on the next line always
overwrote. Dropped; finditer yields at least one match wherever the search that
guards the branch matched.

scripts/ had no importable package before this, so nothing ever left a __pycache__
there and no .gitignore covered it — the SDKs ignore bytecode in their own. A root
rule now catches the rest of the tree.
client.py and provider.py divided their classes with banner comments — "-- public
API ---", "-- execution ---", and twelve more. Every method under them already has
a docstring saying what it does, so the banners were labelling groups that named
themselves, and they are the first thing to go stale when a method moves.

Fourteen removed, nothing else touched.
"New E2E tests for recently added features" sat above twenty test functions, which
is every test in the second half of the file — it dated them rather than grouping
them, and the features stopped being recent some releases ago.

_BLUEFORS_CHANNELS was defined fifteen hundred lines in, immediately above the
first helper that reads it. It joins the other module constants at the top.

The file is not ruff-formatted and this does not change that; reformatting it would
bury two lines of intent in six hundred lines of rewrapping.
…nd lift constants

The four functions that paper over quantify-scheduler and qblox-scheduler
disagreeing about a compiled schedule sat at the bottom of coordinator.py under a
banner comment carrying the whole explanation — which of the two spells pulse_info
as a list, where a subschedule keeps its operations, whether a drive amplitude is
G_amp or amplitude. That is a module's worth of one subject, so it is
simulation/_compiled_schedule.py now and the banner's prose is its docstring.

Renamed on the way out, because the names only read inside the file that defined
them: infos() said nothing about returning pulse or acquisition entries, and
operations_of/amplitude_of were nouns. They are read_info_entries,
read_operations, read_amplitude, and is_subschedule keeps its name.

Constants moved to the top of their modules, out from between the functions that
use them: MAX_ENTANGLED and the four drive-step and propagator-cache bounds in
coordinator.py, MAX_BROADENING in lorentzian.py, _DEPARTED/_RETURNED in
chevron.py, GRID_NS in tuners/base/routines.py, BIAS_KEYS in coupler_bias.py.
Every comment above them moved too.

The remaining banners in transmon.py, coupled.py, agent.py, dag.py and
coordinator.py are gone. One was load-bearing — routines.py explained what a check
is and why the two methods mirror build_schedule/analyse — so that went into
build_check_schedule's docstring rather than the bin.

Constants left where they are: DEVICE_SPEC in bluefors_gen1.py, DEVICE_SPECS in
qpu.py and calibrate.py, DeviceBuilder and _DEVICES in registry.py. Each is built
from a function or class defined above it and cannot move over its own dependency.
… real names

tests/utils.py held fixture loading and qiskit gate-conversion assertions in one
file, and tests/fixtures/ held two Python modules beside its data files. Helpers
are now a tests/utils package split by subject: io.py loads the fixture data,
circuits.py compares a converted gate against qiskit's own unitary,
simulation.py holds the transmon test doubles, half_imported_device.py is still the
module that fails to import. fixtures/ is data files only, and says so.

The nine test modules that divided their tests with banner comments now use test
classes. Each banner's title became the class name and its prose the class
docstring, so what was a comment is now something pytest prints and a reader can
find — TestTheWholeDagThroughTheRealStack rather than "--- the whole DAG, through
the real stack ---". Helpers and constants that sat between the tests of a section
move above the class they serve. Where a banner only restated the single docstring
below it, it is simply gone.

No test changed behaviour: pytest collects the same 739 items before and after,
identical once class names are stripped from the node IDs, and the suite is 615
passed / 124 skipped either way. The skips are the second scheduler's
parametrisation, as before.

test_discovery.py's dotted paths for the moved module are four characters shorter,
which let ruff rejoin a wrapped assertion.

@Tinitto Tinitto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Tinitto
Tinitto merged commit a3d8145 into sopherapps:main Aug 5, 2026
41 checks passed
@ch-ahindura
ch-ahindura deleted the hotfix/style-cleanup branch August 7, 2026 09:40
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.

2 participants