Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:bbn-q/qgl into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gribeill committed Oct 24, 2019
2 parents 6e066a8 + f51e84e commit 823d9e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
28 changes: 22 additions & 6 deletions QGL/ChannelLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from . import config
from . import Channels
from . import PulseShapes
from .PulsePrimitives import clear_pulse_cache

from IPython.display import HTML, display

Expand Down Expand Up @@ -140,14 +139,25 @@ def update_channelDict(self):
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()
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(HTML(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>"))

def cal_ls(self):
''' List of auspex.pulse_calibration results '''
caldb = bbndb.calibration.Calibration
c = self.session.query(caldb.sample_id, caldb.name, caldb.value, caldb.date).order_by(-Channels.ChannelDatabase.id).all()
table_code = ""
for i, (id, sample_id, name, value, time) in enumerate(c):
d,t = str(time).split()
sample = self.session.query(bbndb.calibration.Sample).filter_by(id=sample_id).first()
table_code += f"<tr><td>{id}</td><td>{d}</td><td>{t.split('.')[0]}</td><td>{sample.name}</td><td>{name}</td><td>{round(value,9)}</td></tr>"
display(HTML(f"<table><tr><th>id</th><th>Date</th><th>Time</th><th>Sample</th><th>Name</th><th>Value</th></tr><tr>{table_code}</tr></table>"))

def ent_by_type(self, obj_type, show=False):
q = self.session.query(obj_type).filter(obj_type.channel_db.has(label="working")).order_by(obj_type.label).all()
if show:
Expand Down Expand Up @@ -553,16 +563,22 @@ def set_bias(self, qubit, bias=None, frequency=None):
bias_pairs = sorted(qubit.bias_pairs.items())
biases = [k[0] for k in bias_pairs]
frequencies = [k[1] for k in bias_pairs]
qubit.phys_chan.generator.frequency = freq if freq else interp1d(biases, frequencies)([bias])[0]
qubit.bias_source.level = bias if bias else interp1d(frequencies, biases)([freq])[0]
qubit.phys_chan.generator.frequency = frequency if frequency else interp1d(biases, frequencies)([bias])[0]
qubit.bias_source.level = bias if bias else interp1d(frequencies, biases)([frequency])[0]

def new_edge(self, source, target):
def new_edge(self, source, target, cnot_impl=None):
"""
Create a new edge connecting two qubits
source (Qubit): logical channel for source qubit
target (Qubit): logical channel for target qubit
cnot_impl (string, optional): function name for CNOT implementation, overriding the default in QGL/config.py
"""
label = f"{source.label}->{target.label}"
if label in self.channelDict:
edge = self.channelDict[f"{source.label}->{target.label}"]
logger.warning(f"The edge {source.label}->{target.label} already exists: using this edge.")
else:
edge = Channels.Edge(label=f"{source.label}->{target.label}", source=source, target=target, channel_db=self.channelDatabase)
edge = Channels.Edge(label=f"{source.label}->{target.label}", source=source, target=target, channel_db=self.channelDatabase, cnot_impl=cnot_impl)
self.add_and_update_dict(edge)
return edge

Expand Down
7 changes: 6 additions & 1 deletion QGL/PulsePrimitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,12 @@ def CNOT_simple(source, target, **kwargs):

@_memoize
def CNOT(source, target, **kwargs):
cnot_impl = globals()[config.cnot_implementation]
channel = ChannelLibraries.EdgeFactory(source, target)
if hasattr(channel, 'cnot_impl') and channel.cnot_impl:
cnot_impl_name = channel.cnot_impl
else:
cnot_impl_name = config.cnot_implementation
cnot_impl = globals()[cnot_impl_name]
return cnot_impl(source, target, **kwargs)

# The worker method for MEAS and MEASA
Expand Down
5 changes: 3 additions & 2 deletions QGL/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
pulse_primitives_lib = "standard"

# select a CNOT implementation (a name of a Pulse function that implements
# CNOT in your gate set, e.g. CNOT_simple or CNOT_CR)
cnot_implementation = "CNOT_simple"
# CNOT in your gate set, e.g. CNOT_simple or CNOT_CR).
# This default can be overridden on a per-Edge case as a channel property
cnot_implementation = "CNOT_CR"

def load_config():
global config_file
Expand Down

0 comments on commit 823d9e6

Please sign in to comment.