-
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
Changes from 4 commits
f57ab83
8b2280f
c6c766f
51e2397
bda323a
0dc0d95
8efed6a
e41ceab
45e80df
6fa2124
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,14 @@ | |
from openpulse import ast | ||
from openpulse.printer import dumps | ||
|
||
from oqpy.base import AstConvertible, Var, make_annotations, to_ast | ||
from oqpy.base import AstConvertible, Var, make_annotations, to_ast, OQIndexExpression | ||
from oqpy.classical_types import AngleVar, _ClassicalVar | ||
|
||
if TYPE_CHECKING: | ||
from oqpy.program import Program | ||
|
||
|
||
__all__ = ["Qubit", "QubitArray", "defcal", "gate", "PhysicalQubits", "Cal"] | ||
__all__ = ["Qubit", "defcal", "gate", "PhysicalQubits", "Cal"] | ||
|
||
|
||
class Qubit(Var): | ||
|
@@ -39,11 +39,13 @@ class Qubit(Var): | |
def __init__( | ||
self, | ||
name: str, | ||
size: int = None, | ||
PhilReinhold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
needs_declaration: bool = True, | ||
annotations: Sequence[str | tuple[str, str]] = (), | ||
): | ||
super().__init__(name, needs_declaration=needs_declaration) | ||
self.name = name | ||
self.size = size | ||
self.annotations = annotations | ||
|
||
def to_ast(self, prog: Program) -> ast.Expression: | ||
|
@@ -53,10 +55,18 @@ def to_ast(self, prog: Program) -> ast.Expression: | |
|
||
def make_declaration_statement(self, program: Program) -> ast.Statement: | ||
"""Make an ast statement that declares the OQpy variable.""" | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
is better |
||
) | ||
decl.annotations = make_annotations(self.annotations) | ||
return decl | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I think returning an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the feedback, I updated and added a |
||
|
||
|
||
class PhysicalQubits: | ||
"""Provides a means of accessing qubit variables corresponding to physical qubits. | ||
|
@@ -68,11 +78,6 @@ def __class_getitem__(cls, item: int) -> Qubit: | |
return Qubit(f"${item}", needs_declaration=False) | ||
|
||
|
||
# Todo (#51): support QubitArray | ||
class QubitArray: | ||
"""Represents an array of qubits.""" | ||
|
||
|
||
@contextlib.contextmanager | ||
def gate( | ||
program: Program, | ||
|
Uh oh!
There was an error while loading. Please reload this page.