Skip to content

Commit

Permalink
Merge pull request #182 from QE-Lab/bug/155-attribute-names
Browse files Browse the repository at this point in the history
removed underscores from program/kernel attributes, closes #155
  • Loading branch information
imranashraf authored Oct 2, 2018
2 parents 49042ee + 0692c74 commit feeb478
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 147 deletions.
170 changes: 85 additions & 85 deletions openql/openql.h

Large diffs are not rendered by default.

37 changes: 28 additions & 9 deletions tests/test_Kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ class Test_kernel(unittest.TestCase):
def setUpClass(self):
pass

def test_kernel_name(self):
name = "kernel1"
nqubits = 3
k = ql.Kernel(name, platf, nqubits)
self.assertEqual(k.name, name)

def test_kernel_qubit_count(self):
name = "kernel1"
nqubits=3
k = ql.Kernel(name, platf, nqubits)
self.assertEqual(k.qubit_count, nqubits)

def test_kernel_creg_count(self):
name = "kernel1"
nqubits=2
ncreg = 3
k = ql.Kernel(name, platf, nqubits, ncreg)
self.assertEqual(k.creg_count, ncreg)


def test_allowed_operations(self):
nqubits = 3
k = ql.Kernel("kernel1", platf, nqubits)
Expand All @@ -32,20 +52,19 @@ def test_allowed_operations(self):
# Single qubit cliffords
'clifford',
# 2 qubit gates
'cnot', 'cphase',
'cnot', 'cphase', 'cz',
# Theorist gates
'identity', 'hadamard', 's', 'sdag', 'toffoli',
'identity', 'hadamard', 's', 'sdag', 't', 'tdag', 'toffoli',
# pauli operators
'x', 'y', 'z']
'x', 'y', 'z',
# arbitrary rotations
'rx', 'ry', 'rz',
# synchronization
'wait', 'barrier'
]
# Test that these operations exist as methods of the kernel
self.assertTrue(set(operations).issubset(dir(k)))

def test_kernel_name(self):
name = "kernel1"
nqubits = 3
k = ql.Kernel(name, platf, nqubits)
self.assertEqual(k.name_, name)

def test_simple_kernel(self):
nqubits = 3
k = ql.Kernel("kernel1", platf, nqubits)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_Platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import unittest
from openql import openql as ql

curdir = os.path.dirname(__file__)
output_dir = os.path.join(curdir, 'test_output')

ql.set_option('output_dir', output_dir)
ql.set_option('optimize', 'no')
ql.set_option('scheduler', 'ALAP')
ql.set_option('log_level', 'LOG_WARNING')


class Test_platform(unittest.TestCase):

@classmethod
def setUpClass(self):
pass

def test_platform_name(self):
platf_name = 'starmon_platform'
config_fn = os.path.join(curdir, 'test_cfg_cbox.json')
platf = ql.Platform(platf_name, config_fn)
self.assertEqual(platf.name, platf_name)

def test_config_file(self):
platf_name = 'starmon_platform'
config_fn = os.path.join(curdir, 'test_cfg_cbox.json')
platf = ql.Platform(platf_name, config_fn)
self.assertEqual(platf.config_file, config_fn)

if __name__ == '__main__':
unittest.main()
23 changes: 21 additions & 2 deletions tests/test_Program.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ class Test_program(unittest.TestCase):
def setUpClass(self):
pass

# @unittest.skip('NotImplemented')
def test_program_name(self):
name = "program1"
nqubits=1
p = ql.Program(name, platf, nqubits)
self.assertEqual(p.name_, name)
self.assertEqual(p.name, name)

def test_program_qubit_count(self):
name = "program1"
nqubits=3
p = ql.Program(name, platf, nqubits)
self.assertEqual(p.qubit_count, nqubits)

def test_program_creg_count(self):
name = "program1"
nqubits=2
ncreg = 3
p = ql.Program(name, platf, nqubits, ncreg)
self.assertEqual(p.creg_count, ncreg)

def test_add_kernel(self):
# test that this does not raise any error
Expand All @@ -43,6 +55,13 @@ def test_program_methods(self):
p = ql.Program('program1', platf, nqubits)
program_methods = [
'add_kernel',
'add_program',
'add_if',
'add_if_else',
'add_do_while',
'add_for',
'print_interaction_matrix',
'write_interaction_matrix',
'compile',
'microcode',
'qasm',
Expand Down
38 changes: 19 additions & 19 deletions tests/test_cc_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_smis(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# single qubit mask generation test with custom gates
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_smis_with_custom_gates(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# single qubit mask generation multi-kernel test (custom with non-custom
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_smis_multi_kernel(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

def test_smis_all_bundled(self):
Expand All @@ -193,7 +193,7 @@ def test_smis_all_bundled(self):
# compile the program
p.compile()

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
GOLD_fn = rootDir + '/golden/test_smis_all_bundled.qisa'

assemble(QISA_fn)
Expand Down Expand Up @@ -246,7 +246,7 @@ def test_smit(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

def test_smit_all_bundled(self):
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_smit_all_bundled(self):
# compile the program
p.compile()

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
GOLD_fn = rootDir + '/golden/test_smit_all_bundled.qisa'

assemble(QISA_fn)
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_qubit_busy(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# @unittest.skip
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_qwg_available_01(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# @unittest.skip
Expand Down Expand Up @@ -384,7 +384,7 @@ def test_qwg_available_02(self):
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# @unittest.skip
Expand Down Expand Up @@ -440,7 +440,7 @@ def test_measure_available01(self):
# compile the program
p.compile()

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# load qasm
Expand Down Expand Up @@ -510,7 +510,7 @@ def test_measure_busy(self):
# compile the program
p.compile()

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# load qasm
Expand Down Expand Up @@ -575,7 +575,7 @@ def test_edge_busy(self):
# compile the program
p.compile()

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# load qasm
Expand Down Expand Up @@ -648,7 +648,7 @@ def test_fast_feedback(self):
# compile the program
p.compile()

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
assemble(QISA_fn)

# load qasm
Expand Down Expand Up @@ -706,15 +706,15 @@ def test_ccl_buffers(self):

# load qasm
qasm_files = []
qasm_files.append(os.path.join(output_dir, p.name_+'.qasm'))
qasm_files.append(os.path.join(output_dir, p.name_+'_scheduled.qasm'))
qasm_files.append(os.path.join(output_dir, p.name+'.qasm'))
qasm_files.append(os.path.join(output_dir, p.name+'_scheduled.qasm'))

for qasm_file in qasm_files:
qasm_reader = ql.QASM_Loader(qasm_file)
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
gold_fn = rootDir + '/golden/test_ccl_buffers_'+str(testNo)+'.qisa'

assemble(QISA_fn)
Expand Down Expand Up @@ -757,15 +757,15 @@ def test_ccl_latencies(self):

# load qasm
qasm_files = []
qasm_files.append(os.path.join(output_dir, p.name_+'.qasm'))
qasm_files.append(os.path.join(output_dir, p.name_+'_scheduled.qasm'))
qasm_files.append(os.path.join(output_dir, p.name+'.qasm'))
qasm_files.append(os.path.join(output_dir, p.name+'_scheduled.qasm'))

for qasm_file in qasm_files:
qasm_reader = ql.QASM_Loader(qasm_file)
errors = qasm_reader.load()
self.assertTrue(errors == 0)

QISA_fn = os.path.join(output_dir, p.name_+'.qisa')
QISA_fn = os.path.join(output_dir, p.name+'.qisa')
gold_fn = rootDir + '/golden/test_ccl_latencies_'+str(testNo)+'.qisa'

assemble(QISA_fn)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_conjugate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_conjugate(self):
p.compile()

gold_fn = rootDir + '/golden/test_conjugate.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'.qasm')
qasm_fn = os.path.join(output_dir, p.name+'.qasm')
self.assertTrue( file_compare(qasm_fn, gold_fn) )

if __name__ == '__main__':
Expand Down
18 changes: 9 additions & 9 deletions tests/test_dependence.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_independent(self):
p.compile()

gold_fn = rootDir + '/golden/test_independence.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')
self.assertTrue( file_compare(qasm_fn, gold_fn) )

# load qasm
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_WAW(self):
p.compile()

gold_fn = rootDir + '/golden/test_WAW_ASAP.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')

print(gold_fn)
print(qasm_fn)
Expand All @@ -106,8 +106,8 @@ def test_WAW(self):

# load qasm
qasm_files = []
qasm_files.append(os.path.join(output_dir, p.name_+'.qasm'))
qasm_files.append(os.path.join(output_dir, p.name_+'_scheduled.qasm'))
qasm_files.append(os.path.join(output_dir, p.name+'.qasm'))
qasm_files.append(os.path.join(output_dir, p.name+'_scheduled.qasm'))

for qasm_file in qasm_files:
qasm_reader = ql.QASM_Loader(qasm_file)
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_RAR_Control(self):
p.compile()

gold_fn = rootDir + '/golden/test_RAR_Control_ASAP.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')

self.assertTrue( file_compare(qasm_fn, gold_fn) )

Expand Down Expand Up @@ -183,7 +183,7 @@ def test_RAW(self):
p.compile()

gold_fn = rootDir + '/golden/test_RAW_ASAP.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')

self.assertTrue( file_compare(qasm_fn, gold_fn) )

Expand Down Expand Up @@ -225,7 +225,7 @@ def test_WAR(self):
p.compile()

gold_fn = rootDir + '/golden/test_WAR_ASAP.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')

self.assertTrue( file_compare(qasm_fn, gold_fn) )

Expand Down Expand Up @@ -260,7 +260,7 @@ def test_swap_single(self):
p.compile()

gold_fn = rootDir + '/golden/test_swap_single_ASAP.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')

self.assertTrue( file_compare(qasm_fn, gold_fn) )

Expand Down Expand Up @@ -297,7 +297,7 @@ def test_swap_multi(self):
p.compile()

gold_fn = rootDir + '/golden/test_swap_multi_ASAP.qasm'
qasm_fn = os.path.join(output_dir, p.name_+'_scheduled.qasm')
qasm_fn = os.path.join(output_dir, p.name+'_scheduled.qasm')
self.assertTrue( file_compare(qasm_fn, gold_fn) )

# load qasm
Expand Down
Loading

0 comments on commit feeb478

Please sign in to comment.