diff --git a/Cargo.lock b/Cargo.lock index dee434e870a4..50903b3811af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "ahash" version = "0.8.11" @@ -106,7 +117,7 @@ checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -265,7 +276,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -285,7 +296,7 @@ checksum = "60d08acb9849f7fb4401564f251be5a526829183a3645a90197dea8e786cf3ae" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -509,14 +520,17 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash", + "ahash 0.8.11", "allocator-api2", "rayon", ] @@ -550,7 +564,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "rayon", ] @@ -606,9 +620,9 @@ checksum = "8b23360e99b8717f20aaa4598f5a6541efbe30630039fbc7706cf954a87947ae" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libm" @@ -618,9 +632,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -771,9 +785,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oq3_lexer" -version = "0.0.7" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e867d2797100b8068715e26566a5567c598424d7eddf7118c6b38bc3b15633" +checksum = "0de2f0f9d48042c12f82b2550808378718627e108fc3f6adf63e02e5293541a3" dependencies = [ "unicode-properties", "unicode-xid", @@ -781,9 +795,9 @@ dependencies = [ [[package]] name = "oq3_parser" -version = "0.0.7" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf260dea71b56b405d091d476748c1f9b0a4d22b4ec9af416e002e2df25613f9" +checksum = "e69b215426a4a2a023fd62cca4436c633ba0ab39ee260aca875ac60321b3704b" dependencies = [ "drop_bomb", "oq3_lexer", @@ -792,12 +806,12 @@ dependencies = [ [[package]] name = "oq3_semantics" -version = "0.0.7" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5ba220b91ff849190d53b296711774f761b7e06744b16a9c8f19fc2fb37de47" +checksum = "3e15e9cee54e92fb1b3aaa42556b0bd76c8c1c10912a7d6798f43dfc3afdcb0d" dependencies = [ "boolenum", - "hashbrown 0.14.3", + "hashbrown 0.12.3", "oq3_source_file", "oq3_syntax", "rowan", @@ -805,9 +819,9 @@ dependencies = [ [[package]] name = "oq3_source_file" -version = "0.0.7" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a81fd0c1c100ad8d7a23711c897791d693c3f5b1f3d044cb8c5770766f819c" +checksum = "4f65243cc4807c600c544a21db6c17544c53aa2bc034b3eccf388251cc6530e7" dependencies = [ "ariadne", "oq3_syntax", @@ -815,9 +829,9 @@ dependencies = [ [[package]] name = "oq3_syntax" -version = "0.0.7" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7da2ef9a591d77eee43e972e79fc95c218545e5e79b93738d20479d8d7627ec" +checksum = "a8c3d637a7db9ddb3811719db8a466bd4960ea668df4b2d14043a1b0038465b0" dependencies = [ "cov-mark", "either", @@ -829,6 +843,7 @@ dependencies = [ "ra_ap_stdx", "rowan", "rustc-hash", + "rustversion", "smol_str", "triomphe", "xshell", @@ -836,9 +851,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", "parking_lot_core", @@ -846,15 +861,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -865,9 +880,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pest" -version = "2.7.9" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" dependencies = [ "memchr", "thiserror", @@ -876,9 +891,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.9" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" dependencies = [ "pest", "pest_generator", @@ -886,22 +901,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.9" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] name = "pest_meta" -version = "2.7.9" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" dependencies = [ "once_cell", "pest", @@ -994,7 +1009,7 @@ checksum = "d315b3197b780e4873bc0e11251cb56a33f65a6032a3d39b8d1405c255513766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1017,7 +1032,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" dependencies = [ "cfg-if", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "indexmap 2.2.6", "indoc", "libc", @@ -1062,7 +1077,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1075,18 +1090,18 @@ dependencies = [ "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] name = "qiskit-accelerate" version = "1.1.0" dependencies = [ - "ahash", + "ahash 0.8.11", "approx", "faer", "faer-ext", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "indexmap 2.2.6", "itertools 0.12.1", "ndarray", @@ -1109,7 +1124,7 @@ dependencies = [ name = "qiskit-circuit" version = "1.1.0" dependencies = [ - "hashbrown 0.14.3", + "hashbrown 0.14.5", "pyo3", ] @@ -1128,7 +1143,7 @@ dependencies = [ name = "qiskit-qasm2" version = "1.1.0" dependencies = [ - "hashbrown 0.14.3", + "hashbrown 0.14.5", "pyo3", "qiskit-circuit", ] @@ -1137,7 +1152,7 @@ dependencies = [ name = "qiskit-qasm3" version = "1.1.0" dependencies = [ - "hashbrown 0.14.3", + "hashbrown 0.14.5", "indexmap 2.2.6", "oq3_semantics", "pyo3", @@ -1275,11 +1290,11 @@ checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430" [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -1289,7 +1304,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a58fa8a7ccff2aec4f39cc45bf5f985cec7125ab271cf681c279fd00192b49" dependencies = [ "countme", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "memoffset", "rustc-hash", "text-size", @@ -1301,15 +1316,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustversion" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" + [[package]] name = "rustworkx-core" version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "529027dfaa8125aa61bb7736ae9484f41e8544f448af96918c8da6b1def7f57b" dependencies = [ - "ahash", + "ahash 0.8.11", "fixedbitset", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "indexmap 2.2.6", "num-traits", "petgraph", @@ -1343,22 +1364,22 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1400,9 +1421,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.59" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -1437,22 +1458,22 @@ checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233" [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1487,9 +1508,9 @@ checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "unicode-xid" @@ -1543,11 +1564,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -1604,21 +1625,6 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - [[package]] name = "windows-targets" version = "0.52.5" @@ -1641,12 +1647,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" @@ -1659,12 +1659,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" @@ -1677,12 +1671,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -1701,12 +1689,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" @@ -1719,12 +1701,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" @@ -1737,12 +1713,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" @@ -1755,12 +1725,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" @@ -1805,5 +1769,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] diff --git a/crates/qasm3/Cargo.toml b/crates/qasm3/Cargo.toml index a8e20d13d58c..4dd0d977786e 100644 --- a/crates/qasm3/Cargo.toml +++ b/crates/qasm3/Cargo.toml @@ -13,4 +13,4 @@ doctest = false pyo3.workspace = true indexmap.workspace = true hashbrown.workspace = true -oq3_semantics = "0.0.7" +oq3_semantics = "0.6.0" diff --git a/crates/qasm3/src/build.rs b/crates/qasm3/src/build.rs index 154cd391252a..2f817187625d 100644 --- a/crates/qasm3/src/build.rs +++ b/crates/qasm3/src/build.rs @@ -226,42 +226,32 @@ impl BuilderState { self.qc.append(py, instruction).map(|_| ()) } - fn define_gate( - &mut self, - _py: Python, - ast_symbols: &SymbolTable, - decl: &asg::GateDeclaration, - ) -> PyResult<()> { - let name_id = decl - .name() - .as_ref() - .map_err(|err| QASM3ImporterError::new_err(format!("internal error: {:?}", err)))?; - let name_symbol = &ast_symbols[name_id]; - let pygate = self.pygates.get(name_symbol.name()).ok_or_else(|| { - QASM3ImporterError::new_err(format!( - "can't handle non-built-in gate: '{}'", - name_symbol.name() - )) - })?; - let defined_num_params = decl.params().as_ref().map_or(0, Vec::len); - let defined_num_qubits = decl.qubits().len(); - if pygate.num_params() != defined_num_params { - return Err(QASM3ImporterError::new_err(format!( - "given constructor for '{}' expects {} parameters, but is defined as taking {}", - pygate.name(), - pygate.num_params(), - defined_num_params, - ))); - } - if pygate.num_qubits() != defined_num_qubits { - return Err(QASM3ImporterError::new_err(format!( - "given constructor for '{}' expects {} qubits, but is defined as taking {}", - pygate.name(), - pygate.num_qubits(), - defined_num_qubits, - ))); + // Map gates in the symbol table to Qiskit gates in the standard library. + // Encountering any gates not in the standard library results in raising an exception. + // Gates mapped via CustomGates will not raise an exception. + fn map_gate_ids(&mut self, _py: Python, ast_symbols: &SymbolTable) -> PyResult<()> { + for (name, name_id, defined_num_params, defined_num_qubits) in ast_symbols.gates() { + let pygate = self.pygates.get(name).ok_or_else(|| { + QASM3ImporterError::new_err(format!("can't handle non-built-in gate: '{}'", name)) + })?; + if pygate.num_params() != defined_num_params { + return Err(QASM3ImporterError::new_err(format!( + "given constructor for '{}' expects {} parameters, but is defined as taking {}", + pygate.name(), + pygate.num_params(), + defined_num_params, + ))); + } + if pygate.num_qubits() != defined_num_qubits { + return Err(QASM3ImporterError::new_err(format!( + "given constructor for '{}' expects {} qubits, but is defined as taking {}", + pygate.name(), + pygate.num_qubits(), + defined_num_qubits, + ))); + } + self.symbols.gates.insert(name_id.clone(), pygate.clone()); } - self.symbols.gates.insert(name_id.clone(), pygate.clone()); Ok(()) } @@ -377,37 +367,45 @@ pub fn convert_asg( pygates: gate_constructors, module, }; + + state.map_gate_ids(py, ast_symbols)?; + for statement in program.stmts().iter() { match statement { asg::Stmt::GateCall(call) => state.call_gate(py, ast_symbols, call)?, asg::Stmt::DeclareClassical(decl) => state.declare_classical(py, ast_symbols, decl)?, asg::Stmt::DeclareQuantum(decl) => state.declare_quantum(py, ast_symbols, decl)?, - asg::Stmt::GateDeclaration(decl) => state.define_gate(py, ast_symbols, decl)?, + // We ignore gate definitions because the only information we can currently use + // from them is extracted with `SymbolTable::gates` via `map_gate_ids`. + asg::Stmt::GateDefinition(_) => (), asg::Stmt::Barrier(barrier) => state.apply_barrier(py, ast_symbols, barrier)?, asg::Stmt::Assignment(assignment) => state.assign(py, ast_symbols, assignment)?, - asg::Stmt::Alias + asg::Stmt::Alias(_) | asg::Stmt::AnnotatedStmt(_) | asg::Stmt::Block(_) | asg::Stmt::Box | asg::Stmt::Break | asg::Stmt::Cal | asg::Stmt::Continue - | asg::Stmt::Def + | asg::Stmt::DeclareHardwareQubit(_) | asg::Stmt::DefCal - | asg::Stmt::Delay + | asg::Stmt::DefStmt(_) + | asg::Stmt::Delay(_) | asg::Stmt::End | asg::Stmt::ExprStmt(_) | asg::Stmt::Extern - | asg::Stmt::For + | asg::Stmt::ForStmt(_) | asg::Stmt::GPhaseCall(_) - | asg::Stmt::IODeclaration | asg::Stmt::If(_) | asg::Stmt::Include(_) + | asg::Stmt::InputDeclaration(_) + | asg::Stmt::ModifiedGPhaseCall(_) | asg::Stmt::NullStmt | asg::Stmt::OldStyleDeclaration + | asg::Stmt::OutputDeclaration(_) | asg::Stmt::Pragma(_) - | asg::Stmt::Reset - | asg::Stmt::Return + | asg::Stmt::Reset(_) + | asg::Stmt::SwitchCaseStmt(_) | asg::Stmt::While(_) => { return Err(QASM3ImporterError::new_err(format!( "this statement is not yet handled during OpenQASM 3 import: {:?}", diff --git a/crates/qasm3/src/expr.rs b/crates/qasm3/src/expr.rs index d16bd53add05..e912aecdb875 100644 --- a/crates/qasm3/src/expr.rs +++ b/crates/qasm3/src/expr.rs @@ -244,11 +244,11 @@ pub fn eval_qarg( qarg: &asg::GateOperand, ) -> PyResult { match qarg { - asg::GateOperand::Identifier(iden) => broadcast_bits_for_identifier( + asg::GateOperand::Identifier(symbol) => broadcast_bits_for_identifier( py, &our_symbols.qubits, &our_symbols.qregs, - iden.symbol().as_ref().unwrap(), + symbol.as_ref().unwrap(), ), asg::GateOperand::IndexedIdentifier(indexed) => { let iden_symbol = indexed.identifier().as_ref().unwrap();