-
Notifications
You must be signed in to change notification settings - Fork 11
Qubit and BitVar supports get item #67
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
Qubit and BitVar supports get item #67
Conversation
@PhilReinhold This PR closes issue #8 and #62. Could you review and provide feedback on the implementation? Appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One request, but otherwise looks good. Thanks for the contribution!
oqpy/quantum_types.py
Outdated
def __getitem__(self, index: AstConvertible) -> OQIndexExpression: | ||
if self.size is None: | ||
raise TypeError(f"'{self.name}' is not subscriptable") | ||
return OQIndexExpression(collection=self, index=index, type=ast.Identifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think returning an OQIndexExpression
here is not quite correct, since OQIndexExpression
is a subtype of OQPyExpression
which is only for classical typed expressions. I think here you could either make a new type (e.g. IndexedQubitArray
) or just return the ast.IndexedExpresssion
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the feedback, I updated and added a IndexedQubitArray
class
# Todo (#51): support QubitArray | ||
class QubitArray: | ||
"""Represents an array of qubits.""" | ||
class IndexedQubitArray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason for not being a subclass of OQPyExpression
: There is no ast type for qubits
Reason for not being a subclass of Var
: It cannot not be declared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the changes, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm late but we should add this fix later
decl = ast.QubitDeclaration(ast.Identifier(self.name), size=None) | ||
decl = ast.QubitDeclaration( | ||
ast.Identifier(self.name), | ||
size=ast.IntegerLiteral(self.size) if self.size else self.size, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size=ast.IntegerLiteral(self.size) if self.size else None,
is better
Closes #8 and #62
Description of change:
OQIndexExpression
tooqpy.base
__getitem__
returns anOQIndexExpression
QubitArray
class