Example notebook


Example notebook

This example will contain the following examples

  • Creating and saving a graph
  • Plotting the graph
  • Executing a node
  • Loading a graph from disk

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import networkx as nx
from importlib import reload
import os
import autodepgraph as adg
from autodepgraph import  AutoDepGraph_DAG


/Users/Adriaan/anaconda/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

Creatinga custom graph

A graph can be instantiated and nodes can be added to the graph as with any networkx graph object. It is important to specify a `calibrat


In [48]:
test_graph.add_node?

In [41]:
cal_True_delayed=  'autodepgraph.node_functions.calibration_functions.test_calibration_True_delayed'
test_graph = AutoDepGraph_DAG('test graph')
for node in ['A', 'B', 'C', 'D', 'E']:
    test_graph.add_node(node, 
                        calibrate_function=cal_True_delayed)

Some nodes require other nodes to be in a good or calibrated state. Such dependencies are defined by setting edges in the graph.


In [42]:
test_graph.add_edge('C', 'A')
test_graph.add_edge('C', 'B')
test_graph.add_edge('B', 'A')
test_graph.add_edge('D', 'A')
test_graph.add_edge('E', 'D')

Visualizing the graph

We support two ways of visualizing graphs:

  • matplotlib in the notebook
  • an svg in an html page that updates in real-time

Realtime svg/html visualization


In [43]:
# The default plotting mode is SVG 
test_graph.cfg_plot_mode = 'svg'
# Updates the monitor, in this case the svg/html page
test_graph.update_monitor()

# Updating the monitor overwrites an svg file whose location is determined by the attribute:
test_graph.cfg_svg_filename
# This attribute can safely be overwritten


Out[43]:
'/Users/Adriaan/GitHubRepos/DiCarloLab_Repositories/AutoDepGraph/autodepgraph/svg_viewer/adg_graph.svg'

In [44]:
# The html page is located at the location specified by the url. 
# The page generated based on a template when the open_html_viewer command is called. 
url = test_graph.open_html_viewer()
print(url)


/Users/Adriaan/GitHubRepos/DiCarloLab_Repositories/AutoDepGraph/autodepgraph/svg_viewer/svgviewer-6t2tj5gh.html

Matplotlib drawing of the graph


In [45]:
# Alternatively a render in matplotlib can be drawn 
test_graph.draw_mpl()


Maintaining the graph


In [46]:
test_graph.set_all_node_states('needs calibration')

In [39]:
test_graph.maintain_B()


Maintaining node "B".
Maintaining node "A".
	Calibrating node A.
	Calibration of node A successful.
	Calibrating node B.
	Calibration of node B successful.

In [10]:
test_graph.draw_mpl()



In [11]:
# Update the plotting monitor (default matplotlib) to show your graph
test_graph.update_monitor()

In [12]:
test_graph.set_all_node_states('needs calibration')

In [13]:
test_graph.maintain_node('E')


Maintaining node "E".
Maintaining node "D".
Maintaining node "A".
	Calibrating node A.
	Calibration of node A successful.
	Calibrating node D.
	Calibration of node D successful.
	Calibrating node E.
	Calibration of node E successful.
Out[13]:
'good'

Three qubit example

This example shows a more realistic graph. The examples below show ways of exploring the graph


In [59]:
test_dir = os.path.join(adg.__path__[0], 'tests', 'test_data')
fn = os.path.join(test_dir, 'three_qubit_graph.yaml')
DAG = nx.readwrite.read_yaml(fn)

Reset the state of all nodes


In [60]:
DAG.node['CZ q0-q1']


Out[60]:
{'calibrate_function': 'autodepgraph.node_functions.calibration_functions.test_calibration_True',
 'check_function': 'autodepgraph.node_functions.check_functions.return_fixed_value',
 'color': '#D3D3D3',
 'fillcolor': '#D3D3D3',
 'fixedsize': 'false',
 'last_update': datetime.datetime(2018, 3, 17, 23, 44, 29, 972265),
 'shape': 'ellipse',
 'state': 'unknown',
 'style': 'filled',
 'timeout': inf,
 'tolerance': 0}

In [61]:
DAG.set_all_node_states('needs calibration')
# DAG.set_all_node_states('unknown')
DAG.update_monitor()

In [57]:
DAG._construct_maintenance_methods(DAG.nodes.keys())

In [58]:
DAG.maintain_CZ_q0_q1()


Maintaining node "CZ q0-q1".
Maintaining node "Chevron q0-q1".
Maintaining node "3 qubit device multiplexed readout".
Maintaining node "q0 optimal weights".
Maintaining node "q0 pulse amplitude med".
Maintaining node "q0 frequency fine".
Maintaining node "q0 pulse amplitude coarse".
Maintaining node "AWG8 MW-staircase".
	Calibrating node AWG8 MW-staircase.
	Calibration of node AWG8 MW-staircase successful.
Maintaining node "q0 frequency coarse".
Maintaining node "q0 resonator frequency".
Maintaining node "3 qubit device resonator frequencies coarse".
	Calibrating node 3 qubit device resonator frequencies coarse.
	Calibration of node 3 qubit device resonator frequencies coarse successful.
	Calibrating node q0 resonator frequency.
	Calibration of node q0 resonator frequency successful.
	Calibrating node q0 frequency coarse.
	Calibration of node q0 frequency coarse successful.
Maintaining node "q0 mixer offsets drive".
	Calibrating node q0 mixer offsets drive.
	Calibration of node q0 mixer offsets drive successful.
Maintaining node "q0 mixer offsets readout".
	Calibrating node q0 mixer offsets readout.
	Calibration of node q0 mixer offsets readout successful.
Maintaining node "q0 mixer skewness drive".
	Calibrating node q0 mixer skewness drive.
	Calibration of node q0 mixer skewness drive successful.
	Calibrating node q0 pulse amplitude coarse.
	Calibration of node q0 pulse amplitude coarse successful.
	Calibrating node q0 frequency fine.
	Calibration of node q0 frequency fine successful.
	Calibrating node q0 pulse amplitude med.
	Calibration of node q0 pulse amplitude med successful.
	Calibrating node q0 optimal weights.
	Calibration of node q0 optimal weights successful.
Maintaining node "q1 optimal weights".
Maintaining node "q1 pulse amplitude med".
Maintaining node "q1 frequency fine".
Maintaining node "q1 pulse amplitude coarse".
Maintaining node "q1 frequency coarse".
Maintaining node "q1 resonator frequency".
	Calibrating node q1 resonator frequency.
	Calibration of node q1 resonator frequency successful.
	Calibrating node q1 frequency coarse.
	Calibration of node q1 frequency coarse successful.
Maintaining node "q1 mixer offsets drive".
	Calibrating node q1 mixer offsets drive.
	Calibration of node q1 mixer offsets drive successful.
Maintaining node "q1 mixer offsets readout".
	Calibrating node q1 mixer offsets readout.
	Calibration of node q1 mixer offsets readout successful.
Maintaining node "q1 mixer skewness drive".
	Calibrating node q1 mixer skewness drive.
	Calibration of node q1 mixer skewness drive successful.
	Calibrating node q1 pulse amplitude coarse.
	Calibration of node q1 pulse amplitude coarse successful.
	Calibrating node q1 frequency fine.
	Calibration of node q1 frequency fine successful.
	Calibrating node q1 pulse amplitude med.
	Calibration of node q1 pulse amplitude med successful.
	Calibrating node q1 optimal weights.
	Calibration of node q1 optimal weights successful.
Maintaining node "q2 optimal weights".
Maintaining node "q2 pulse amplitude med".
Maintaining node "q2 frequency fine".
Maintaining node "q2 pulse amplitude coarse".
Maintaining node "q2 frequency coarse".
Maintaining node "q2 resonator frequency".
	Calibrating node q2 resonator frequency.
	Calibration of node q2 resonator frequency successful.
	Calibrating node q2 frequency coarse.
	Calibration of node q2 frequency coarse successful.
Maintaining node "q2 mixer offsets drive".
	Calibrating node q2 mixer offsets drive.
	Calibration of node q2 mixer offsets drive successful.
Maintaining node "q2 mixer offsets readout".
	Calibrating node q2 mixer offsets readout.
	Calibration of node q2 mixer offsets readout successful.
Maintaining node "q2 mixer skewness drive".
	Calibrating node q2 mixer skewness drive.
	Calibration of node q2 mixer skewness drive successful.
	Calibrating node q2 pulse amplitude coarse.
	Calibration of node q2 pulse amplitude coarse successful.
	Calibrating node q2 frequency fine.
	Calibration of node q2 frequency fine successful.
	Calibrating node q2 pulse amplitude med.
	Calibration of node q2 pulse amplitude med successful.
	Calibrating node q2 optimal weights.
	Calibration of node q2 optimal weights successful.
	Calibrating node 3 qubit device multiplexed readout.
	Calibration of node 3 qubit device multiplexed readout successful.
Maintaining node "AWG8 Flux-staircase".
	Calibrating node AWG8 Flux-staircase.
	Calibration of node AWG8 Flux-staircase successful.
Maintaining node "q0 gates restless".
	Calibrating node q0 gates restless.
	Calibration of node q0 gates restless successful.
Maintaining node "q1 gates restless".
	Calibrating node q1 gates restless.
	Calibration of node q1 gates restless successful.
	Calibrating node Chevron q0-q1.
	Calibration of node Chevron q0-q1 successful.
Maintaining node "q0 cryo dist. corr.".
Maintaining node "q0 room temp. dist. corr.".
	Calibrating node q0 room temp. dist. corr..
	Calibration of node q0 room temp. dist. corr. successful.
	Calibrating node q0 cryo dist. corr..
	Calibration of node q0 cryo dist. corr. successful.
Maintaining node "q1 cryo dist. corr.".
Maintaining node "q1 room temp. dist. corr.".
	Calibrating node q1 room temp. dist. corr..
	Calibration of node q1 room temp. dist. corr. successful.
	Calibrating node q1 cryo dist. corr..
	Calibration of node q1 cryo dist. corr. successful.
	Calibrating node CZ q0-q1.
	Calibration of node CZ q0-q1 successful.