Skip to content

Commit 85ba1e2

Browse files
authored
Merge pull request #407 from QE-Lab/fix-cqasm-reader-cr
Fix parsing of real numbers in gate arguments in cQASM
2 parents 7f2e2bb + d3e1f09 commit 85ba1e2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/cqasm/cqasm_reader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class AngleFromParameter : public Value<Real> {
188188
Real val;
189189
if (auto i = operands[index]->as_const_int()) {
190190
val = i->value;
191-
} else if (auto r = operands[index]->as_const_int()) {
191+
} else if (auto r = operands[index]->as_const_real()) {
192192
val = r->value;
193193
} else {
194194
throw Exception("expected a real number at " + location(*operands[index]));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version 1.0
2+
# this file has been automatically generated by the OpenQL compiler please do not modify it manually.
3+
qubits 10
4+
5+
._0
6+
rx q[0], 1
7+
wait 1

tests/test_cqasm_reader.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ def test_single_bit_kernel_operations(self):
5959
program.compile()
6060
self.assertTrue(file_compare(os.path.join(output_dir, name + '.qasm'), os.path.join(curdir, 'golden', name + '.qasm')))
6161

62+
def test_cqasm_real_numbers(self):
63+
config_fn = os.path.join(curdir, 'hardware_config_qx.json')
64+
platform = ql.Platform('seven_qubits_chip', config_fn)
65+
number_qubits = platform.get_qubit_number()
66+
name = 'test_cqasm_real_numbers'
67+
program = ql.Program(name, platform, number_qubits)
68+
qasm_rdr = ql.cQasmReader(platform, program)
69+
qasm_str = "version 1.0\n" \
70+
"qubits 5\n" \
71+
"error_model depolarizing_channel, 0.001\n" \
72+
"rx q[0], 1.0\n"
73+
qasm_rdr.string2circuit(qasm_str)
74+
program.compile()
75+
self.assertTrue(file_compare(os.path.join(output_dir, name + '.qasm'), os.path.join(curdir, 'golden', name + '.qasm')))
76+
6277
def test_sub_circuit_programs(self):
6378
config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
6479
platform = ql.Platform('seven_qubits_chip', config_fn)

0 commit comments

Comments
 (0)