


from manim import *



class        a					(			_UpperCAmelCase   ):





     def  SCREAMING_SNAKE_CASE__       (    self					:				int							):
        __lowerCamelCase:				int     =	Rectangle(height=0.5    ,	width=0.5							)
        __lowerCamelCase:				List[str]     =	Rectangle(height=0.25    ,	width=0.25							)
        __lowerCamelCase:				Optional[int]     =	Rectangle(height=0.46    ,	width=0.46							).set_stroke(width=0							)

        __lowerCamelCase:				str     =	[mem.copy() for i in range(6							)]
        __lowerCamelCase:				Dict     =	[mem.copy() for i in range(6							)]
        __lowerCamelCase:				Union[str, Any]     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Tuple     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Optional[int]     =	VGroup(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Dict     =	Text("""CPU"""    ,	font_size=24							)
        __lowerCamelCase:				Any     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        cpu.move_to([-2.5, -0.5, 0]							)
        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Optional[int]     =	[mem.copy() for i in range(4							)]
        __lowerCamelCase:				Optional[int]     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Dict     =	Text("""GPU"""    ,	font_size=24							)
        __lowerCamelCase:				Dict     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        gpu.move_to([-1, -1, 0]							)
        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Any     =	[mem.copy() for i in range(6							)]
        __lowerCamelCase:				Dict     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)

        __lowerCamelCase:				List[Any]     =	Text("""Model"""    ,	font_size=24							)
        __lowerCamelCase:				Any     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        model.move_to([3, -1.0, 0]							)
        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Tuple     =	[]
        __lowerCamelCase:				Any     =	[]
        __lowerCamelCase:				int     =	[]

        for i, rect in enumerate(SCREAMING_SNAKE_CASE_							):
           rect.set_stroke(SCREAMING_SNAKE_CASE_							)

           __lowerCamelCase:				int     =	Rectangle(height=0.46 / 4    ,	width=0.46 / 3							).set_stroke(width=0.0							).set_fill(SCREAMING_SNAKE_CASE_    ,	opacity=0.7							)

           if i == 0:
              cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT							)    ,	buff=0.02    ,	direction=SCREAMING_SNAKE_CASE_							)
              cpu_target.set_x(cpu_target.get_x() + 0.1							)
           elif i == 3:
              cpu_target.next_to(model_cpu_arr[0]    ,	direction=SCREAMING_SNAKE_CASE_    ,	buff=0.0							)
           else:
              cpu_target.next_to(model_cpu_arr[i - 1]    ,	direction=SCREAMING_SNAKE_CASE_    ,	buff=0.0							)
           self.add(SCREAMING_SNAKE_CASE_							)
           model_cpu_arr.append(SCREAMING_SNAKE_CASE_							)

        self.add(*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				List[Any]     =	[mem.copy() for i in range(6							)]
        __lowerCamelCase:				Any     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)

        __lowerCamelCase:				Tuple     =	Text("""Loaded Checkpoint"""    ,	font_size=24							)
        __lowerCamelCase:				Tuple     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        checkpoint.move_to([3, 0.5, 0]							)

        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				List[Any]     =	[]
        __lowerCamelCase:				Optional[int]     =	[]

        for i, rect in enumerate(SCREAMING_SNAKE_CASE_							):
           __lowerCamelCase:				Optional[int]     =	fill.copy().set_fill(SCREAMING_SNAKE_CASE_    ,	opacity=0.7							)
           target.move_to(SCREAMING_SNAKE_CASE_							)
           ckpt_arr.append(SCREAMING_SNAKE_CASE_							)

           __lowerCamelCase:				List[Any]     =	target.copy()
           if i < 5:
              cpu_target.move_to(cpu_left_col_base[i + 1]							)
           else:
              cpu_target.move_to(cpu_right_col_base[i - 5]							)
           ckpt_cpu_arr.append(SCREAMING_SNAKE_CASE_							)
        self.add(*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Optional[Any]     =	Square(side_length=2.2							)
        key.move_to([-5, 2, 0]							)

        __lowerCamelCase:				Dict     =	MarkupText(
            F'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'    ,	font_size=18    ,	)

        key_text.move_to([-5, 2.4, 0]							)

        self.add(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Optional[int]     =	MarkupText(
            F'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'    ,	font_size=18    ,	)

        blue_text.next_to(SCREAMING_SNAKE_CASE_    ,	DOWN * 2.4    ,	aligned_edge=key_text.get_left()							)
        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Tuple     =	MarkupText(
            F'Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device.'    ,	font_size=24    ,	)
        step_a.move_to([2, 2, 0]							)

        __lowerCamelCase:				List[Any]     =	[meta_mem.copy() for i in range(6							)]
        __lowerCamelCase:				Optional[int]     =	[meta_mem.copy() for i in range(6							)]
        __lowerCamelCase:				str     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Optional[int]     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				List[str]     =	VGroup(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Dict     =	Text("""Disk"""    ,	font_size=24							)
        __lowerCamelCase:				Any     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        disk.move_to([-4.0, -1.25, 0]							)
        self.play(Write(SCREAMING_SNAKE_CASE_    ,	run_time=3							)    ,	Write(SCREAMING_SNAKE_CASE_    ,	run_time=1							)    ,	Create(SCREAMING_SNAKE_CASE_    ,	run_time=1							)							)

        __lowerCamelCase:				int     =	[]
        for i, rect in enumerate(SCREAMING_SNAKE_CASE_							):
           __lowerCamelCase:				Optional[int]     =	rect.copy()
           target.generate_target()
           target.target.move_to(disk_left_col_base[i]							).scale(0.5							)
           animations.append(MoveToTarget(SCREAMING_SNAKE_CASE_    ,	run_time=1.5							)							)
        self.play(*SCREAMING_SNAKE_CASE_							)

        self.play(FadeOut(SCREAMING_SNAKE_CASE_							)							)

        __lowerCamelCase:				List[Any]     =	MarkupText(F'Then, the checkpoint is removed from memory\nthrough garbage collection.'    ,	font_size=24							)
        step_a.move_to([2, 2, 0]							)

        self.play(Write(SCREAMING_SNAKE_CASE_    ,	run_time=3							)							)

        self.play(
            FadeOut(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_							)    ,	)

        self.wait()







from __future__ import annotations

_A		:				List[str]									=       {
    '''A''': ['''B''', '''C''', '''E'''],
    '''B''': ['''A''', '''D''', '''E'''],
    '''C''': ['''A''', '''F''', '''G'''],
    '''D''': ['''B'''],
    '''E''': ['''A''', '''B''', '''D'''],
    '''F''': ['''C'''],
    '''G''': ['''C'''],
}



class        a					:





     def __init__(    self					:				Any    ,	SCREAMING_SNAKE_CASE_					:				dict[str, list[str]]    ,	SCREAMING_SNAKE_CASE_					:				str							):
        __lowerCamelCase:				Dict     =	graph
        # mapping node to its parent in resulting breadth first tree
        __lowerCamelCase:				dict[str, str | None]     =	{}
        __lowerCamelCase:				str     =	source_vertex





     def  SCREAMING_SNAKE_CASE__       (    self					:				int							):
        __lowerCamelCase:				Optional[int]     =	{self.source_vertex}
        __lowerCamelCase:				Optional[int]     =	None
        __lowerCamelCase:				Optional[int]     =	[self.source_vertex]  # first in first out queue

        while queue:
           __lowerCamelCase:				int     =	queue.pop(0							)
           for adjacent_vertex in self.graph[vertex]:
              if adjacent_vertex not in visited:
                 visited.add(SCREAMING_SNAKE_CASE_							)
                 __lowerCamelCase:				Dict     =	vertex
                 queue.append(SCREAMING_SNAKE_CASE_							)







     def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				str							):
        if target_vertex == self.source_vertex:
           return self.source_vertex

        __lowerCamelCase:				List[str]     =	self.parent.get(SCREAMING_SNAKE_CASE_							)
        if target_vertex_parent is None:
           __lowerCamelCase:				Optional[int]     =	(
               F'No path from vertex: {self.source_vertex} to vertex: {target_vertex}'
           )
           raise ValueError(SCREAMING_SNAKE_CASE_							)

        return self.shortest_path(SCREAMING_SNAKE_CASE_							) + F'->{target_vertex}'


if __name__ == "__main__":
   _A		:				int									=       Graph(graph, '''G''')
   g.breath_first_search()
   print(g.shortest_path('''D'''))
   print(g.shortest_path('''G'''))
   print(g.shortest_path('''Foo'''))


