dechantoine commited on
Commit
0254047
·
verified ·
1 Parent(s): 7b279ca

Upload folder using huggingface_hub

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
app.py CHANGED
@@ -28,7 +28,7 @@ model.eval()
28
  os.makedirs(name=TEMP_DIR, exist_ok=True)
29
 
30
 
31
- @logger.catch(level="DEBUG")
32
  def evaluate_board(board: chess.Board):
33
  """Evaluate the board.
34
 
@@ -53,7 +53,7 @@ def evaluate_board(board: chess.Board):
53
  return os.path.join(TEMP_DIR, "board.svg"), eval_board(model=model, board=board)
54
 
55
 
56
- @logger.catch(level="DEBUG")
57
  def plot_beam_search(board: chess.Board, depth: int, beam_width: int):
58
  """Plot the beam search tree.
59
 
@@ -75,10 +75,10 @@ def plot_beam_search(board: chess.Board, depth: int, beam_width: int):
75
  temp_dir=TEMP_DIR,
76
  )
77
 
78
- return os.path.join(TEMP_DIR, "beam_search.png")
79
 
80
 
81
- @logger.catch(level="DEBUG")
82
  def test_graphviz(board: chess.Board, depth: int, beam_width: int):
83
  """Plot the beam search tree.
84
 
 
28
  os.makedirs(name=TEMP_DIR, exist_ok=True)
29
 
30
 
31
+ @logger.catch(level="DEBUG", reraise=True)
32
  def evaluate_board(board: chess.Board):
33
  """Evaluate the board.
34
 
 
53
  return os.path.join(TEMP_DIR, "board.svg"), eval_board(model=model, board=board)
54
 
55
 
56
+ @logger.catch(level="DEBUG", reraise=True)
57
  def plot_beam_search(board: chess.Board, depth: int, beam_width: int):
58
  """Plot the beam search tree.
59
 
 
75
  temp_dir=TEMP_DIR,
76
  )
77
 
78
+ return os.path.join(TEMP_DIR, "beam_search.svg")
79
 
80
 
81
+ @logger.catch(level="DEBUG", reraise=True)
82
  def test_graphviz(board: chess.Board, depth: int, beam_width: int):
83
  """Plot the beam search tree.
84
 
src/agents/__pycache__/viz_utils.cpython-311.pyc CHANGED
Binary files a/src/agents/__pycache__/viz_utils.cpython-311.pyc and b/src/agents/__pycache__/viz_utils.cpython-311.pyc differ
 
src/agents/viz_utils.py CHANGED
@@ -19,6 +19,7 @@ graph_params = {
19
  }
20
 
21
 
 
22
  def board_to_svg(board: chess.Board, is_pruned: bool = False, size: int = 360) -> str:
23
  """Convert a chess.Board object to an SVG string.
24
 
@@ -47,8 +48,9 @@ def board_to_svg(board: chess.Board, is_pruned: bool = False, size: int = 360) -
47
  return svg
48
 
49
 
50
- def save_svg(board: chess.Board, filename: str, is_pruned: bool = False):
51
- """Save a chess.Board object to an SVG file.
 
52
 
53
  Args:
54
  board (chess.Board): chess.Board object
@@ -61,9 +63,9 @@ def save_svg(board: chess.Board, filename: str, is_pruned: bool = False):
61
  f.write(xml_declaration + board_to_svg(board, is_pruned=is_pruned))
62
 
63
 
64
- @logger.catch(level="DEBUG")
65
  def plot_save_beam_search(
66
- beam: AnyNode, filename: str, temp_dir: str = "../reports/figures"
67
  ) -> None:
68
  """Plot and save the beam search tree.
69
 
@@ -119,11 +121,11 @@ def plot_save_beam_search(
119
  tailport=graph_params["tailport"],
120
  )
121
 
122
- dot.render(filename=filename, format="png")
123
 
124
  logger.info(os.listdir(temp_dir))
125
 
126
- #log render file
127
  with open(filename, "r") as f:
128
  logger.info(f.read())
129
 
 
19
  }
20
 
21
 
22
+ @logger.catch(level="DEBUG")
23
  def board_to_svg(board: chess.Board, is_pruned: bool = False, size: int = 360) -> str:
24
  """Convert a chess.Board object to an SVG string.
25
 
 
48
  return svg
49
 
50
 
51
+ @logger.catch(level="DEBUG")
52
+ def save_svg(board: chess.Board, filename: str, is_pruned: bool = False) -> None:
53
+ """Save a chess.Board object to an image file.
54
 
55
  Args:
56
  board (chess.Board): chess.Board object
 
63
  f.write(xml_declaration + board_to_svg(board, is_pruned=is_pruned))
64
 
65
 
66
+ @logger.catch(level="DEBUG", reraise=True)
67
  def plot_save_beam_search(
68
+ beam: AnyNode, filename: str, temp_dir: str = "../reports/figures"
69
  ) -> None:
70
  """Plot and save the beam search tree.
71
 
 
121
  tailport=graph_params["tailport"],
122
  )
123
 
124
+ dot.render(filename=filename, format="svg")
125
 
126
  logger.info(os.listdir(temp_dir))
127
 
128
+ # log render file
129
  with open(filename, "r") as f:
130
  logger.info(f.read())
131
 
temp/Depth 0 Candidate 0.svg CHANGED
temp/Depth 1 Candidate 0.svg CHANGED
temp/Depth 2 Candidate 1.svg CHANGED
temp/Depth 2 Candidate 2.svg CHANGED
temp/Depth 2 Candidate 4.svg CHANGED
temp/Depth 3 Candidate 0.svg CHANGED
temp/Depth 3 Candidate 1.svg CHANGED
temp/Depth 3 Candidate 2.svg CHANGED
temp/Depth 3 Candidate 3.svg CHANGED
temp/Depth 4 Candidate 1.svg CHANGED
temp/Depth 4 Candidate 2.svg CHANGED
temp/Depth 4 Candidate 3.svg CHANGED
temp/Depth 4 Candidate 4.svg CHANGED
temp/beam_search CHANGED
@@ -8,28 +8,4 @@ digraph "Beam Search" {
8
  ROOT -> "Depth 0 Candidate 1" [fontsize=20 headlabel=e8d7 headport=n tailport=s]
9
  "Depth 1 Candidate 1" [label="score = 0.2649" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 1 Candidate 1.svg" image_pos=tc labelloc=b shape=none]
10
  "Depth 0 Candidate 1" -> "Depth 1 Candidate 1" [fontsize=20 headlabel=d1b3 headport=n tailport=s]
11
- "Depth 2 Candidate 2" [label="score = -0.0108" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 2 Candidate 2.svg" image_pos=tc labelloc=b shape=none]
12
- "Depth 1 Candidate 1" -> "Depth 2 Candidate 2" [fontsize=20 headlabel=a7a5 headport=n tailport=s]
13
- "Depth 3 Candidate 0" [label="score = 0.3467" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 3 Candidate 0.svg" image_pos=tc labelloc=b shape=none]
14
- "Depth 2 Candidate 2" -> "Depth 3 Candidate 0" [fontsize=20 headlabel=b1d2 headport=n tailport=s]
15
- "Depth 0 Candidate 2" [label="score = 0.1044" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 0 Candidate 2.svg" image_pos=tc labelloc=b shape=none]
16
- ROOT -> "Depth 0 Candidate 2" [fontsize=20 headlabel=a7a6 headport=n tailport=s]
17
- "Depth 1 Candidate 2" [label="score = 0.4743" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 1 Candidate 2.svg" image_pos=tc labelloc=b shape=none]
18
- "Depth 0 Candidate 2" -> "Depth 1 Candidate 2" [fontsize=20 headlabel=f2f3 headport=n tailport=s]
19
- "Depth 2 Candidate 3" [label="score = 0.0125" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 2 Candidate 3.svg" image_pos=tc labelloc=b shape=none]
20
- "Depth 1 Candidate 2" -> "Depth 2 Candidate 3" [fontsize=20 headlabel=c7c6 headport=n tailport=s]
21
- "Depth 3 Candidate 1" [label="score = 0.1925" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 3 Candidate 1.svg" image_pos=tc labelloc=b shape=none]
22
- "Depth 2 Candidate 3" -> "Depth 3 Candidate 1" [fontsize=20 headlabel=b1a3 headport=n tailport=s]
23
- "Depth 0 Candidate 3" [label="score = 0.1071" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 0 Candidate 3.svg" image_pos=tc labelloc=b shape=none]
24
- ROOT -> "Depth 0 Candidate 3" [fontsize=20 headlabel=g7g5 headport=n tailport=s]
25
- "Depth 1 Candidate 3" [label="score = 0.2784" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 1 Candidate 3.svg" image_pos=tc labelloc=b shape=none]
26
- "Depth 0 Candidate 3" -> "Depth 1 Candidate 3" [fontsize=20 headlabel=d1c2 headport=n tailport=s]
27
- "Depth 2 Candidate 0" [label="score = -0.0356" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 2 Candidate 0.svg" image_pos=tc labelloc=b shape=none]
28
- "Depth 1 Candidate 3" -> "Depth 2 Candidate 0" [fontsize=20 headlabel=b8d7 headport=n tailport=s]
29
- "Depth 3 Candidate 2" [label="score = 0.2430" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 3 Candidate 2.svg" image_pos=tc labelloc=b shape=none]
30
- "Depth 2 Candidate 0" -> "Depth 3 Candidate 2" [fontsize=20 headlabel=g1h3 headport=n tailport=s]
31
- "Depth 2 Candidate 1" [label="score = -0.0332" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 2 Candidate 1.svg" image_pos=tc labelloc=b shape=none]
32
- "Depth 1 Candidate 3" -> "Depth 2 Candidate 1" [fontsize=20 headlabel=b8c6 headport=n tailport=s]
33
- "Depth 3 Candidate 3" [label="score = 0.1914" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 3 Candidate 3.svg" image_pos=tc labelloc=b shape=none]
34
- "Depth 2 Candidate 1" -> "Depth 3 Candidate 3" [fontsize=20 headlabel=c4d5 headport=n tailport=s]
35
  }
 
8
  ROOT -> "Depth 0 Candidate 1" [fontsize=20 headlabel=e8d7 headport=n tailport=s]
9
  "Depth 1 Candidate 1" [label="score = 0.2649" fontsize=20 image="/Users/10142632/PycharmProjects/explainable-chess-engine/demos/temp/Depth 1 Candidate 1.svg" image_pos=tc labelloc=b shape=none]
10
  "Depth 0 Candidate 1" -> "Depth 1 Candidate 1" [fontsize=20 headlabel=d1b3 headport=n tailport=s]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }