QuTech-Delft / OpenQL

OpenQL: A Portable Quantum Programming Framework for Quantum Accelerators. https://dl.acm.org/doi/10.1145/3474222
https://openql.readthedocs.io
Other
97 stars 44 forks source link

Review qubit operand separation in strings in old style configuration files #444

Open jvansomeren opened 2 years ago

jvansomeren commented 2 years ago

In old style configuration files in the instruction and decomposition sections keys (and decompositions) contain gates with operands. Those operands are identifiers such as q0, %0, etc. In those keys and decomposition sections, those operands are separated by a single comma optionally with spaces around them (that is the way that OpenQL accepts those rules). But when those commas are omitted and only white space separates those operands, OpenQL cannot match those keys with actual gates with operands and/or when in decomposition rules operand separation no commas are used, the generated gates cannot be matched with instruction and decomposition rule keys. The end-effect is that particular gates are not decomposed and end up in the resulting qasm or at the entry of the code-generator. Examples have been seen of such behavior with cnot and swap gates (because these are the ones that occur often and need decomposition, also because swap decomposes to cnots).

Exactly which absence of commas is accepted and which result in non-matching has not been investigated yet. What has been done, is a consistent replacement of sole white space by commas, which worked out well.

So the following are suspect in the decomposition section:

And in the instructions section:

What needs to be done:

jvansomeren commented 2 years ago

Part of the problem is existing practice: some json files for cc and for diamond use a space as separator in the key in the gate_decomposition section and/or in the sub instructions. Are the following used:

Nowhere in the code is checked when reading a json file what is the case. Only some sanitation is done: removal of redundant spacing. Resulting keys are accepted and stored in the instruction_map. When finding keys on gate creation in the instruction_map, a comma without spacing is required, hence those finds fail.

wvlothuizen commented 2 years ago

The documentation is quite clear that the operands should be a comma separated list:

The spaces as operand separator are probably a hangover of https://github.com/QuTech-Delft/OpenQL/pull/214 (Jan 2019), and were already unsupported in https://github.com/DiCarloLab-Delft/OpenQL/blob/0.8.1.dev4/src/hardware_configuration.h#L157 (which is the version that now still runs on QI)

For reference, the extra check should be built into:

jvansomeren commented 2 years ago

The gate_decomposition section only specifies commas in an example, not in the text. So the documentation text should be updated as well.

Conclusion for the interfacing to PycQED: standardizing on a comma optionally surrounded by spacing as separator of qubit operands in keys in instruction and decomposition sections and in decompositions is ok. All spacing that we see is either old stuff already repaired in updates to come or backward compatibility that can be deleted.

Op 4 apr. 2022, om 10:08 heeft Wouter Vlothuizen @.**@.>> het volgende geschreven:

The documentation is quite clear that the operands should be a comma separated list:

The spaces as operand separator are probably a hangover of #214https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_QuTech-2DDelft_OpenQL_pull_214&d=DwMCaQ&c=XYzUhXBD2cD-CornpT4QE19xOJBbRy-TBPLK0X9U2o8&r=kNdT9ewT6pQdYFkBLR_5-ZqsrSTk7k5Hdd7MSC_Vnzg&m=yLJPbNMkLnhiQ3OfcVKuJFzyPxqja2qhbc4H7ffd1Fk&s=ieNMUUCQc2_BBzdFszUrKMUSNxDudPAZfmYG8KNVHMc&e= (Jan 2019), and were already unsupported in https://github.com/DiCarloLab-Delft/OpenQL/blob/0.8.1.dev4/src/hardware_configuration.h#L157https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_DiCarloLab-2DDelft_OpenQL_blob_0.8.1.dev4_src_hardware-5Fconfiguration.h-23L157&d=DwMCaQ&c=XYzUhXBD2cD-CornpT4QE19xOJBbRy-TBPLK0X9U2o8&r=kNdT9ewT6pQdYFkBLR_5-ZqsrSTk7k5Hdd7MSC_Vnzg&m=yLJPbNMkLnhiQ3OfcVKuJFzyPxqja2qhbc4H7ffd1Fk&s=QBRkFfqgyGbfUXgrLXHmxYs227DvHN62pD32ay7_Fb4&e= (which is the version that now still runs on QI)

For reference, the extra check should be built into:

— Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_QuTech-2DDelft_OpenQL_issues_444-23issuecomment-2D1087243967&d=DwMCaQ&c=XYzUhXBD2cD-CornpT4QE19xOJBbRy-TBPLK0X9U2o8&r=kNdT9ewT6pQdYFkBLR_5-ZqsrSTk7k5Hdd7MSC_Vnzg&m=yLJPbNMkLnhiQ3OfcVKuJFzyPxqja2qhbc4H7ffd1Fk&s=7MfV95ccDM4B4G_m3AWUJqhH_w-ebAfcJjpiHcOiDlU&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AEDTBNWNFB5BHS6HZSBZA4DVDKPPLANCNFSM5SKVWI7Q&d=DwMCaQ&c=XYzUhXBD2cD-CornpT4QE19xOJBbRy-TBPLK0X9U2o8&r=kNdT9ewT6pQdYFkBLR_5-ZqsrSTk7k5Hdd7MSC_Vnzg&m=yLJPbNMkLnhiQ3OfcVKuJFzyPxqja2qhbc4H7ffd1Fk&s=1OWJwHbi4sn0g2lRGDfXqVXMKaTfBdxTH6n7E0VqueU&e=. You are receiving this because you authored the thread.Message ID: @.***>