Skip to content

refactor(pyamber): extract shared canonicalize_port_id helper - #9610

Open
Ma77Ball wants to merge 1 commit into
apache:mainfrom
Ma77Ball:refactor/pyamber-port-id-normalization
Open

Ma77Ball wants to merge 1 commit into
apache:mainfrom
Ma77Ball:refactor/pyamber-port-id-normalization

Conversation

@Ma77Ball

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

  • Added a module-level canonicalize_port_id(port_id) in input_manager that defaults a PortIdentity's unset id/internal fields in place (id 0, internal False) and returns it.
  • InputManager.add_input_port, InputManager.get_port, InputManager.register_input, and OutputManager.add_output_port now call the helper instead of repeating the two if-None blocks; behavior, including the in-place mutation, is unchanged.

Any related issues, documentation, discussions?

Closes: #9607

How was this PR tested?

  • Run: cd amber && pytest src/test/python/core/architecture/packaging/test_input_manager.py src/test/python/core/architecture/packaging/test_output_manager.py (expect all green, 70 tests).
  • Existing TestPortIdentityDefaults and TestAddOutputPort still pass (behavior preserved through the call sites); new TestCanonicalizePortId checks in-place defaulting with identity-preserving return and already-set fields left untouched.

Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF

input_manager now defines a module-level canonicalize_port_id(port_id) that fills a PortIdentity's unset id/internal fields with their defaults (id 0, internal False) in place and returns it. A PortIdentity arrives from protobuf where an unset scalar reaches Python as None, so every path that keys a port by identity must canonicalize it first or the same logical port hashes to two map entries.

InputManager.add_input_port, InputManager.get_port, InputManager.register_input, and OutputManager.add_output_port now call this helper instead of repeating the two if-None blocks; OutputManager imports it from input_manager, which it already depends on for WorkerPort and Channel. Behavior is unchanged, including the in-place mutation of the caller's PortIdentity that the existing manager tests rely on.

test_input_manager adds TestCanonicalizePortId covering the in-place defaulting with identity-preserving return and the already-set case left untouched.
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @carloea2
    You can notify them by mentioning @carloea2 in a comment.

@codecov-commenter

codecov-commenter commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.58%. Comparing base (9647f58) to head (041e306).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9610   +/-   ##
=========================================
  Coverage     91.57%   91.58%           
  Complexity     5182     5182           
=========================================
  Files          1300     1300           
  Lines         58133    58127    -6     
  Branches       7615     7609    -6     
=========================================
- Hits          53236    53234    -2     
+ Misses         2959     2957    -2     
+ Partials       1938     1936    -2     
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø) Carriedforward from 9647f58
agent-service 99.56% <ø> (ø) Carriedforward from 9647f58
amber 85.45% <ø> (ø) Carriedforward from 9647f58
computing-unit-managing-service 63.88% <ø> (ø) Carriedforward from 9647f58
config-service 87.50% <ø> (ø) Carriedforward from 9647f58
file-service 82.16% <ø> (ø) Carriedforward from 9647f58
frontend 96.46% <ø> (ø) Carriedforward from 9647f58
notebook-migration-service 83.77% <ø> (ø) Carriedforward from 9647f58
pyamber 98.46% <100.00%> (+0.08%) ⬆️
result-service 85.71% <ø> (ø) Carriedforward from 9647f58
workflow-compiling-service 78.30% <ø> (ø) Carriedforward from 9647f58

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 4 better · 🔴 7 worse · ⚪ 4 noise (<±5%) · 0 without baseline

Compared against main f030df1 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 410 0.25 22,860/44,979/44,979 us 🔴 +42.0% / 🔴 +224.5%
🔴 bs=100 sw=10 sl=64 808 0.493 121,800/143,219/143,219 us 🔴 +7.5% / 🔴 +64.6%
🟢 bs=1000 sw=10 sl=64 973 0.594 1,025,202/1,057,315/1,057,315 us 🟢 -6.9% / 🔴 +32.0%
Baseline details

Latest main f030df1 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 410 tuples/sec 438 tuples/sec 1,019 tuples/sec -6.4% -59.8%
bs=10 sw=10 sl=64 MB/s 0.25 MB/s 0.267 MB/s 0.622 MB/s -6.4% -59.8%
bs=10 sw=10 sl=64 p50 22,860 us 23,280 us 10,136 us -1.8% +125.5%
bs=10 sw=10 sl=64 p95 44,979 us 31,682 us 13,860 us +42.0% +224.5%
bs=10 sw=10 sl=64 p99 44,979 us 31,682 us 16,484 us +42.0% +172.9%
bs=100 sw=10 sl=64 throughput 808 tuples/sec 857 tuples/sec 1,363 tuples/sec -5.7% -40.7%
bs=100 sw=10 sl=64 MB/s 0.493 MB/s 0.523 MB/s 0.832 MB/s -5.7% -40.8%
bs=100 sw=10 sl=64 p50 121,800 us 113,300 us 79,194 us +7.5% +53.8%
bs=100 sw=10 sl=64 p95 143,219 us 152,556 us 87,022 us -6.1% +64.6%
bs=100 sw=10 sl=64 p99 143,219 us 152,556 us 106,894 us -6.1% +34.0%
bs=1000 sw=10 sl=64 throughput 973 tuples/sec 974 tuples/sec 1,407 tuples/sec -0.1% -30.8%
bs=1000 sw=10 sl=64 MB/s 0.594 MB/s 0.595 MB/s 0.859 MB/s -0.2% -30.8%
bs=1000 sw=10 sl=64 p50 1,025,202 us 1,021,165 us 776,422 us +0.4% +32.0%
bs=1000 sw=10 sl=64 p95 1,057,315 us 1,135,306 us 814,091 us -6.9% +29.9%
bs=1000 sw=10 sl=64 p99 1,057,315 us 1,135,306 us 860,577 us -6.9% +22.9%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,487.74,200,128000,410,0.250,22860.12,44978.94,44978.94
1,100,10,64,20,2473.84,2000,1280000,808,0.493,121800.38,143218.96,143218.96
2,1000,10,64,20,20553.63,20000,12800000,973,0.594,1025201.51,1057315.06,1057315.06

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pyamber refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract shared canonicalize_port_id helper in packaging managers

2 participants