Skip to content

Commit

Permalink
Display CNOT properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ristè committed Jan 10, 2020
1 parent 2a4dbab commit b5735df
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions QGL/ChannelLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import bbndb

from bqplot import Figure, LinearScale, Axis, Lines, Figure
from bqplot import Figure, LinearScale, ColorScale, Axis, Lines, Figure
from bqplot.marks import Graph, Lines, Label
from ipywidgets import Layout, VBox, HBox

Expand Down Expand Up @@ -141,10 +141,10 @@ def ls(self):
cdb = Channels.ChannelDatabase
q = self.session.query(cdb.label, cdb.time, cdb.id, cdb.notes).\
order_by(-Channels.ChannelDatabase.id, Channels.ChannelDatabase.label, Channels.ChannelDatabase.notes).all()

table_code = ""
for i, (label, time, id, notes) in enumerate(q):
y, d, t = map(time.strftime, ["%Y", "%b. %d", "%I:%M:%S %p"])
# t = time.strftime("(%Y) %b. %d @ %I:%M:%S %p")
table_code += f"<tr><td>{id}</td><td>{y}</td><td>{d}</td><td>{t}</td><td>{label}</td><td>{notes}</td></tr>"
display(IPHTML(f"<table><tr><th>id</th><th>Year</th><th>Date</th><th>Time</th><th>Name</th><th>Notes</th></tr><tr>{table_code}</tr></table>"))

Expand Down Expand Up @@ -234,7 +234,7 @@ def next_level(nodes, iteration=0, offset=0, accum=[]):
fig = Figure(marks=[bq_graph], layout=fig_layout)
return fig

def show_connectivity(self):
def show_connectivity(self, verbose=False):
graph_edges = []
qub_objs = self.qubits()
edges = self.edges()
Expand All @@ -258,7 +258,9 @@ def show_connectivity(self):
graph.add_edges_from(graph_edges)

indices = {n: i for i, n in enumerate(graph.nodes())}
node_data = [{'label': n, 'data': v['node_obj'].print(False)} for n,v in graph.nodes(True)] # fix node visualization

node_data = [{'label': n, 'data': v['node_obj'].print(show=False, verbose=verbose), 'edge_data': v['node_obj'].print_edges(show=False, verbose=verbose, edges = [e for e in self.edges() if e.source.label == n or e.target.label == n]
)} for n,v in graph.nodes(True)] # fix edges
link_data = [{'source': indices[s], 'target': indices[t]} for s, t in graph.edges()]

qub_objs.sort(key=lambda x: x.label)
Expand All @@ -278,15 +280,23 @@ def hover_handler(self, content, hovered_symbol=hovered_symbol, table=table):
hovered_symbol = symbol
table.value = symbol['data']

def click_handler(self, content, hovered_symbol=hovered_symbol, table=table):
symbol = content.get('data', '')
if(symbol != hovered_symbol):
hovered_symbol = symbol
table.value = symbol['edge_data']

xs = LinearScale(min=min(x)-0.5, max=max(x)+0.6)
ys = LinearScale(min=min(y)-0.5, max=max(y)+0.6)
fig_layout = Layout(width='500px', height='500px')
bq_graph = Graph(node_data=node_data, link_data=link_data, x=x, y=y,scales={'x':xs, 'y':ys},
link_type='line', colors=['blue'] * len(node_data), directed=True)
cs = ColorScale(scheme = 'PuBuGn')
bq_graph = Graph(node_data=node_data, link_data=link_data, x=x, y=y,scales={'x':xs, 'y':ys, 'color': cs},
link_type='line', color=np.linspace(0,1,len(node_data)), directed=True)
bgs_lines = []
middles = []
bq_graph.tooltip = table
bq_graph.on_hover(hover_handler)
bq_graph.on_element_click(click_handler)
fig = Figure(marks=[bq_graph], layout=fig_layout)
return fig

Expand Down

0 comments on commit b5735df

Please sign in to comment.