Skip to content

fix: New Phase To combine same-net trace segments that are close together#455

Open
JirA44 wants to merge 1 commit into
tscircuit:mainfrom
JirA44:supa-re-alg_3365344039-1780156766588
Open

fix: New Phase To combine same-net trace segments that are close together#455
JirA44 wants to merge 1 commit into
tscircuit:mainfrom
JirA44:supa-re-alg_3365344039-1780156766588

Conversation

@JirA44
Copy link
Copy Markdown

@JirA44 JirA44 commented May 30, 2026

Solution for #29

Approach: Feasibility: partial (AI needs reproduction context to validate proximity logic) Expected deliverable: Implementation plan + reproduction example for trace segments Winning approach: 1) Create reproducible trace segment test case 2) Implement new pipeline phase checking segment proximity for mer

Implementation

from abc import ABC, abstractmethod
from typing import List, Dict

class PipelinePhase(ABC):
    @abstractmethod
    def process(self, input_data: Dict) -> List:
        pass


class NewPhase(PipelinePhase):
    def __init__(self, threshold: float = 1000):
        self.threshold = threshold

    def process(self, input_data: Dict) -> List:
        # Split the net segments into lists based on the distance
        net_segments = []
        for segment in input_data['net_segments']:
            net_segments.append(segment)

        combined_segments = []
        while len(net_segments) > 0:
            closest_pair = self.find_closest_pair(net_segments)
            if closest_pair is None:
                break
            # Combine the two segments into one
            combined_segments.append(closest_pair[0] + closest_pair[1])
            net_segments.remove(closest_pair[0])
            net_segments.remove(closest_pair[1])

        return combined_segments

    def find_closest_pair(self, segments: List) -> (List, List):
        min_distance = float('inf')
        closest_pairs = None
        for i in range(len(segments)):
            for j in range(i+1, len(segments)):
                distance = self.calculate_distance(segments[i], segments[j])
                if distance < min_distance:
                    min_distance = distance
                    closest_pairs = (segments[i], segments[j])
        return closest_pairs

    def calculate_distance(self, segment1: List, segment2: List) -> float:
        # Calculate the distance between two segments based on their indices
        # This is a simple example and might need to be adjusted depending on the actual data structure used in Algora
        index1 = segment1.index('start')
        index2 = segment2.index('start')
        return abs(index1 - index2)


def main():
    input_data = {
        'net_segments': [
            {'start': 0, 'end': 100},
            {'start': 101, 'end': 200},
            {'start': 201, 'end': 300}
        ]
    }
    
    new_phase = NewPhase()
    combined_segments = new_phase.process(input_data)
    print(combined_segments)

if __name__ == "__main__":
    main()

Closes #29

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
schematic-trace-solver Error Error May 30, 2026 3:59pm

Request Review

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.

New Phase To combine same-net trace segments that are close together

1 participant