Skip to content

✨ Sorting designed SiDB gates - #552

Open
wlambooy wants to merge 264 commits into
cda-tum:mainfrom
wlambooy:designed_gates_sorting
Open

✨ Sorting designed SiDB gates#552
wlambooy wants to merge 264 commits into
cda-tum:mainfrom
wlambooy:designed_gates_sorting

Conversation

@wlambooy

@wlambooy wlambooy commented Oct 30, 2024

Copy link
Copy Markdown
Collaborator

Description

This PR introduces an extension to is_operational and design_sidb_gates. The former is now able to return the simulation results that certify the status OPERATIONAL, which may then be used by the extension to the latter, which uses the simulation results to return the designed layouts in a specific ordering. This PR implements a simple heuristic for this ordering, namely it prefers the layouts for the the ground state isolation is large, ie., the energetic gap between the ground state and the first excited state. Specifically, it sorts by the minimum ground state isolation for each input.

To use this new feature when designing SiDB gates, make sure that all combinations are enumerated, and set the post_design_process parameter to PREFER_ENERGETICALLY_ISOLATED_GROUND_STATES.

Checklist:

  • The pull request only contains commits that are related to it.
  • I have added appropriate tests and documentation.
  • I have added a changelog entry.
  • I have created/adjusted the Python bindings for any new or updated functionality.
  • I have made sure that all CI jobs on GitHub pass.
  • The pull request introduces no new warnings and follows the project's style guidelines.

Summary by CodeRabbit

  • New Features
    • Added richer SiDB “operational assessment” outputs (overall status plus optional per-input results), including new Python assessment types.
    • Enhanced SiDB gate design configuration with lattice-specific parameter classes (100/111), richer mode/termination controls, and post-design ordering using ground-state isolation.
    • Introduced separate configuration for kink handling vs positive-charge feasibility.
  • Bug Fixes
    • Improved handling of edge cases where no valid configuration exists (including zero-entity combination generation).
  • Documentation
    • Updated SiDB gate design, operational-domain, and Python API documentation to match the new outputs and configuration.
  • Tests
    • Refreshed unit tests for the updated APIs and parameter fields.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread test/algorithms/simulation/sidb/is_operational.cpp Outdated
Comment thread test/algorithms/simulation/sidb/is_operational.cpp Outdated
Comment thread test/algorithms/simulation/sidb/is_operational.cpp Outdated
Comment thread test/algorithms/simulation/sidb/is_operational.cpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Fixed
@Drewniok Drewniok added the enhancement New feature or request label Nov 1, 2024

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
wlambooy and others added 3 commits November 13, 2024 00:20
…ned_gates_sorting

# Conflicts:
#	include/fiction/algorithms/physical_design/design_sidb_gates.hpp

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread include/fiction/algorithms/physical_design/design_sidb_gates.hpp Outdated
@marcelwa

Copy link
Copy Markdown
Collaborator

@wlambooy is this PR still under active development, or can it be closed?

@wlambooy

Copy link
Copy Markdown
Collaborator Author

@wlambooy is this PR still under active development, or can it be closed?

I actually started merging it with main yesterday (big task in this case). It is a good starting point for the advanced circuit design I'm getting into. I'll let you know if this PR will stay or if it will be part of a different one.

@wlambooy

wlambooy commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator Author

The changes in this PR introduce some functionality that is fundamental to the new circuit design project that I'm working on now. By merging these changes in main already soon, we prevent having some massive PR later

@wlambooy
wlambooy requested a review from Drewniok February 3, 2025 12:35
@codecov

codecov Bot commented Feb 3, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.79300% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.12%. Comparing base (f8ba413) to head (1089568).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...ulation/sidb/compare_by_ground_state_isolation.hpp 61.53% 15 Missing ⚠️
...tion/algorithms/simulation/sidb/is_operational.hpp 96.63% 4 Missing ⚠️
...ms/physical_design/compare_designed_sidb_gates.hpp 90.90% 2 Missing ⚠️
...t/algorithms/physical_design/design_sidb_gates.cpp 99.23% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #552      +/-   ##
==========================================
- Coverage   98.16%   98.12%   -0.04%     
==========================================
  Files         261      263       +2     
  Lines       40105    40417     +312     
  Branches     2110     2130      +20     
==========================================
+ Hits        39370    39661     +291     
- Misses        735      756      +21     
Files with missing lines Coverage Δ
.../algorithms/physical_design/apply_gate_library.hpp 100.00% <ø> (ø)
...n/algorithms/physical_design/design_sidb_gates.hpp 97.73% <100.00%> (-0.56%) ⬇️
...clude/fiction/algorithms/physical_design/exact.hpp 89.60% <100.00%> (ø)
...imulation/sidb/calculate_energy_and_state_type.hpp 100.00% <100.00%> (ø)
...lgorithms/simulation/sidb/critical_temperature.hpp 95.83% <100.00%> (+0.08%) ⬆️
...on/algorithms/simulation/sidb/defect_influence.hpp 95.95% <100.00%> (ø)
...simulation/sidb/displacement_robustness_domain.hpp 98.11% <100.00%> (+0.01%) ⬆️
.../algorithms/simulation/sidb/operational_domain.hpp 94.43% <100.00%> (ø)
...iction/technology/sidb_on_the_fly_gate_library.hpp 74.35% <100.00%> (+0.53%) ⬆️
include/fiction/utils/layout_utils.hpp 99.16% <100.00%> (ø)
... and 12 more

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 304948a...1089568. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Willem Lambooy <35612535+wlambooy@users.noreply.github.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated
Comment thread include/fiction/algorithms/simulation/sidb/is_operational.hpp Outdated

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.

could you make sure to use #if (FICTION_ALGLIB_ENABLED) where CC is used.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I actually do not see any uses. Did I miss something?

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.

Yes, in one test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I double checked it again. There is only one removed mention of CLUSTERCOMPLETE. Please check if your comment still holds

wlambooy and others added 21 commits August 11, 2025 15:13
# Conflicts:
#	bindings/mnt/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp
#	bindings/mnt/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
#	bindings/mnt/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py
#	bindings/mnt/pyfiction/test/algorithms/simulation/sidb/test_is_operational.py
#	include/fiction/algorithms/physical_design/design_sidb_gates.hpp
#	include/fiction/algorithms/simulation/sidb/is_operational.hpp
Signed-off-by: GitHub Actions <actions@github.com>
# Conflicts:
#	bindings/mnt/pyfiction/include/pyfiction/documentation.hpp
#	bindings/mnt/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
#	bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp
#	bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/is_operational.cpp
#	bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/sidb_simulation_parameters.cpp
#	bindings/mnt/pyfiction/src/pyfiction/inout/write_qca_layout.cpp
#	bindings/mnt/pyfiction/src/pyfiction/layouts/cartesian_layout.cpp
#	bindings/mnt/pyfiction/src/pyfiction/layouts/coordinates.cpp
#	bindings/mnt/pyfiction/src/pyfiction/layouts/gate_level_layout.cpp
#	bindings/mnt/pyfiction/src/pyfiction/layouts/hexagonal_layout.cpp
#	bindings/mnt/pyfiction/src/pyfiction/layouts/obstruction_layout.cpp
#	bindings/mnt/pyfiction/src/pyfiction/layouts/shifted_cartesian_layout.cpp
#	experiments/standard_cell_design/quickcell_vs_automatic_exhaustive_2_input.cpp
#	include/fiction/algorithms/physical_design/design_sidb_gates.hpp
#	include/fiction/technology/sidb_cluster_hierarchy.hpp
#	libs/CMakeLists.txt
#	test/algorithms/physical_design/design_sidb_gates.cpp
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0fd3e08-2c5b-4135-8b78-ae7491571515

📥 Commits

Reviewing files that changed from the base of the PR and between b49de62 and 1089568.

📒 Files selected for processing (16)
  • experiments/sidb_simulation/temperature/critical_temperature_simulation_bestagon.cpp
  • experiments/sidb_simulation/temperature/critical_temperature_simulation_siqad.cpp
  • experiments/standard_cell_design/automatic_exhaustive_gate_design.cpp
  • experiments/standard_cell_design/quickcell_3_input.cpp
  • experiments/standard_cell_design/quickcell_rectangular_gate_library.cpp
  • experiments/standard_cell_design/quickcell_vs_automatic_exhaustive_2_input.cpp
  • include/fiction/algorithms/physical_design/compare_designed_sidb_gates.hpp
  • include/fiction/algorithms/physical_design/exact.hpp
  • include/fiction/algorithms/simulation/sidb/compare_by_ground_state_isolation.hpp
  • include/fiction/algorithms/simulation/sidb/critical_temperature.hpp
  • include/fiction/algorithms/simulation/sidb/is_operational.hpp
  • test/algorithms/physical_design/design_sidb_gates.cpp
  • test/algorithms/simulation/sidb/is_operational.cpp
  • test/algorithms/simulation/sidb/operational_domain_ratio.cpp
  • test/algorithms/simulation/sidb/verify_logic_match.cpp
  • test/utils/math_utils.cpp
💤 Files with no reviewable changes (7)
  • experiments/sidb_simulation/temperature/critical_temperature_simulation_bestagon.cpp
  • experiments/standard_cell_design/quickcell_3_input.cpp
  • experiments/sidb_simulation/temperature/critical_temperature_simulation_siqad.cpp
  • experiments/standard_cell_design/quickcell_rectangular_gate_library.cpp
  • experiments/standard_cell_design/quickcell_vs_automatic_exhaustive_2_input.cpp
  • experiments/standard_cell_design/automatic_exhaustive_gate_design.cpp
  • test/algorithms/physical_design/design_sidb_gates.cpp
🚧 Files skipped from review as they are similar to previous changes (9)
  • test/algorithms/simulation/sidb/verify_logic_match.cpp
  • include/fiction/algorithms/simulation/sidb/critical_temperature.hpp
  • test/algorithms/simulation/sidb/operational_domain_ratio.cpp
  • include/fiction/algorithms/physical_design/exact.hpp
  • test/utils/math_utils.cpp
  • include/fiction/algorithms/physical_design/compare_designed_sidb_gates.hpp
  • include/fiction/algorithms/simulation/sidb/compare_by_ground_state_isolation.hpp
  • test/algorithms/simulation/sidb/is_operational.cpp
  • include/fiction/algorithms/simulation/sidb/is_operational.hpp

📝 Walkthrough

Walkthrough

This PR refactors SiDB operational assessments into structured results, separates kink and positive-charge conditions, generalizes gate-design parameters and execution modes, adds gate-ordering comparators, updates Python bindings and documentation, and migrates dependent C++, experiment, benchmark, and test code.

Changes

SiDB API and gate-design refactor

Layer / File(s) Summary
Operational assessment contract and execution
include/fiction/algorithms/simulation/sidb/*.hpp, bindings/mnt/pyfiction/src/...
Operational checks now use separate kink and positive-charge conditions and return structured assessment objects with optional per-input results, termination settings, and simulator counts.
Gate-design parameters and execution
include/fiction/algorithms/physical_design/design_sidb_gates.hpp, bindings/mnt/pyfiction/src/...
Gate-design parameters are lattice-typed, modes and termination conditions are updated, and exhaustive, QuickCell, pruning, and random execution paths support threading, solution limits, and post-processing.
Designed-gate comparison and ordering
include/fiction/algorithms/physical_design/compare_designed_sidb_gates.hpp, include/fiction/algorithms/simulation/sidb/compare_by_ground_state_isolation.hpp
Designed gates can be ordered through comparator chains using minimum or average ground-state isolation.
Bindings and public exports
bindings/mnt/pyfiction/__init__.py, bindings/mnt/pyfiction/src/...
Python exports now expose lattice-specific design parameters, split condition enums, simulation-result modes, and operational assessment classes.
Dependent migrations and validation
experiments/*, test/*, docs/*
Experiments, tests, benchmarks, and API documentation are updated for the new parameter and assessment contracts.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested labels: python, documentation, refactoring

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.47% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change: sorting designed SiDB gates.
Description check ✅ Passed The description covers the change, motivation, context, and checklist, but it omits a fixed issue and any dependencies.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (1)
include/fiction/algorithms/simulation/sidb/is_operational.hpp (1)

235-251: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

extract_simulation_results_per_input() copies rather than moves.

The method is const and the loop for (operational_assessment_for_input assessment : assessment_per_input.value()) iterates by value, so each sidb_simulation_result<Lyt> (a vector of charge-distribution surfaces) is deep-copied before the inner std::move. This contradicts the "through moves" docstring and can be costly for every operational gate during post-design sorting. Since callers bind the assessment as const operational_assessment<Lyt>&, a true move requires exposing a non-const overload (e.g. &&-qualified) and iterating by reference.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@include/fiction/algorithms/simulation/sidb/is_operational.hpp` around lines
235 - 251, Update extract_simulation_results_per_input so result extraction has
a non-const rvalue-qualified path that can move retained simulation results.
Iterate assessment_per_input by reference rather than value, move each
referenced assessment’s simulation_results into the returned vector, and update
callers to invoke this overload on a movable assessment instead of a const
reference while preserving the existing assertions and output behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bindings/mnt/pyfiction/__init__.py`:
- Around line 114-119: Re-export design_sidb_gates_stats from the package
initializer: add it to the relevant import list and __all__ alongside the other
design_sidb_gates symbols, preserving the public
mnt.pyfiction.design_sidb_gates_stats API.

In `@bindings/mnt/pyfiction/include/pyfiction/documentation.hpp`:
- Around line 98-99: Update the documentation string for
__doc_fiction_design_sidb_gates_stats_pruning_total_overridden to explicitly
describe the total runtime spent in the pruning phase, distinguishing it from
the overall time_total statistic.

In
`@bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp`:
- Around line 46-47: Update the EXHAUSTIVE enum binding in the
design_sidb_gates_mode definition to use the EXHAUSTIVE-specific documentation
symbol instead of the QUICKCELL documentation symbol; leave the QUICKCELL
binding unchanged.

In
`@bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/is_operational.cpp`:
- Line 91: Update the constructor binding’s py::arg name in
operational_assessment_for_input from " op_status" to "op_status", matching the
sibling binding so the normal op_status keyword is accepted.

In `@docs/algorithms/design_sidb_gates.rst`:
- Around line 26-29: Replace the four `.. doxygenenum::` directives in the
Python enum section of `design_sidb_gates.rst` with `.. autoclass::` directives
targeting the corresponding `mnt.pyfiction` enum bindings: both design mode
enums and both termination condition enums, matching the existing Python enum
documentation style.

In `@include/fiction/algorithms/physical_design/design_sidb_gates.hpp`:
- Around line 539-586: Synchronize the shared num_solutions_found counter in
both extract_gate_designs
(include/fiction/algorithms/physical_design/design_sidb_gates.hpp:539-586) and
run_random_design
(include/fiction/algorithms/physical_design/design_sidb_gates.hpp:310-382).
Prefer making the counter std::atomic<uint64_t> and use atomic operations for
increments and termination-guard reads, preserving the existing
maximum-number-of-solutions behavior without data races or overshooting.

In
`@include/fiction/algorithms/simulation/sidb/compare_by_ground_state_isolation.hpp`:
- Around line 177-197: Update average_ground_state_isolation_over_all_inputs to
handle count == 0 before dividing, returning
std::numeric_limits<double>::infinity() when every simulation result has a
single charge distribution; preserve the existing accumulated average for count
greater than zero.

In `@test/algorithms/physical_design/design_sidb_gates.cpp`:
- Around line 357-362: In the QuickCell validation block, update the
first_gate_quickcell binding to read from found_gate_layouts_quickcell rather
than found_gate_layouts_exhaustive. Keep the existing operational-status and
layout-count checks unchanged.

---

Nitpick comments:
In `@include/fiction/algorithms/simulation/sidb/is_operational.hpp`:
- Around line 235-251: Update extract_simulation_results_per_input so result
extraction has a non-const rvalue-qualified path that can move retained
simulation results. Iterate assessment_per_input by reference rather than value,
move each referenced assessment’s simulation_results into the returned vector,
and update callers to invoke this overload on a movable assessment instead of a
const reference while preserving the existing assertions and output behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4614d7ca-92c4-4966-b16c-2c8ced8627b3

📥 Commits

Reviewing files that changed from the base of the PR and between 304948a and 8b6c154.

📒 Files selected for processing (48)
  • .readthedocs.yml
  • bindings/mnt/pyfiction/__init__.py
  • bindings/mnt/pyfiction/include/pyfiction/documentation.hpp
  • bindings/mnt/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
  • bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp
  • bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/is_operational.cpp
  • bindings/mnt/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py
  • bindings/mnt/pyfiction/test/algorithms/simulation/sidb/test_is_operational.py
  • bindings/mnt/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py
  • docs/algorithms/design_sidb_gates.rst
  • docs/algorithms/sidb_simulation.rst
  • experiments/figure_of_merit_analysis/fom_analysis_2_input_1_output.cpp
  • experiments/operational_domain/critical_temperature_domain_bestagon.cpp
  • experiments/operational_domain/operational_domain_bestagon.cpp
  • experiments/operational_domain/operational_domain_bestagon_grid_vs_sketch.cpp
  • experiments/physical_design_with_on_the_fly_gate_design/on_the_fly_sidb_circuit_design_on_defective_surface.cpp
  • experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp
  • experiments/sidb_simulation/temperature/critical_temperature_simulation_bestagon.cpp
  • experiments/sidb_simulation/temperature/critical_temperature_simulation_siqad.cpp
  • experiments/standard_cell_design/automatic_exhaustive_gate_design.cpp
  • experiments/standard_cell_design/pruning_vs_simulation_scalability.cpp
  • experiments/standard_cell_design/quickcell_3_input.cpp
  • experiments/standard_cell_design/quickcell_rectangular_gate_library.cpp
  • experiments/standard_cell_design/quickcell_vs_automatic_exhaustive_2_input.cpp
  • include/fiction/algorithms/physical_design/apply_gate_library.hpp
  • include/fiction/algorithms/physical_design/compare_designed_sidb_gates.hpp
  • include/fiction/algorithms/physical_design/design_sidb_gates.hpp
  • include/fiction/algorithms/physical_design/exact.hpp
  • include/fiction/algorithms/physical_design/on_the_fly_sidb_circuit_design.hpp
  • include/fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp
  • include/fiction/algorithms/simulation/sidb/compare_by_ground_state_isolation.hpp
  • include/fiction/algorithms/simulation/sidb/critical_temperature.hpp
  • include/fiction/algorithms/simulation/sidb/defect_influence.hpp
  • include/fiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp
  • include/fiction/algorithms/simulation/sidb/is_operational.hpp
  • include/fiction/algorithms/simulation/sidb/operational_domain.hpp
  • include/fiction/technology/sidb_on_the_fly_gate_library.hpp
  • include/fiction/utils/layout_utils.hpp
  • include/fiction/utils/math_utils.hpp
  • test/algorithms/physical_design/apply_gate_library.cpp
  • test/algorithms/physical_design/design_sidb_gates.cpp
  • test/algorithms/simulation/sidb/critical_temperature.cpp
  • test/algorithms/simulation/sidb/is_operational.cpp
  • test/algorithms/simulation/sidb/operational_domain.cpp
  • test/algorithms/simulation/sidb/operational_domain_ratio.cpp
  • test/algorithms/simulation/sidb/verify_logic_match.cpp
  • test/benchmark/sidb_logic.cpp
  • test/utils/math_utils.cpp
💤 Files with no reviewable changes (1)
  • .readthedocs.yml

Comment on lines +114 to +119
design_sidb_gates_params_100,
design_sidb_gates_params_111,
design_sidb_gates_params_design_sidb_gates_mode_100,
design_sidb_gates_params_design_sidb_gates_mode_111,
design_sidb_gates_params_termination_condition_100,
design_sidb_gates_params_termination_condition_111,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether design_sidb_gates_stats is still bound in the pybind11 module and whether it's re-exported.
rg -n 'design_sidb_gates_stats' bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp
rg -n 'design_sidb_gates_stats' bindings/mnt/pyfiction/__init__.py

Repository: cda-tum/fiction

Length of output: 1649


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the export list around the reported lines and search for any re-export of the stats class.
python3 - <<'PY'
from pathlib import Path

path = Path("bindings/mnt/pyfiction/__init__.py")
lines = path.read_text().splitlines()
for start in (1, 90, 110, 420, 520):
    end = min(len(lines), start + 30)
    print(f"\n--- {path}:{start}-{end} ---")
    for i in range(start, end + 1):
        print(f"{i:4}: {lines[i-1]}")
PY

printf '\n--- grep ---\n'
rg -n 'design_sidb_gates_stats|__all__|design_sidb_gates_params_' bindings/mnt/pyfiction/__init__.py

Repository: cda-tum/fiction

Length of output: 7170


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Confirm the binding exists in the C++ module and whether the Python package references it anywhere else.
rg -n 'py::class_<fiction::design_sidb_gates_stats>|design_sidb_gates_stats' bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp bindings/mnt/pyfiction

Repository: cda-tum/fiction

Length of output: 7597


Re-export design_sidb_gates_stats
bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp still binds design_sidb_gates_stats, but bindings/mnt/pyfiction/__init__.py no longer exposes it. Add it back to the import list and __all__ so mnt.pyfiction.design_sidb_gates_stats remains available.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bindings/mnt/pyfiction/__init__.py` around lines 114 - 119, Re-export
design_sidb_gates_stats from the package initializer: add it to the relevant
import list and __all__ alongside the other design_sidb_gates symbols,
preserving the public mnt.pyfiction.design_sidb_gates_stats API.

Comment on lines +98 to +99
inline constexpr auto __doc_fiction_design_sidb_gates_stats_pruning_total_overridden =
R"doc(The total runtime of the process.)doc";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Clarify pruning_total docstring to distinguish it from time_total.

Both pruning_total (line 98-99) and time_total (line 101-102) are documented with nearly identical wording ("The total runtime of the process." vs "The total runtime of the SiDB gate design process."). Since pruning_total presumably measures time spent specifically in the pruning phase, the docstring should say so explicitly to avoid confusing the two stats.

📝 Proposed fix
 inline constexpr auto __doc_fiction_design_sidb_gates_stats_pruning_total_overridden =
-    R"doc(The total runtime of the process.)doc";
+    R"doc(The total runtime spent on pruning non-operational layouts.)doc";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
inline constexpr auto __doc_fiction_design_sidb_gates_stats_pruning_total_overridden =
R"doc(The total runtime of the process.)doc";
inline constexpr auto __doc_fiction_design_sidb_gates_stats_pruning_total_overridden =
R"doc(The total runtime spent on pruning non-operational layouts.)doc";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bindings/mnt/pyfiction/include/pyfiction/documentation.hpp` around lines 98 -
99, Update the documentation string for
__doc_fiction_design_sidb_gates_stats_pruning_total_overridden to explicitly
describe the total runtime spent in the pruning phase, distinguishing it from
the overall time_total statistic.

Comment on lines +46 to +47
.value("EXHAUSTIVE", fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode::EXHAUSTIVE,
DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_QUICKCELL))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Wrong docstring reference for EXHAUSTIVE.

The EXHAUSTIVE enum value is bound with DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_QUICKCELL), a copy-paste of the QUICKCELL docstring. It should reference the EXHAUSTIVE doc.

Proposed fix
         .value("EXHAUSTIVE", fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode::EXHAUSTIVE,
-               DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_QUICKCELL))
+               DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.value("EXHAUSTIVE", fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode::EXHAUSTIVE,
DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_QUICKCELL))
.value("EXHAUSTIVE", fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode::EXHAUSTIVE,
DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp`
around lines 46 - 47, Update the EXHAUSTIVE enum binding in the
design_sidb_gates_mode definition to use the EXHAUSTIVE-specific documentation
symbol instead of the QUICKCELL documentation symbol; leave the QUICKCELL
binding unchanged.

py::class_<typename fiction::operational_assessment<Lyt>::operational_assessment_for_input>(
m, fmt::format("operational_assessment_for_input{}", lattice).c_str(),
DOC(fiction_operational_assessment_operational_assessment_for_input))
.def(py::init<fiction::operational_status>(), py::arg(" op_status"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant binding file around the reported lines.
FILE="bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/is_operational.cpp"
wc -l "$FILE"
sed -n '70,120p' "$FILE"

echo
echo "---- registration references ----"
rg -n "operational_assessment|is_operational_impl|simulation_result|sidb_simulation_result|register_.*sidb" bindings/mnt/pyfiction/src -S

Repository: cda-tum/fiction

Length of output: 15781


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,80p' bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/register_sidb_support.cpp
echo
sed -n '1,80p' bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/register_sidb_simulation.cpp
echo
sed -n '1,80p' bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/register_simulation.cpp

Repository: cda-tum/fiction

Length of output: 2883


Fix the constructor keyword typo

py::arg(" op_status") registers the parameter with a leading space, so operational_assessment_for_input(..., op_status=...) can’t be called with the normal keyword name. Rename it to py::arg("op_status") to match the sibling binding.

Proposed fix
-        .def(py::init<fiction::operational_status>(), py::arg(" op_status"),
+        .def(py::init<fiction::operational_status>(), py::arg("op_status"),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.def(py::init<fiction::operational_status>(), py::arg(" op_status"),
.def(py::init<fiction::operational_status>(), py::arg("op_status"),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bindings/mnt/pyfiction/src/pyfiction/algorithms/simulation/sidb/is_operational.cpp`
at line 91, Update the constructor binding’s py::arg name in
operational_assessment_for_input from " op_status" to "op_status", matching the
sibling binding so the normal op_status keyword is accepted.

Comment on lines +26 to +29
.. doxygenenum:: mnt.pyfiction.design_sidb_gates_params_design_sidb_gates_mode_100
.. doxygenenum:: mnt.pyfiction.design_sidb_gates_params_design_sidb_gates_mode_111
.. doxygenenum:: mnt.pyfiction.design_sidb_gates_params_termination_condition_100
.. doxygenenum:: mnt.pyfiction.design_sidb_gates_params_termination_condition_111

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== File outline ==\n'
ast-grep outline docs/algorithms/design_sidb_gates.rst --view expanded || true

printf '\n== Relevant lines ==\n'
sed -n '1,120p' docs/algorithms/design_sidb_gates.rst | cat -n

printf '\n== Search for autoclass/doxygenenum in docs ==\n'
rg -n --glob '*.rst' 'autoclass::|doxygenenum::' docs | sed -n '1,200p'

printf '\n== Search for these exact enum symbols ==\n'
rg -n 'design_sidb_gates_params_(design_sidb_gates_mode_100|design_sidb_gates_mode_111|termination_condition_100|termination_condition_111)' -S . | sed -n '1,200p'

Repository: cda-tum/fiction

Length of output: 21283


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== Nearby Python enum docs examples ==\n'
rg -n --glob '*.rst' 'Python tab|autoclass:: .*enum|autoclass:: mnt\.pyfiction' docs | sed -n '1,220p'

printf '\n== Files referencing design_sidb_gates ==\n'
rg -n 'design_sidb_gates' docs include src python -S | sed -n '1,220p'

Repository: cda-tum/fiction

Length of output: 19102


Use autodoc for the Python enum bindings. The Python tab in docs/algorithms/design_sidb_gates.rst should use .. autoclass:: for these four mnt.pyfiction enums, matching the rest of the Python enum docs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/algorithms/design_sidb_gates.rst` around lines 26 - 29, Replace the four
`.. doxygenenum::` directives in the Python enum section of
`design_sidb_gates.rst` with `.. autoclass::` directives targeting the
corresponding `mnt.pyfiction` enum bindings: both design mode enums and both
termination condition enums, matching the existing Python enum documentation
style.

Comment on lines +539 to +586
++num_solutions_found;
}
else
{
return;
}

// pruning was already conducted above. Hence, SIMULATION_ONLY is chosen.
params.operational_params.strategy_to_analyze_operational_status =
is_operational_params::operational_analysis_strategy::SIMULATION_ONLY;
const std::scoped_lock lock_vector{mutex_to_protect_designed_gate_layouts};

designed_gate_layouts.gate_layouts.emplace_back(std::move(layout_with_added_cells));

if (const auto [status, sim_calls] = is_operational(candidate, truth_table, params.operational_params,
input_bdl_wires, output_bdl_wires);
status == operational_status::OPERATIONAL)
#if (PROGRESS_BARS)
if (params.termination_cond == design_sidb_gates_params<Lyt>::termination_condition::OBTAINED_N_SOLUTIONS &&
num_solutions_found < params.maximum_number_of_solutions)
{
// Lock and update shared resources
{
const std::scoped_lock lock{mutex_to_protect_gate_designs};
gate_layouts.push_back(candidate);
}
gate_design_found = true; // Notify all threads that a solution has been found
// update the progress bar
bar(num_solutions_found);
}
#endif
};

std::vector<std::thread> threads{};
threads.reserve(num_threads);

for (std::size_t i = 0; i < num_threads; ++i)
{
threads.emplace_back(
[this, i, chunk_size, &gate_candidates, &check_operational_status, &gate_design_found]()
[this, i, chunk_size, &candidate_combinations, &add_combination_to_layout_and_check_operation,
&num_solutions_found, &max_number_of_solutions
#if (PROGRESS_BARS)
,
&bar
#endif
]
{
const std::size_t start_index = i * chunk_size;
const std::size_t end_index = std::min(start_index + chunk_size, gate_candidates.size());
const std::size_t end_index = std::min(start_index + chunk_size, candidate_combinations.size());

for (std::size_t j = start_index; j < end_index; ++j)
{
if (gate_design_found &&
(params.termination_cond ==
design_sidb_gates_params<cell<Lyt>>::termination_condition::AFTER_FIRST_SOLUTION))
if (params.termination_cond ==
design_sidb_gates_params<Lyt>::termination_condition::OBTAINED_N_SOLUTIONS &&
num_solutions_found >= max_number_of_solutions)
{
return;
}

check_operational_status(gate_candidates[j]);
add_combination_to_layout_and_check_operation(candidate_combinations[j]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Non-atomic num_solutions_found counter is raced by worker threads in two design paths. Both multithreaded designers share a plain uint64_t num_solutions_found that one thread mutates while others read the loop/stop guard outside the mutex, which is a data race (UB) and permits overshooting maximum_number_of_solutions. Make the counter std::atomic<uint64_t> (or perform the increment and the guard check under the same lock).

  • include/fiction/algorithms/physical_design/design_sidb_gates.hpp#L539-L586: extract_gate_designs increments num_solutions_found (Line 539) before acquiring the lock at Line 546 and reads it in the thread loop at Line 581 without a lock — synchronize both.
  • include/fiction/algorithms/physical_design/design_sidb_gates.hpp#L310-L382: run_random_design reads the loop guard at Line 334 without the mutex while incrementing under lock at Line 382 — synchronize the guard read.
📍 Affects 1 file
  • include/fiction/algorithms/physical_design/design_sidb_gates.hpp#L539-L586 (this comment)
  • include/fiction/algorithms/physical_design/design_sidb_gates.hpp#L310-L382
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@include/fiction/algorithms/physical_design/design_sidb_gates.hpp` around
lines 539 - 586, Synchronize the shared num_solutions_found counter in both
extract_gate_designs
(include/fiction/algorithms/physical_design/design_sidb_gates.hpp:539-586) and
run_random_design
(include/fiction/algorithms/physical_design/design_sidb_gates.hpp:310-382).
Prefer making the counter std::atomic<uint64_t> and use atomic operations for
increments and termination-guard reads, preserving the existing
maximum-number-of-solutions behavior without data races or overshooting.

Comment on lines +177 to +197
[[nodiscard]] double
average_ground_state_isolation_over_all_inputs(const sidb_gate_design& gate_design) const noexcept
{
uint64_t count = 0;

double accumulated_ground_state_isolation = 0.0;

for (const auto& sim_res : gate_design.simulation_results_per_input)
{
if (sim_res.charge_distributions.size() == 1)
{
continue;
}

accumulated_ground_state_isolation += detail::get_ground_state_isolation(sim_res);

++count;
}

return accumulated_ground_state_isolation / static_cast<double>(count);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Guard against division by zero in average isolation.

If every input's simulation_results_per_input has a single charge distribution, the continue at Line 188 skips all iterations, leaving count == 0, and the return computes 0.0 / 0.0 = NaN. Because this value is used as a sort key inside std::sort, a NaN comparator result violates strict-weak-ordering and is undefined behavior. Return std::numeric_limits<double>::infinity() (consistent with the single-distribution case in get_ground_state_isolation) when count == 0.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@include/fiction/algorithms/simulation/sidb/compare_by_ground_state_isolation.hpp`
around lines 177 - 197, Update average_ground_state_isolation_over_all_inputs to
handle count == 0 before dividing, returning
std::numeric_limits<double>::infinity() when every simulation result has a
single charge distribution; preserve the existing accumulated average for count
greater than zero.

Comment on lines +357 to +362
REQUIRE(found_gate_layouts_quickcell.size() == 1);
const auto& first_gate_quickcell = found_gate_layouts_exhaustive.front();
CHECK(
is_operational(first_gate_quickcell, std::vector<tt>{create_and_tt()}, params.operational_params).status ==
operational_status::OPERATIONAL);
CHECK(design_gates_stats_quickcell.number_of_layouts == 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Wrong container: first_gate_quickcell reads from the exhaustive result.

first_gate_quickcell is bound to found_gate_layouts_exhaustive.front(), so the QuickCell branch validates the exhaustive layout instead of the QuickCell one. This defeats the purpose of the section.

🐛 Proposed fix
-        const auto& first_gate_quickcell = found_gate_layouts_exhaustive.front();
+        const auto& first_gate_quickcell = found_gate_layouts_quickcell.front();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
REQUIRE(found_gate_layouts_quickcell.size() == 1);
const auto& first_gate_quickcell = found_gate_layouts_exhaustive.front();
CHECK(
is_operational(first_gate_quickcell, std::vector<tt>{create_and_tt()}, params.operational_params).status ==
operational_status::OPERATIONAL);
CHECK(design_gates_stats_quickcell.number_of_layouts == 1);
REQUIRE(found_gate_layouts_quickcell.size() == 1);
const auto& first_gate_quickcell = found_gate_layouts_quickcell.front();
CHECK(
is_operational(first_gate_quickcell, std::vector<tt>{create_and_tt()}, params.operational_params).status ==
operational_status::OPERATIONAL);
CHECK(design_gates_stats_quickcell.number_of_layouts == 1);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/algorithms/physical_design/design_sidb_gates.cpp` around lines 357 -
362, In the QuickCell validation block, update the first_gate_quickcell binding
to read from found_gate_layouts_quickcell rather than
found_gate_layouts_exhaustive. Keep the existing operational-status and
layout-count checks unchanged.

- Remove unused fiction/traits.hpp and fiction/layouts/coordinates.hpp
  includes from the pyfiction design_sidb_gates binding.
- Remove unused fiction/traits.hpp and lorina/lorina.hpp includes from
  the on-the-fly SiDB circuit design experiment; include lorina/verilog.hpp
  directly since that is what provides lorina::read_verilog.
- Annotate unchecked std::optional accesses with NOLINT, matching the
  existing convention used elsewhere in the codebase.
- Remove unused <filesystem> and <iostream> includes from the
  operational_domain_bestagon experiment.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@experiments/physical_design_with_on_the_fly_gate_design/on_the_fly_sidb_circuit_design_on_defective_surface.cpp`:
- Around line 163-170: Update the result-handling block around st.gate_layout,
mockturtle::miter, and mockturtle::equivalence_checking to validate each
optional before dereferencing it. Replace the assert-only protection for eq with
runtime guards that safely handle missing miter or equivalence results, and
invoke sidb_circuits_with_defects only when both values are available.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8443a6c9-f244-4ee8-a9b5-e22086643321

📥 Commits

Reviewing files that changed from the base of the PR and between 8b6c154 and b49de62.

📒 Files selected for processing (3)
  • bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp
  • experiments/operational_domain/operational_domain_bestagon.cpp
  • experiments/physical_design_with_on_the_fly_gate_design/on_the_fly_sidb_circuit_design_on_defective_surface.cpp
💤 Files with no reviewable changes (2)
  • experiments/operational_domain/operational_domain_bestagon.cpp
  • bindings/mnt/pyfiction/src/pyfiction/algorithms/physical_design/design_sidb_gates.cpp

Comment on lines +163 to +170
const auto& gate_layout = st.gate_layout.value(); // NOLINT(bugprone-unchecked-optional-access)
const auto miter = mockturtle::miter<mockturtle::klut_network>(mapped_network, gate_layout);
const auto eq = mockturtle::equivalence_checking(*miter); // NOLINT(bugprone-unchecked-optional-access)
assert(eq.has_value());
const auto eq_result = *eq; // NOLINT(bugprone-unchecked-optional-access)

sidb_circuits_with_defects(benchmark, mockturtle::to_seconds(st.time_total),
st.exact_stats.num_aspect_ratios, *eq, result.num_cells());
st.exact_stats.num_aspect_ratios, eq_result, result.num_cells());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target snippet =="
sed -n '130,190p' experiments/physical_design_with_on_the_fly_gate_design/on_the_fly_sidb_circuit_design_on_defective_surface.cpp

echo
echo "== search for miter/equivalence_checking usages =="
rg -n "equivalence_checking|miter<mockturtle::klut_network>|gate_layout\.value\(|gate_layout" experiments -S

echo
echo "== locate mockturtle references in repo =="
rg -n "namespace mockturtle|equivalence_checking\(" -S .

Repository: cda-tum/fiction

Length of output: 25651


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for the exact symbols and relevant type hints in the repository
rg -n "equivalence_checking\(|miter<|struct .*gate_layout|gate_layout\.value\(" -S .

# If a local copy of mockturtle headers exists in the repo, inspect the symbol definitions
fd -a "mockturtle" .

Repository: cda-tum/fiction

Length of output: 18915


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,240p' experiments/physical_design_with_on_the_fly_gate_design/on_the_fly_sidb_circuit_design_on_defective_surface.cpp

Repository: cda-tum/fiction

Length of output: 9257


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '80,150p' include/fiction/algorithms/verification/equivalence_checking.hpp

echo
echo "== miter wrapper definition =="
sed -n '1,220p' include/fiction/utils/mockturtle_utils.hpp

echo
echo "== exact target context in a similar experiment =="
sed -n '160,190p' experiments/defect_aware_physical_design/defect_aware_physical_design.cpp

Repository: cda-tum/fiction

Length of output: 6464


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the repository's wrappers and the concrete miter/equivalence pattern used elsewhere.
sed -n '1,180p' include/fiction/algorithms/verification/equivalence_checking.hpp
echo
sed -n '1,140p' include/fiction/utils/mockturtle_utils.hpp
echo
sed -n '170,190p' experiments/defect_aware_physical_design/defect_aware_physical_design.cpp

Repository: cda-tum/fiction

Length of output: 8409


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '90,140p' include/fiction/algorithms/verification/equivalence_checking.hpp
echo
sed -n '1,120p' include/fiction/utils/mockturtle_utils.hpp
echo
sed -n '170,190p' experiments/defect_aware_physical_design/defect_aware_physical_design.cpp

Repository: cda-tum/fiction

Length of output: 5252


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "gate_layout|on_the_fly_sidb_circuit_design_on_defective_surface_stats|on_the_fly_circuit_design_on_defective_surface_stats" include experiments -S

echo
sed -n '1,260p' include/fiction/algorithms/physical_design/on_the_fly_sidb_circuit_design.hpp

Repository: cda-tum/fiction

Length of output: 19054


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the implementation file and inspect the public contract around stats and return values.
fd -a "on_the_fly_sidb_circuit_design.hpp" include
fd -a "on_the_fly_sidb_circuit_design*.hpp" include

echo
sed -n '1,260p' include/fiction/algorithms/physical_design/on_the_fly_sidb_circuit_design.hpp

Repository: cda-tum/fiction

Length of output: 11114


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "gate_layout" include/fiction -S

Repository: cda-tum/fiction

Length of output: 6612


Guard the optional miter/equivalence results before dereferencing. st.gate_layout is populated by the design routine, but *miter and *eq still rely on optional values; assert(eq.has_value()) won’t protect release builds.

🧰 Tools
🪛 Cppcheck (2.21.0)

[error] 168-168: Found an exit path from function with non-void return type that has missing return statement

(missingReturn)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@experiments/physical_design_with_on_the_fly_gate_design/on_the_fly_sidb_circuit_design_on_defective_surface.cpp`
around lines 163 - 170, Update the result-handling block around st.gate_layout,
mockturtle::miter, and mockturtle::equivalence_checking to validate each
optional before dereferencing it. Replace the assert-only protection for eq with
runtime guards that safely handle missing miter or equivalence results, and
invoke sidb_circuits_with_defects only when both values are available.

Source: Linters/SAST tools

Proactively scanned every file touched by this PR's true diff against
main with clang-tidy's misc-include-cleaner and
bugprone-unchecked-optional-access checks, since CI only surfaces a
partial batch of findings per run.

- Remove unused includes: <thread>, <atomic>, <mockturtle/views/color_view.hpp>,
  and <kitty/dynamic_truth_table.hpp> from exact.hpp; unused fiction/traits.hpp
  from several standard_cell_design experiments and two test files.
- Annotate unchecked std::optional accesses with NOLINT, matching the
  existing convention, in exact.hpp, compare_designed_sidb_gates.hpp,
  is_operational.hpp, compare_by_ground_state_isolation.hpp, and
  critical_temperature.hpp.
- Add missing direct includes for Catch2 macros used in several test
  files that previously relied on transitive includes, and add
  <cstddef> for std::size_t in math_utils.cpp.
- Refactor a chain of repeated `.value()` accesses in the is_operational
  test into named references to keep the NOLINT annotations stable
  across clang-format reflows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants