isi-usc-edu / pyLIQTR

Lincoln Laboratory Quantum Algorithm Test and Research
https://isi-usc-edu.github.io/pyLIQTR/
MIT License
26 stars 6 forks source link

Fix quadratic scaling in circuit printing #3

Closed zmorrell closed 1 year ago

zmorrell commented 1 year ago

The current version of the qasm printing helper function has a quadratic scaling because it is iterating over the circuit every time an operation is called. By instead storing the operations as a list at the beginning of the function, this allows for instantaneous lookup while retaining the same functionality.

This is largely untested as a fix beyond viewing the file size and structure of the files, so please exercise caution before merging. The output from the circuit generators seems to be non-deterministic and when I tried reading the file into cirq by reading the file and translating the string to cirq, I get an error QasmException: Unknown gate "reset" at line 7. I tried finding a built in circuit reader in case I was making a mistake, but couldn't find one.

jbelarge commented 1 year ago

Good fix, thank you for the PR. We tested internally for a number of cases and it looks to generate the same output as our old version.