Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
737 commits
Select commit Hold shift + click to select a range
684bc46
Cleanup test
comp-phys-marc Jun 10, 2025
1c17d2f
Test resets
comp-phys-marc Jun 10, 2025
8c204ff
Format
comp-phys-marc Jun 10, 2025
d5c4567
Remove recursion protection - now unecessary
comp-phys-marc Jun 10, 2025
a6f667b
Pass None to getattr instead of catching KeyError
comp-phys-marc Jun 10, 2025
f7e8b94
Revert suggested change
comp-phys-marc Jun 10, 2025
d0278a6
Format, paths for CI
comp-phys-marc Jun 11, 2025
3d20119
Merge branch 'feature/subroutines' into feature/control-flow
comp-phys-marc Jun 11, 2025
c22a6c6
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 11, 2025
3e27f82
format
comp-phys-marc Jun 11, 2025
2774bcf
Remove outer_wires, outer_scopes
comp-phys-marc Jun 11, 2025
3851b2b
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 11, 2025
6dc1c9e
Test measurement outside of subroutine
comp-phys-marc Jun 11, 2025
b2983d5
Inputs
comp-phys-marc Jun 11, 2025
d80a23b
Create PR
comp-phys-marc Jun 11, 2025
323be18
Update docstring
comp-phys-marc Jun 11, 2025
9131bfa
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jun 11, 2025
1b2ac89
Update docstring
comp-phys-marc Jun 11, 2025
408f3af
Test naming
comp-phys-marc Jun 11, 2025
7a844a1
Ouptuts
comp-phys-marc Jun 11, 2025
964f16d
Update docs
comp-phys-marc Jun 11, 2025
119f8d3
Return outputs from from_qasm3
comp-phys-marc Jun 11, 2025
a4511ca
Minor fixes
comp-phys-marc Jun 11, 2025
f0a53f8
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 11, 2025
4aa6701
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jun 11, 2025
ef5292d
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jun 11, 2025
858d82a
Minor cleanup
comp-phys-marc Jun 11, 2025
6c53100
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 11, 2025
802ecf9
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jun 11, 2025
87cdbff
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jun 11, 2025
5b6ed05
Repeated calls test
comp-phys-marc Jun 11, 2025
fe671b1
Test passing
comp-phys-marc Jun 11, 2025
d9fdab3
format
comp-phys-marc Jun 11, 2025
bab7814
Merge branch 'feature/subroutines' into feature/control-flow
comp-phys-marc Jun 11, 2025
d91c081
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 11, 2025
2b83310
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jun 11, 2025
4dd6d04
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jun 11, 2025
82f4eee
replace else if with wlif
comp-phys-marc Jun 11, 2025
268eabb
Trigger CI
comp-phys-marc Jun 11, 2025
a4e2f12
Merge remote-tracking branch 'origin/feature/subroutines' into featur…
comp-phys-marc Jun 11, 2025
cf419af
Init wire map on call and test
comp-phys-marc Jun 11, 2025
b61e01d
path for CI
comp-phys-marc Jun 11, 2025
727a1c1
Reset return
comp-phys-marc Jun 11, 2025
741037e
Stylistic change
comp-phys-marc Jun 11, 2025
68c899d
Resolve wire renamings in outer contexts before new calls
comp-phys-marc Jun 11, 2025
400fd35
Merge remote-tracking branch 'origin/feature/subroutines' into featur…
comp-phys-marc Jun 11, 2025
be4c009
Could get a collision with the first call
comp-phys-marc Jun 11, 2025
51caaa7
Merge branch 'master' into feature/subroutines
comp-phys-marc Jun 11, 2025
712ee90
Merge branch 'feature/subroutines' into feature/control-flow
comp-phys-marc Jun 11, 2025
27f9570
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 11, 2025
52a5624
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jun 11, 2025
4c224ed
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jun 11, 2025
6f292b0
Minor feedback
comp-phys-marc Jun 13, 2025
36d20fd
Format
comp-phys-marc Jun 13, 2025
2eae3b6
Avoid pointless lookup
comp-phys-marc Jun 13, 2025
37d4aa5
Merge branch 'feature/subroutines' into feature/control-flow
comp-phys-marc Jun 13, 2025
d4d2024
Basic custom gates
comp-phys-marc Jun 13, 2025
1823bb6
Call a gate within a gate
comp-phys-marc Jun 13, 2025
70488b3
Format
comp-phys-marc Jun 13, 2025
128f9b6
Docs
comp-phys-marc Jun 13, 2025
069e1eb
Built-in constants
comp-phys-marc Jun 13, 2025
3d15137
Format
comp-phys-marc Jun 13, 2025
1b0d3d9
Improve test coverage
comp-phys-marc Jun 13, 2025
f7d8f2e
Handle set declarations and try to simplify loop iterators
comp-phys-marc Jun 13, 2025
999e24a
Format, cleanup
comp-phys-marc Jun 13, 2025
f5b9886
Built in functions
comp-phys-marc Jun 13, 2025
e69c649
Docs
comp-phys-marc Jun 13, 2025
0f5f797
Update changelog
comp-phys-marc Jun 13, 2025
f133db4
Cleanup
comp-phys-marc Jun 13, 2025
4b48978
pylint
comp-phys-marc Jun 13, 2025
a623bfc
Docs
comp-phys-marc Jun 13, 2025
465134c
Paths for CI
comp-phys-marc Jun 13, 2025
ce60304
Format
comp-phys-marc Jun 13, 2025
979dbce
Control on true rather than false case
comp-phys-marc Jun 13, 2025
839d451
Fix indentation from suggested change
comp-phys-marc Jun 13, 2025
74f675d
Add sdg, tdg, CU gates
comp-phys-marc Jun 16, 2025
b91e312
Control on true rather than false case
comp-phys-marc Jun 16, 2025
a63117c
Handle scoping of constants
comp-phys-marc Jun 16, 2025
7dfafa7
Test SDG, TDG, CU
comp-phys-marc Jun 16, 2025
e8ca87a
Update docs
comp-phys-marc Jun 16, 2025
5367de9
Format
comp-phys-marc Jun 16, 2025
414bce9
Create PR
comp-phys-marc Jun 16, 2025
e6c05a8
Test CU
comp-phys-marc Jun 16, 2025
73af8dc
Add resource params
comp-phys-marc Jun 16, 2025
a4a8379
Use ctrl and GlobalPhase instead of new fundamental gate
comp-phys-marc Jun 16, 2025
431ed0e
Merge branch 'feature/subroutines' into feature/control-flow
comp-phys-marc Jun 16, 2025
100d7f7
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 16, 2025
fe42a88
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jun 16, 2025
5cbb792
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jun 16, 2025
a09194b
Merge branch 'feature/outputs' into feature/custom-gates
comp-phys-marc Jun 16, 2025
21d9bb8
Merge branch 'feature/custom-gates' into feature/built-in-constants
comp-phys-marc Jun 16, 2025
130eef8
Merge branch 'feature/built-in-constants' into feature/built-in-funct…
comp-phys-marc Jun 16, 2025
ffb4a61
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jun 16, 2025
aa04138
pylint
comp-phys-marc Jun 16, 2025
b2cae8c
Debug unrelated test failing in CI
comp-phys-marc Jun 16, 2025
dfeb535
Unecessary partial use
comp-phys-marc Jun 16, 2025
a970daa
Remove erroneous lines in suggested change
comp-phys-marc Jun 16, 2025
237f039
Format
comp-phys-marc Jun 16, 2025
7e871e5
Debug failing docs build in CI
comp-phys-marc Jun 16, 2025
aa0af14
More formal wording in docstring.
comp-phys-marc Jun 16, 2025
97a9ec7
More formal wording in docstring.
comp-phys-marc Jun 16, 2025
5e1b0e1
More formal wording in docstring.
comp-phys-marc Jun 16, 2025
5adb8ea
Refactor import for brevity
comp-phys-marc Jun 17, 2025
6440669
Merge remote-tracking branch 'origin/feature/control-flow' into featu…
comp-phys-marc Jun 17, 2025
32d5977
Format
comp-phys-marc Jun 17, 2025
b337dba
Remove ast. prefix from docstrings
comp-phys-marc Jun 17, 2025
7eecdb4
PR feedback
comp-phys-marc Jun 17, 2025
157615f
Raise using MCM as while condition
comp-phys-marc Jun 17, 2025
5961d8d
pylint
comp-phys-marc Jun 17, 2025
4527a58
Trigger CI
comp-phys-marc Jun 17, 2025
71a6090
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 17, 2025
651d385
Paths for CI
comp-phys-marc Jun 17, 2025
c12faba
format
comp-phys-marc Jun 17, 2025
80cbade
Clean up tests
comp-phys-marc Jun 17, 2025
5d59b6d
Mudit's feedback
comp-phys-marc Jun 17, 2025
e3be2b2
Test of nested control flow
comp-phys-marc Jun 17, 2025
bf16181
Add empty newline at end of file
comp-phys-marc Jun 17, 2025
e796806
Add empty newline at end of file
comp-phys-marc Jun 17, 2025
31d6a92
Add empty newline at end of file
comp-phys-marc Jun 17, 2025
d28cb73
Update docstring
comp-phys-marc Jun 18, 2025
9b84812
Newline at end of file
comp-phys-marc Jun 18, 2025
ed41fbc
Test _rotate, support conversion of int vars
comp-phys-marc Jun 18, 2025
44dd9f8
Path for CI
comp-phys-marc Jun 18, 2025
adda770
Add newlines to ends of .qasm files
comp-phys-marc Jun 18, 2025
3b0bab8
Typo in comment
comp-phys-marc Jun 18, 2025
c3ebd93
Reword docstring
comp-phys-marc Jun 18, 2025
57e8c81
Tighten type hint on unary operands
comp-phys-marc Jun 18, 2025
1c41686
Merge remote-tracking branch 'origin/feature/measurement' into featur…
comp-phys-marc Jun 18, 2025
796bb31
Revert type hint change
comp-phys-marc Jun 18, 2025
2d9a177
Update test
comp-phys-marc Jun 18, 2025
5e7d80a
Merge branch 'master' into feature/control-flow
comp-phys-marc Jun 18, 2025
20e4e4b
Merge remote-tracking branch 'origin/feature/control-flow' into featu…
comp-phys-marc Jun 18, 2025
263f129
Improve type hints
comp-phys-marc Jun 18, 2025
838da90
Codefactor
comp-phys-marc Jun 18, 2025
ef17074
Codefactor
comp-phys-marc Jun 18, 2025
59044a1
format
comp-phys-marc Jun 18, 2025
57673a8
Simplify loops scopes
comp-phys-marc Jun 18, 2025
25eb22e
Oops I over simplified
comp-phys-marc Jun 18, 2025
0edf61f
Simplify by removing unecessary block scopes
comp-phys-marc Jun 18, 2025
d322e21
Paths for CI
comp-phys-marc Jun 18, 2025
a9cc3db
format
comp-phys-marc Jun 18, 2025
8ab4f95
__getitem__ no longer necessary or helpful
comp-phys-marc Jun 18, 2025
c6ed0a2
Simplify 3 lines -> 1 line
comp-phys-marc Jun 21, 2025
bd341b3
Rename _handle_break -> execute_loop
comp-phys-marc Jun 21, 2025
93ec021
Trigger CI
comp-phys-marc Jun 21, 2025
b140f19
Trigger CI
comp-phys-marc Jun 23, 2025
ca527ea
Merge remote-tracking branch 'origin/feature/control-flow' into featu…
comp-phys-marc Jun 23, 2025
b4641d1
Merge branch 'master' into feature/control-flow
comp-phys-marc Jun 23, 2025
f1acac2
Merge branch 'master' into feature/control-flow
comp-phys-marc Jun 23, 2025
8c56393
Merge branch 'feature/control-flow' into feature/measurement
comp-phys-marc Jun 23, 2025
0e27170
Allow subscripting of Context - helpful now
comp-phys-marc Jun 23, 2025
1b11f54
Merge branch 'master' into feature/measurement
comp-phys-marc Jun 23, 2025
e2208d3
PR feedback
comp-phys-marc Jun 30, 2025
90cb251
Merge branch 'master' into feature/measurement
comp-phys-marc Jun 30, 2025
403d316
Add PR to changelog
comp-phys-marc Jun 30, 2025
747f7b0
Support for qubit registers
comp-phys-marc Jun 30, 2025
4b366ee
PR feedback
comp-phys-marc Jun 30, 2025
e8a29ec
Add test for index out of range
comp-phys-marc Jul 2, 2025
6bcb33f
Test nested renaming of registers
comp-phys-marc Jul 2, 2025
f1442e3
Fix namespace leakage bug
comp-phys-marc Jul 2, 2025
a78c591
pylint
comp-phys-marc Jul 2, 2025
0d3bd07
pylint
comp-phys-marc Jul 2, 2025
48e30e4
Trigger CI
comp-phys-marc Jul 2, 2025
993d203
Merge branch 'feature/measurement' into feature/inputs
comp-phys-marc Jul 2, 2025
9b697f3
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jul 2, 2025
83779bd
Merge branch 'feature/outputs' into feature/custom-gates
comp-phys-marc Jul 2, 2025
2f53567
Merge branch 'feature/custom-gates' into feature/built-in-constants
comp-phys-marc Jul 2, 2025
1065e69
Merge branch 'feature/built-in-constants' into feature/built-in-funct…
comp-phys-marc Jul 2, 2025
d981c29
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 2, 2025
ddb45aa
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 2, 2025
b6fdea1
typo
comp-phys-marc Jul 2, 2025
b07685f
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 2, 2025
7f33036
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 2, 2025
fc16326
typo
comp-phys-marc Jul 2, 2025
573f158
pylint
comp-phys-marc Jul 3, 2025
9706dff
Merge branch 'master' into feature/inputs
comp-phys-marc Jul 3, 2025
c0b0f05
Raise if too many / incorrect params are passed
comp-phys-marc Jul 3, 2025
70ede3d
Docs
comp-phys-marc Jul 3, 2025
b4b275a
scope name
comp-phys-marc Jul 3, 2025
98f6735
pylint
comp-phys-marc Jul 4, 2025
216187e
Stylistic reordering of clauses
comp-phys-marc Jul 4, 2025
540a63a
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jul 4, 2025
4ef4973
Merge branch 'feature/outputs' into feature/custom-gates
comp-phys-marc Jul 4, 2025
fdd9f9f
Remove unecessary methods
comp-phys-marc Jul 4, 2025
94fc9bd
Format
comp-phys-marc Jul 4, 2025
9686960
Merge branch 'feature/custom-gates' into feature/built-in-constants
comp-phys-marc Jul 4, 2025
3d2f01c
Merge branch 'feature/built-in-constants' into feature/built-in-funct…
comp-phys-marc Jul 4, 2025
9f25d2b
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 4, 2025
7d4b37a
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 4, 2025
ec503ad
Add to changelog
comp-phys-marc Jul 7, 2025
362c835
Cleanup merge
comp-phys-marc Jul 7, 2025
65397de
Pylint
comp-phys-marc Jul 9, 2025
8c566f9
Pylint
comp-phys-marc Jul 9, 2025
4791e4d
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 9, 2025
0034192
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 9, 2025
3adcb3f
Pylint
comp-phys-marc Jul 9, 2025
8f817af
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 9, 2025
6d899e1
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 9, 2025
eaa85a2
Merge branch 'master' into feature/inputs
comp-phys-marc Jul 10, 2025
582ea90
Cleanup merge
comp-phys-marc Jul 10, 2025
aee090b
Merge branch 'feature/inputs' into feature/outputs
comp-phys-marc Jul 10, 2025
9b75faa
Format
comp-phys-marc Jul 10, 2025
4be5a26
Update test
comp-phys-marc Jul 10, 2025
1fb144c
Merge branch 'feature/outputs' into feature/custom-gates
comp-phys-marc Jul 10, 2025
001e28e
Merge branch 'feature/custom-gates' into feature/built-in-constants
comp-phys-marc Jul 10, 2025
9955c6f
Merge branch 'feature/built-in-constants' into feature/built-in-funct…
comp-phys-marc Jul 10, 2025
b8fc493
Test _get_bit_type_val
comp-phys-marc Jul 10, 2025
51acdef
Improve coverage
comp-phys-marc Jul 10, 2025
ce8c999
Typo
comp-phys-marc Jul 10, 2025
63d20e3
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 10, 2025
39bb0ee
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 10, 2025
784cb61
Improve coverage
comp-phys-marc Jul 10, 2025
e48da2e
Merge branch 'feature/built-in-functions' into feature/dagger-gates
comp-phys-marc Jul 10, 2025
32a99fc
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 10, 2025
6901409
Changelog
comp-phys-marc Jul 10, 2025
d3acad2
Improve coverage
comp-phys-marc Jul 10, 2025
6453e6e
pylint
comp-phys-marc Jul 10, 2025
cbc8b78
Merge branch 'master' into feature/dagger-gates
comp-phys-marc Jul 16, 2025
67fd665
cleanup merge
comp-phys-marc Jul 16, 2025
c155315
Cleanup merge
comp-phys-marc Jul 16, 2025
17ba068
PR Feeedback
comp-phys-marc Jul 16, 2025
cc81ca8
Abstract quantum paramter binding
comp-phys-marc Jul 17, 2025
480303f
Handle index out of bounds
comp-phys-marc Jul 17, 2025
5d840cb
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 17, 2025
f8bcd33
Remove redundant test
comp-phys-marc Jul 17, 2025
0d9c514
Account for vars
comp-phys-marc Jul 18, 2025
182cfc5
Consistency of function call and custom gate behaviour
comp-phys-marc Jul 18, 2025
fcd52c4
Replace ctrl globalphase with phaseshift
comp-phys-marc Jul 18, 2025
f7f0cb9
args, kwargs implicit
comp-phys-marc Jul 18, 2025
10a7190
Debug suggested changes
comp-phys-marc Jul 18, 2025
aeb8eea
EOF newline
comp-phys-marc Jul 18, 2025
34c658e
PR feedback
comp-phys-marc Jul 18, 2025
9cf7e8e
Merge remote-tracking branch 'origin/feature/qubit-registers' into fe…
comp-phys-marc Jul 18, 2025
c7240c4
Stylistic reordering of branches for readability
comp-phys-marc Jul 18, 2025
c513f04
Replace globalphase with phaseshift
comp-phys-marc Jul 18, 2025
77401c8
Update test
comp-phys-marc Jul 18, 2025
e9ffd62
pylint
comp-phys-marc Jul 18, 2025
dc4aebe
Merge remote-tracking branch 'origin/feature/qubit-registers' into fe…
comp-phys-marc Jul 18, 2025
a3934bf
Changelog
comp-phys-marc Jul 18, 2025
854fd5c
Merge branch 'feature/dagger-gates' into feature/qubit-registers
comp-phys-marc Jul 18, 2025
6283861
Changelog
comp-phys-marc Jul 18, 2025
48144bc
Update docstring
comp-phys-marc Jul 18, 2025
dbd910a
Merge branch 'master' into feature/qubit-registers
comp-phys-marc Jul 21, 2025
c044532
Stylistic loop refactor
comp-phys-marc Jul 21, 2025
ed4a13b
Merge branch 'master' into feature/qubit-registers
comp-phys-marc Jul 21, 2025
7ee3536
Merge branch 'master' into feature/qubit-registers
comp-phys-marc Jul 21, 2025
a094b97
Merge branch 'master' into feature/qubit-registers
comp-phys-marc Jul 21, 2025
5ea2c5f
Merge remote-tracking branch 'origin/feature/qubit-registers' into fe…
comp-phys-marc Jul 21, 2025
d5c7b81
Merge branch 'master' into feature/qubit-registers
comp-phys-marc Jul 21, 2025
b940caa
Cleanup GitHub's merge
comp-phys-marc Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
<h4>OpenQASM-PennyLane interoperability</h4>

* The :func:`qml.from_qasm3` function can now convert OpenQASM 3.0 circuits that contain
subroutines, constants, all remaining stdlib gates, and built-in mathematical functions.
subroutines, constants, all remaining stdlib gates, qubit registers, and built-in mathematical functions.
[(#7651)](https://github.com/PennyLaneAI/pennylane/pull/7651)
[(#7653)](https://github.com/PennyLaneAI/pennylane/pull/7653)
[(#7676)](https://github.com/PennyLaneAI/pennylane/pull/7676)
[(#7679)](https://github.com/PennyLaneAI/pennylane/pull/7679)
[(#7677)](https://github.com/PennyLaneAI/pennylane/pull/7677)
[(#7767)](https://github.com/PennyLaneAI/pennylane/pull/7767)
[(#7690)](https://github.com/PennyLaneAI/pennylane/pull/7690)

<h4>Other improvements</h4>
Expand Down
4 changes: 2 additions & 2 deletions pennylane/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ def from_qasm3(quantum_circuit: str, wire_map: dict = None):
Converts an OpenQASM 3.0 circuit into a quantum function that can be used within a QNode.

.. note::
The standard library gates, built-in mathematical functions and constants, subroutines, variables,
control flow, measurements, inputs, outputs, custom gates and ``end`` statements are all supported.
The standard library gates, qubit registers, built-in mathematical functions and constants, subroutines,
variables, control flow, measurements, inputs, outputs, custom gates and ``end`` statements are all supported.
Pulses are not yet supported.

In order to use this function, ``openqasm3`` and ``'openqasm3[parser]'`` must be installed in the user's
Expand Down
120 changes: 94 additions & 26 deletions pennylane/io/qasm_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ def __init__(self, context: dict):
context["aliases"] = {}
if "wires" not in context:
context["wires"] = []
if "registers" not in context:
context["registers"] = {}
if "scopes" not in context:
context["scopes"] = {"subroutines": {}, "custom_gates": {}}
if "wire_map" not in context or context["wire_map"] is None:
Expand All @@ -300,6 +302,7 @@ def init_custom_gate_scope(self, node: ast.QuantumGateDefinition):
"params": [_resolve_name(param) for param in node.arguments]
+ [_resolve_name(qubit) for qubit in node.qubits],
"wires": copy.deepcopy(self.wires),
"registers": copy.deepcopy(self.registers),
"name": node.name.name,
# we want subroutines declared in the global scope to be available
"scopes": {
Expand All @@ -323,6 +326,7 @@ def init_subroutine_scope(self, node: ast.SubroutineDefinition):
"vars": {k: v for k, v in self.vars.items() if v.constant}, # same namespace
"wire_map": {},
"wires": copy.deepcopy(self.wires),
"registers": copy.deepcopy(self.registers),
"name": node.name.name,
# we want subroutines declared in the global scope to be available
"scopes": {
Expand Down Expand Up @@ -354,6 +358,8 @@ def retrieve_variable(self, name: str):
if res.val is not None:
return res
raise ValueError(f"Attempt to reference uninitialized parameter {name}!")
if name in self.registers:
return self.registers[name]
if name in self.wires:
return name
if name in self.aliases:
Expand Down Expand Up @@ -393,7 +399,7 @@ def require_wires(self, wires: list):
Raises:
NameError: If the context is missing a wire.
"""
missing_wires = set(wires) - set(self.wires)
missing_wires = set(wires) - (set(self.wires + list(self.registers)))
if len(missing_wires) > 0:
raise NameError(
f"Attempt to reference wire(s): {missing_wires} that have not been declared in {self.name}"
Expand Down Expand Up @@ -596,8 +602,11 @@ def visit_quantum_measurement_statement(
node (QuantumMeasurementStatement): the quantum measurement statement to register.
context (Context): the current context.
"""
wire = self.visit(node.measure.qubit, context)
res = measure(context.wire_map.get(wire, wire))
wires = self.visit(node.measure.qubit, context)
if isinstance(wires, list):
res = [measure(context.wire_map.get(wire, wire)) for wire in wires]
else:
res = measure(context.wire_map.get(wires, wires))
if node.target is not None:
name = _resolve_name(node.target) # str or Identifier
context.vars[name].val = res
Expand Down Expand Up @@ -829,8 +838,33 @@ def visit_quantum_reset(self, node: QASMNode, context: dict):
node (QASMNode): the quantum reset node.
context (dict): the current context.
"""
wire = self.visit(node.qubits, context)
measure(context.wire_map.get(wire, wire), reset=True)
wires = self.visit(node.qubits, context)
if isinstance(wires, list):
for wire in wires:
measure(context.wire_map.get(wire, wire), reset=True)
else:
measure(context.wire_map.get(wires, wires), reset=True)

@staticmethod
def _bind_quantum_parameter(param, evald_arg, inner_context, context):
"""
Binds a quantum parameter in a subroutine or custom gate context.

Args:
param (str): the name of the quantum parameter to bind.
evald_arg (str): the name of the qubit.
inner_context (Context): the custom gate or subroutine context.
context (Context): the outer context.
"""
reg = False
if evald_arg in context.registers:
reg = True
del inner_context.wires[inner_context.wires.index(param)]
inner_context.registers[param] = context.registers[evald_arg]
elif evald_arg in context.wire_map:
evald_arg = context.wire_map[evald_arg]
if param != evald_arg and not reg:
inner_context.wire_map[param] = evald_arg

def execute_custom_gate(self, node: ast.QuantumGate, context: Context):
"""
Expand All @@ -853,10 +887,7 @@ def execute_custom_gate(self, node: ast.QuantumGate, context: Context):
evald_arg.__class__.__name__, evald_arg, None, node.span.start_line, False
)
else:
if evald_arg in context.wire_map:
evald_arg = context.wire_map[evald_arg]
if param != evald_arg:
gate_context.wire_map[param] = evald_arg
self._bind_quantum_parameter(param, evald_arg, gate_context, context)

# execute the subroutine
self.visit(gate_context.body, gate_context)
Expand Down Expand Up @@ -885,13 +916,20 @@ def _execute_function(self, name: str, node: FunctionCall, context: Context):
func_context.context["return"] = None

# bind subroutine arguments
evald_args = [self.visit(raw_arg, context) for raw_arg in node.arguments]
evald_args = [
# visit will resolve a qubit name to itself, but a register name to a list of its member qubits,
# we don't want to dereference yet... to behave consistently with execute_custom_gate
(
_resolve_name(raw_arg)
if isinstance(raw_arg, (str, ast.Identifier))
and _resolve_name(raw_arg) in context.registers
else self.visit(raw_arg, context)
)
for raw_arg in node.arguments
]
for evald_arg, param in list(zip(evald_args, func_context.params)):
if isinstance(evald_arg, str): # this would indicate a quantum parameter
if evald_arg in context.wire_map:
evald_arg = context.wire_map[evald_arg]
if evald_arg != param:
func_context.wire_map[param] = evald_arg
self._bind_quantum_parameter(param, evald_arg, func_context, context)
else:
func_context.vars[param] = Variable(
evald_arg.__class__.__name__,
Expand Down Expand Up @@ -1043,11 +1081,13 @@ def visit_qubit_declaration(self, node: ast.QubitDeclaration, context: Context):
Raises:
TypeError: if it is a qubit register declaration.
"""
if node.size is not None:
raise TypeError(
"Qubit registers are not yet supported, please declare each qubit individually."
)
context.wires.append(node.qubit.name)
if node.size is not None and isinstance(self.visit(node.size, context), int):
context.registers[node.qubit.name] = []
for i in range(self.visit(node.size, context)):
context.wires.append(f"{node.qubit.name}[{i}]")
context.registers[node.qubit.name].append(f"{node.qubit.name}[{i}]")
else:
context.wires.append(node.qubit.name)

@visit.register(ast.ClassicalAssignment)
def visit_classical_assignment(self, node: ast.ClassicalAssignment, context: Context):
Expand Down Expand Up @@ -1281,15 +1321,43 @@ def _gate_setup_helper(self, node: ast.QuantumGate, gates_dict: dict, context: C
gate = gates_dict[node.name.name.upper()]

# setup wires
wires = [_resolve_name(node.qubits[q]) for q in range(len(node.qubits))]

context.require_wires(wires)
wires = []
require_wires = []
for qubit in node.qubits:
if (not hasattr(qubit, "indices")) or qubit.indices is None:
# we are dealing with a wire label directly
wire = _resolve_name(qubit)
# require the qubit to have been declared
require_wires.append(wire)
# resolve any wire relabelling (mapping pennylane wires to qasm wires, or renaming between func contexts)
wires.append(context.wire_map[wire] if wire in context.wire_map else wire)
elif len(qubit.indices) == 1 and len(qubit.indices[0]) == 1:
# we are dealing with an index into a register
register = _resolve_name(qubit)
# required the register to have been declared
require_wires.append(register)
# evaluate the register to a list of the qubits that compose it
reg_var = context.retrieve_variable(register)
# evaluate the index into the register to a literal
index = self.visit(qubit.indices[0][0], context)
# check that the index is not out of bounds
if index < len(reg_var):
# index into the register and return the wire acted on
wires.append(reg_var[index])
else:
raise IndexError(
f"Index {index} into register {register} of length {len(reg_var)} out of bounds on line {node.span.start_line}."
)
else:
raise (
NotImplementedError(
"Only a single Expression or Index is supported for indexing into registers."
)
)

resolved_wires = list(
map(lambda wire: context.wire_map[wire] if wire in context.wire_map else wire, wires)
)
context.require_wires(require_wires)

return gate, args, resolved_wires
return gate, args, wires

def apply_modifier(
self, mod: ast.QuantumGate, previous: Operator, context: Context, wires: list
Expand Down
7 changes: 7 additions & 0 deletions tests/io/qasm_interpreter/complex_subroutines.qasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
qubit q0;
qubit anc;
qubit[2] p;

def second(qubit q) {
h q;
Expand All @@ -20,4 +21,10 @@ def third(qubit q, float a) {
rx(a) q;
}

def fourth(qubit[2] p) {
x p[0];
y p[1];
}

third(q0, 0.1);
fourth(p);
8 changes: 8 additions & 0 deletions tests/io/qasm_interpreter/custom_gates.qasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
qubit q0;
qubit q1;
qubit[2] p;

const float pi = 3.14159;

Expand All @@ -17,4 +18,11 @@ gate custom_two(θ) c, d
x d;
}

gate custom_three f
{
x f[0];
y f[1];
}

custom_two(pi) q1, q0;
custom_three p;
22 changes: 20 additions & 2 deletions tests/io/qasm_interpreter/nested_renaming.qasm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qubit q0;
qubit[1] q;

def f3(qubit q2) {
h q2;
Expand All @@ -14,4 +14,22 @@ def f1(qubit q1) {
f2(q1);
}

f1(q0);
f1(q[0]);

qubit[2] p;

def l3(qubit[2] p2) {
h p2[1];
}

def l2(qubit[2] p2) {
x p2[0];
l3(p2);
}

def l1(qubit[2] p1) {
y p1[1];
l2(p1);
}

l1(p);
11 changes: 5 additions & 6 deletions tests/io/qasm_interpreter/resets.qasm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
qubit q;
reset q;
qubit[10] q;

def reset_and_measure(qubit p) -> bit {
bit b = "0";
reset p;
measure p -> b;
def reset_and_measure(qubit[10] q) -> bit {
bit b = "0000000000";
reset q;
measure q -> b;
return b;
}

Expand Down
Loading
Loading