Skip to content

Commit

Permalink
tamaki callback usage update
Browse files Browse the repository at this point in the history
  • Loading branch information
danlkv committed Oct 26, 2023
1 parent 1b47507 commit 66e1708
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ local.properties
*.cobaltlog
*.error
*.output

bench/qc_simulation/data/
17 changes: 14 additions & 3 deletions qtensor/optimisation/Optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,28 @@ def _get_ordering_ints(self, graph, inplace=True):
return peo, [self.treewidth]

class TamakiOptimizer(GreedyOptimizer):
def __init__(self, max_width=None, *args, wait_time=5, **kwargs):
def __init__(self, max_width=None, *args, wait_time=5,
update_callback=None,
**kwargs):
"""
Args:
- max_width: stop when width is less than max_width
- wait_time: maximum time to wait for tamaki to finish
- update_callback: callback function to update progress bar accepts tuple
(time, width). Called when width is changed.
"""
super().__init__(*args, **kwargs)
self.wait_time = wait_time
self.max_width = max_width
self._update_callback = **kwargs.get('update_callback')
self._update_callback = update_callback

def _get_ordering(self, graph, inplace=True):
node_names = nx.get_node_attributes(graph, 'name')
node_sizes = nx.get_node_attributes(graph, 'size')
peo, tw = qtree.graph_model.peo_calculation.get_upper_bound_peo_pace2017_interactive(
graph, method="tamaki", max_time=self.wait_time, max_width=self.max_width)
graph, method="tamaki", max_time=self.wait_time, max_width=self.max_width,
callback=self._update_callback
)


peo = [qtree.optimizer.Var(var, size=node_sizes[var],
Expand Down

0 comments on commit 66e1708

Please sign in to comment.