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
BillyKalfus committed Oct 22, 2019
2 parents aff1a7e + 8b25b2c commit f51e84e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
23 changes: 20 additions & 3 deletions QGL/ChannelLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,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 @@ -555,13 +566,19 @@ def set_bias(self, qubit, bias=None, frequency=None):
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 f51e84e

Please sign in to comment.