Skip to content

Commit

Permalink
Merge pull request #270 from BBN-Q/fix/mandatory_db_resource_name
Browse files Browse the repository at this point in the history
Fix/mandatory db resource name
  • Loading branch information
grahamrow committed Oct 19, 2020
2 parents 8c8ceaa + 9c92bfa commit 19a9083
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 17 deletions.
18 changes: 16 additions & 2 deletions QGL/ChannelLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,25 @@ def wrapper(cls, label, *args, **kwargs):

class ChannelLibrary(object):

def __init__(self, db_resource_name=":memory:", db_provider="sqlite"):
"""Create the channel library."""
def __init__(self, db_resource_name):
"""Create the channel library.
db_resource_name is the filename (without suffix) of the sqlite database use for the channel library.
The .sqlite suffix will automatically be added. Optionally one can be ":memory:" for a purely in-memory
database.
"""
db_provider="sqlite"

global channelLib

if ".sqlite" not in db_resource_name:
db_resource_name += ".sqlite"

if db_resource_name is not ":memory:":
if not os.path.isabs(db_resource_name):
db_resource_name = os.path.abspath(db_resource_name)

logger.info(f"Intializing database at {db_provider}:///{db_resource_name}")

bbndb.initialize_db(f'{db_provider}:///{db_resource_name}')
self.session = bbndb.get_cl_session()
self.connectivityG = nx.DiGraph()
Expand Down
4 changes: 2 additions & 2 deletions doc/ex1_QGL_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
}
],
"source": [
"cl = ChannelLibrary(db_resource_name=\"example.sqlite\")\n",
"cl = ChannelLibrary(\"example\")\n",
"\n",
"# This would be a temporary, in memory database\n",
"# cl = ChannelLibrary(db_resource_name=\":memory:\")"
"# cl = ChannelLibrary(\":memory:\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/ex2_single-qubit_sequences.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"metadata": {},
"outputs": [],
"source": [
"cl = ChannelLibrary(db_resource_name=\"example.sqlite\")"
"cl = ChannelLibrary(\"example\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/ex3_two-qubit_sequences.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"cl = ChannelLibrary(db_resource_name=\"example.sqlite\")"
"cl = ChannelLibrary(\"example\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/ex4_update_in_place.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}
],
"source": [
"cl = ChannelLibrary(db_resource_name=\":memory:\")\n",
"cl = ChannelLibrary(\":memory:\")\n",
"q1 = cl.new_qubit(\"q1\")\n",
"aps2_1 = cl.new_APS2(\"BBNAPS1\", address=\"192.168.5.101\") \n",
"aps2_2 = cl.new_APS2(\"BBNAPS2\", address=\"192.168.5.102\")\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/example_channel_library.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"source": [
"from QGL import *\n",
"\n",
"cl = ChannelLibrary(db_resource_name=\"./example.sqlite\")\n",
"cl = ChannelLibrary(\"./example\")\n",
"q1 = cl.new_qubit(\"q1\")\n",
"q2 = cl.new_qubit(\"q2\")\n",
"CNOT12 = cl.new_edge(q1, q2)\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ programs typically refer only to `Qubit` channels. Actions on other channel
types may be implied by the operation. For example, to create a `Qubit` object
in QGL, one can write:
```
cl = ChannelLibrary(db_resource_name=":memory:")
cl = ChannelLibrary(":memory:")
q1 = cl.new_qubit("q1")
```
where the Channel Library contains the "physical" information for the logical "qubit"
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from QGL import *

def setup_test_lib():
cl = ChannelLibrary(db_resource_name=":memory:")
cl = ChannelLibrary(":memory:")
cl.clear()
q1 = cl.new_qubit(label='q1')
q2 = cl.new_qubit(label='q2')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class APSPatternUtils(unittest.TestCase):
def setUp(self):
self.cl = ChannelLibrary(db_resource_name=":memory:")
self.cl = ChannelLibrary(":memory:")
#self.q1gate = Channels.LogicalMarkerChannel(label='q1-gate',
# channel_db=self.cl.channelDatabase)
self.q1 = self.cl.new_qubit(label='q1')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_APSPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class APSPatternUtils(unittest.TestCase):
def setUp(self):
self.cl = ChannelLibrary(db_resource_name=":memory:")
self.cl = ChannelLibrary(":memory:")
self.q1gate = Channels.LogicalMarkerChannel(label='q1-gate', channel_db=self.cl.channelDatabase)
self.q1 = self.cl.new_qubit(label='q1')
self.q1.gate_chan = self.q1gate
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class CompileUtils(unittest.TestCase):
def setUp(self):
print("Running setup")
self.cl = ChannelLibrary(db_resource_name=":memory:")
self.cl = ChannelLibrary(":memory:")
self.cl.clear()
self.q1gate = Channels.LogicalMarkerChannel(label='q1-gate', channel_db=self.cl.channelDatabase)
self.q1gate = Channels.LogicalMarkerChannel(label='q1-gate', channel_db=self.cl.channelDatabase)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ControlFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ControlFlowTest(unittest.TestCase):
def setUp(self):
cl = ChannelLibrary(db_resource_name=":memory:")
cl = ChannelLibrary(":memory:")
self.q1 = cl.new_qubit(label='q1')
self.q2 = cl.new_qubit(label='q2')
self.q3 = cl.new_qubit(label='q3')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_QGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SingleQubitTestCases(SequenceTestCases):
fileHeader = 'single'

def newQ1(self):
cl = ChannelLibrary(db_resource_name=":memory:")
cl = ChannelLibrary(":memory:")
cl.clear()
q1 = cl.new_qubit("q1")
q1.pulse_params['length'] = 30e-9
Expand All @@ -164,7 +164,7 @@ class MultiQubitTestCases(SequenceTestCases):

def newQubits(self):
# Create an in-memory blank channel library
cl = ChannelLibrary(db_resource_name=":memory:")
cl = ChannelLibrary(":memory:")
cl.clear()
q1 = cl.new_qubit("q1")
q2 = cl.new_qubit("q2")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def finalize_map(self, mapping):
for name, value in mapping.items():
self.channels[name].phys_chan = self.channels[value]

self.cl = ChannelLibrary(db_resource_name=":memory:")
self.cl = ChannelLibrary(":memory:")
self.cl.clear()
self.cl.session.add_all(self.channels.values())
for chan in self.channels.values():
Expand Down

0 comments on commit 19a9083

Please sign in to comment.