Skip to content

Commit

Permalink
Merge pull request #77 from AdriaanRol/develop
Browse files Browse the repository at this point in the history
PR for release 0.3.5

- Included call funtion kwargs (#75, PR by @jorgemfm27 )
- Fixed networkx 2.x compatibility issues #73.
- Updated example notebook.
- Made SVG file location a property of the graph to solve a bug caused by reading and writing files.
- updated version tag to 0.3.5.
- Fixed a bug that caused the PyPI shield to show the wrong version.
  • Loading branch information
AdriaanRol authored Aug 12, 2020
2 parents 36d3ac3 + dd08a4e commit 93efb54
Show file tree
Hide file tree
Showing 3 changed files with 1,109 additions and 94 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# AutoDepGraph
# AutoDepGraph

[![PyPI](https://img.shields.io/pypi/v/adaptive.svg)](https://pypi.python.org/pypi/autodepgraph)
[![PyPI](https://img.shields.io/pypi/v/autodepgraph.svg)](https://pypi.python.org/pypi/autodepgraph)
[![Build Status](https://travis-ci.org/AdriaanRol/AutoDepGraph.svg?branch=master)](https://travis-ci.org/AdriaanRol/AutoDepGraph)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ae46c58617ff45df9ac98446b3dc34ac)](https://www.codacy.com/app/adriaan-rol/AutoDepGraph?utm_source=github.com&utm_medium=referral&utm_content=AdriaanRol/AutoDepGraph&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ae46c58617ff45df9ac98446b3dc34ac)](https://www.codacy.com/app/adriaan-rol/AutoDepGraph?utm_source=github.com&utm_medium=referral&utm_content=AdriaanRol/AutoDepGraph&utm_campaign=Badge_Grade)
[![Coverage Status](https://coveralls.io/repos/github/AdriaanRol/AutoDepGraph/badge.svg?branch=master)](https://coveralls.io/github/AdriaanRol/AutoDepGraph?branch=master)
[![DOI](https://zenodo.org/badge/85987885.svg)](https://zenodo.org/badge/latestdoi/85987885)

AutoDepGraph is a framework for using dependency graphs to calibrate a system. It is heavily inspired by ["Physical qubit calibration on a directed acyclic graph"](https://arxiv.org/abs/1803.03226).
AutoDepGraph is a framework for using dependency graphs to calibrate a system. It is heavily inspired by ["Physical qubit calibration on a directed acyclic graph"](https://arxiv.org/abs/1803.03226).

## Overview
AutoDepGraph consists of two main classes, the CalibrationNode and the Graph.
Expand All @@ -21,11 +21,11 @@ A CalibrationNode contains:
+ Bad (red): calibration or check has failed
+ unknown (grayed): checks of the node should be run
+ active (blue): calibration or check in progress
- parents: the nodes it depends on
- parents: the nodes it depends on
- children: nodes that depend on this node
- check_function : name of function to be executed when check is called. This can be a method of another instrument.
- calibrate_function : name of function to be executed when calibrate is called. This can be a method of another instrument.
- calibration_timeout: time in (s) after which a calibration times out.
- calibration_timeout: time in (s) after which a calibration times out.

- function
- execute or call
Expand All @@ -35,8 +35,8 @@ A CalibrationNode contains:
- calibrate
+ Executes the calibration routines of the node

A Graph is a container of nodes, it is used for:
- new graphs can be created by instantiating a graph and then using the add_node method to define new nodes.
A Graph is a container of nodes, it is used for:
- new graphs can be created by instantiating a graph and then using the add_node method to define new nodes.
- loading and saving the graph
- real-time visualization using pyqtgraph
- state of the node determines color of a node
Expand All @@ -45,7 +45,7 @@ A Graph is a container of nodes, it is used for:

![Example calibration graph](docs/example_graph.png)

## Examples
## Examples
For an introductory example see the example notebook. If you want to see how to use a specific function, see the tests located in the autodepgraph/tests folder.

## Installation
Expand All @@ -54,8 +54,8 @@ For an introductory example see the example notebook. If you want to see how to
- navigate to the repository and run `pip install -e .`
- verify success of installation by running `py.test`

#### N.B. windows can be "problematic"
Installation on windows is a bit more difficult, this relates mostly to the installation of pygraphviz. To install graphviz and pygraphviz on windows follow these steps:
#### N.B. windows can be "problematic"
Installation on windows is a bit more difficult, this relates mostly to the installation of pygraphviz. To install graphviz and pygraphviz on windows follow these steps:

- get the 64 bit version of ![graphviz for windows](https://github.com/mahkoCosmo/GraphViz_x64/), copy it to e.g., program files and add the bin folder to the system path.
- the 64 bit version lacks the libxml2.dll, you most likely have this from some other program. You can find this by searching for `libxml2.dll` in the program files folder. After that just copy paste it to the bin folder of graphviz.
Expand All @@ -69,4 +69,4 @@ python setup.py install --include-path="C:\Program Files\graphviz-2.38_x64\inclu
- then install autodepgraph and test the installation using `py.test`

## Acknowledgements
I would like to thank Julian Kelly for the idea of using a dependency graph for calibrations and for early discussions. I would like to thank Joe Weston for discussions and help in working out the initial design. I would like to acknowledge Livio Ciorciaro for disucssions and as a coauthor of this project.
I would like to thank Julian Kelly for the idea of using a dependency graph for calibrations and for early discussions. I would like to thank Joe Weston for discussions and help in working out the initial design. I would like to acknowledge Livio Ciorciaro for disucssions and as a coauthor of this project.
47 changes: 16 additions & 31 deletions autodepgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

class AutoDepGraph_DAG(nx.DiGraph):
"""
Attributes:
node_states: Allowed states for the nodes
matplotlib_edge_properties: Properties passed to networkx plotting of edges
matplotlib_label_properties: Properties passed to networkx plotting of labels
"""
node_states : List[str] = ['good', 'needs calibration',
'bad', 'unknown', 'active']
Expand All @@ -52,9 +52,6 @@ def __init__(self, name, cfg_plot_mode='svg',
self.cfg_plot_mode = cfg_plot_mode
self.cfg_plot_mode_args = {'fig': None}

_path_name = split(__file__)[:-1][0]
self.cfg_svg_filename = join(_path_name, 'svg_viewer', 'adg_graph.svg')

super().__init__(incoming_graph_data, **attr)

# internal attributes
Expand All @@ -66,7 +63,15 @@ def __init__(self, name, cfg_plot_mode='svg',
self._exec_cnt = 0
self._calib_cnt = 0
self._check_cnt = 0



@property
def cfg_svg_filename(self):
"""
Default location for storing svg based visualizations of the DAG.
"""
_path_name = split(__file__)[:-1][0]
return join(_path_name, 'svg_viewer', 'adg_graph.svg')

def fresh_copy(self):
return AutoDepGraph_DAG(name=self.name,
Expand Down Expand Up @@ -96,9 +101,6 @@ def add_node(self, node_for_adding, **attr):
'autodepgraph.node_functions.calibration_functions' +
'.NotImplementedCalibration')

attr.setdefault('calibrate_function_kwargs', {})
'calibrate_function_kwargs', {})

attr['check_function'] = attr.get(
'check_function',
'autodepgraph.node_functions.check_functions' +
Expand Down Expand Up @@ -283,10 +285,8 @@ def calibrate_node(self, node : str, verbose : bool =False):
self.set_node_state(node, 'active')

func = _get_function(self.nodes[node]['calibrate_function'])
func_kwargs = self.nodes[node]['calibrate_function_kwargs']

try:
result = func(**func_kwargs)
result = func()
except Exception as e:
self.set_node_state(node, 'bad')
logging.warning(e)
Expand All @@ -311,8 +311,6 @@ def set_all_node_states(self, state):
def update_monitor(self):
if self.cfg_plot_mode == 'matplotlib':
self.update_monitor_mpl()
# elif self.cfg_plot_mode == 'pyqtgraph':
# self.draw_pg()
elif self.cfg_plot_mode == 'svg':
self.draw_svg()
elif self.cfg_plot_mode is None or self.cfg_plot_mode == 'None':
Expand All @@ -337,8 +335,7 @@ def _generate_node_positions(self, node_positions : Optional[dict] = None):
nodes=self.nodes()

if node_positions is None:
node_positions = {}

node_positions = {}
def position_generator(N=10, centre=[0,5]):
""" Generate circle of positions around centre """
idx=0
Expand All @@ -350,9 +347,8 @@ def position_generator(N=10, centre=[0,5]):

positions=position_generator(len(nodes))
pos=dict([ (node, node_positions.get(node, next(positions)) ) for node in nodes] )
return pos


return pos

def draw_mpl(self, ax=None):
if ax is None:
f, ax = plt.subplots()
Expand All @@ -376,17 +372,6 @@ def _format_mpl_plot(ax):
ax.set_xticks([])
ax.set_yticks([])

# def draw_pg(self, DiGraphWindow=None):
# """
# draws the graph using an interactive pyqtgraph window
# """
# if DiGraphWindow is None:
# DiGraphWindow = self._DiGraphWindow
# self._DiGraphWindow = vis.draw_graph_pyqt(
# self, DiGraphWindow=DiGraphWindow,
# window_title=self.name)
# return self._DiGraphWindow

def draw_svg(self, filename: str=None):
"""
"""
Expand Down Expand Up @@ -446,7 +431,7 @@ def set_node_description(self, node, description):

def calibration_state(self):
""" Return dictionary with current calibration state """
return dict(self.node)
return dict(self.nodes)

def _update_drawing_attrs(self):
for node_name, node_attrs in self.nodes(True):
Expand Down
Loading

0 comments on commit 93efb54

Please sign in to comment.