Skip to content

Commit

Permalink
Fix emscripten tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rturrado committed Nov 13, 2024
1 parent 38f598b commit 060d80a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions emscripten/test_libqasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wrapper().then(function(result: any) {
try {
let program_2 = "version 3;qubit[5] q;bit[5] b;H q[0:4];b = measure q"
let output = cqasm.parse_string_to_json(program_2, "<unknown>")
let expected_output = String.raw`{"Program":{"version":{"Version":{"items":"3","source_location":"<unknown>:1:9..10"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Type":{"name":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":"<unknown>:1:11..19"}},"annotations":[],"source_location":"<unknown>:1:20..21"}},{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Type":{"name":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":"<unknown>:1:22..28"}},"annotations":[],"source_location":"<unknown>:1:29..30"}},{"GateInstruction":{"gate":{"Gate":{"name":{"Identifier":{"name":"H"}},"gate":"-","parameter":"-","annotations":[],"source_location":"<unknown>:1:31..32"}},"operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexRange":{"first":{"IntegerLiteral":{"value":"0","source_location":"<unknown>:1:35..36"}},"last":{"IntegerLiteral":{"value":"4","source_location":"<unknown>:1:37..38"}}}}]}},"source_location":"<unknown>:1:33..34"}}]}},"annotations":[],"source_location":"<unknown>:1:31..32"}},{"NonGateInstruction":{"name":{"Keyword":{"name":"measure"}},"operands":{"ExpressionList":{"items":[{"Identifier":{"name":"b","source_location":"<unknown>:1:40..41"}},{"Identifier":{"name":"q","source_location":"<unknown>:1:52..53"}}]}},"annotations":[],"source_location":"<unknown>:1:44..51"}}]}}}}`
let expected_output = String.raw`{"Program":{"version":{"Version":{"items":"3","source_location":"<unknown>:1:9..10"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Type":{"name":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":"<unknown>:1:11..19"}},"annotations":[],"source_location":"<unknown>:1:20..21"}},{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Type":{"name":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"5"}},"source_location":"<unknown>:1:22..28"}},"annotations":[],"source_location":"<unknown>:1:29..30"}},{"GateInstruction":{"gate":{"Gate":{"name":{"Identifier":{"name":"H"}},"gate":"-","parameter":"-","annotations":[],"source_location":"<unknown>:1:31..32"}},"operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexRange":{"first":{"IntegerLiteral":{"value":"0","source_location":"<unknown>:1:35..36"}},"last":{"IntegerLiteral":{"value":"4","source_location":"<unknown>:1:37..38"}}}}]}},"source_location":"<unknown>:1:33..34"}}]}},"annotations":[],"source_location":"<unknown>:1:31..32"}},{"NonGateInstruction":{"name":{"Keyword":{"name":"measure"}},"operands":{"ExpressionList":{"items":[{"Identifier":{"name":"b","source_location":"<unknown>:1:40..41"}},{"Identifier":{"name":"q","source_location":"<unknown>:1:52..53"}}]}},"parameter":"-","annotations":[],"source_location":"<unknown>:1:44..51"}}]}}}}`
console.log("\nExample 2:", program_2, "\n\tCalling parse_string_to_json...", "\n\tOutput:", output)
if (output !== expected_output) {
console.log("\tExpected output:", expected_output)
Expand All @@ -56,7 +56,7 @@ wrapper().then(function(result: any) {
try {
let program_4 = "version 3;qubit[5] q;bit[5] b;H q[0:4];b = measure q"
let output = cqasm.analyze_string_to_json(program_4, "spin_q.cq")
let expected_output = String.raw`{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":[{"GateInstruction":{"instruction_ref":"H(qubit array)","gate":{"Gate":{"name":"H","gate":"-","parameter":"-","annotations":[]}},"operands":[{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},"indices":[{"ConstInt":{"value":"0"}},{"ConstInt":{"value":"1"}},{"ConstInt":{"value":"2"}},{"ConstInt":{"value":"3"}},{"ConstInt":{"value":"4"}}]}}],"annotations":[]}},{"NonGateInstruction":{"instruction_ref":"measure(bit array, qubit array)","name":"measure","operands":[{"VariableRef":{"variable":{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}}},{"VariableRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}}}}],"annotations":[]}}]}},"variables":[{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}]}}`
let expected_output = String.raw`{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":[{"GateInstruction":{"instruction_ref":"H(qubit array)","gate":{"Gate":{"name":"H","gate":"-","parameter":"-","annotations":[]}},"operands":[{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},"indices":[{"ConstInt":{"value":"0"}},{"ConstInt":{"value":"1"}},{"ConstInt":{"value":"2"}},{"ConstInt":{"value":"3"}},{"ConstInt":{"value":"4"}}]}}],"annotations":[]}},{"NonGateInstruction":{"instruction_ref":"measure(bit array, qubit array)","name":"measure","operands":[{"VariableRef":{"variable":{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}}},{"VariableRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}}}}],"parameter":"-","annotations":[]}}]}},"variables":[{"Variable":{"name":"q","typ":{"QubitArray":{"size":"5"}},"annotations":[]}},{"Variable":{"name":"b","typ":{"BitArray":{"size":"5"}},"annotations":[]}}]}}`
console.log("\nExample 4:", program_4, "\n\tCalling analyze_string_to_json...", "\n\tOutput:", output)
if (output !== expected_output) {
console.log("\tExpected output:", expected_output)
Expand Down

0 comments on commit 060d80a

Please sign in to comment.