Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate pyqir.SimpleModule as return type instead of pyqir.Module #187

Open
ryanhill1 opened this issue Dec 5, 2024 · 0 comments
Open
Labels
discussion Needs further discussion enhancement New feature or request pyqir Interfacing with QIR python bindings

Comments

@ryanhill1
Copy link
Member

In our functions cirq_to_qir and qasm3_to_qir, we currently return a pyqir.Module, which takes a "context" of type pyqir.Context and a "name" of type str. However, it might be worth considering whether we should return a pyqir.SimpleModule instead.

The pyqir.SimpleModule accepts a "context" object and "name," but it also requires an integer number of qubits, an integer number of results, and an optional entrypoint name (which defaults to "main"). Unlike pyqir.SimpleModule, the pyqir.Module does not store any entrypoint name. The qiskit_qir.to_qir_module() function returns a list of tuples containing entrypoint name strings and pyqir.Module objects. However, they could have instead just return a list of pyqir.SimpleModule objects, each of which would already have a .entry_point property.

Through our Cirq and OpenQASM 3 to QIR conversions, we can easily derive the values needed for the additional fields required to create a pyqir.SimpleModule. Furthermore, all the examples I’ve encountered (e.g., the pyqir README) indicate that pyqir.SimpleModule is the intended user-facing class, while pyqir.Module appears to be more of a low-level construct.

For instance, pyqir.SimpleModule.bitcode() supports Python type hints, whereas pyqir.Module.bitcode does not. The pyqir.SimpleModule also provides several user-facing methods that are not present in pyqir.Module. Furthermore, the pyqir.SimpleModule._module property ultimately returns a pyqir.Module, meaning that adopting SimpleModule would not lose any information.

Given these points, returning a SimpleModule instead of a plain Module seems like it would be a meaningful enhancement with minimal cost, aligning better with the intended usage patterns and providing additional functionality to users.

@ryanhill1 ryanhill1 added discussion Needs further discussion pyqir Interfacing with QIR python bindings labels Dec 5, 2024
@ryanhill1 ryanhill1 changed the title Investigate pyqir.SimpleModule as return type instead of pyqir.Module` Investigate pyqir.SimpleModule as return type instead of pyqir.Module Dec 5, 2024
@ryanhill1 ryanhill1 added the enhancement New feature or request label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Needs further discussion enhancement New feature or request pyqir Interfacing with QIR python bindings
Projects
None yet
Development

No branches or pull requests

1 participant