Skip to content

Commit

Permalink
Use qubit types from braket.registers module (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer authored Oct 31, 2023
1 parent 5459174 commit 53ea006
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/braket/experimental/autoqasm/instructions/qubits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
from openpulse.printer import dumps

from braket.experimental.autoqasm import constants, errors, program
from braket.registers.qubit import Qubit

QubitIdentifierType = Union[int, oqpy._ClassicalVar, oqpy.base.OQPyExpression, str, oqpy.Qubit]
QubitIdentifierType = Union[
int, str, Qubit, oqpy._ClassicalVar, oqpy.base.OQPyExpression, oqpy.Qubit
]


def is_qubit_identifier_type(qubit: Any) -> bool:
Expand Down Expand Up @@ -58,11 +61,8 @@ def _get_physical_qubit_indices(qids: list[str]) -> list[int]:
return braket_qubits


def _global_qubit_register(qubit_idx_expr: Union[int, str]) -> str:
# TODO: We should index into a oqpy.Qubit register rather
# than manually generating the string to index into
# a hard-coded global qubit register.
return f"{constants.QUBIT_REGISTER}[{qubit_idx_expr}]"
def _global_qubit_register(qubit_idx_expr: Union[int, str]) -> oqpy.Qubit:
return oqpy.Qubit(f"{constants.QUBIT_REGISTER}[{qubit_idx_expr}]", needs_declaration=False)


@singledispatch
Expand Down Expand Up @@ -92,15 +92,15 @@ def _(qid: float) -> oqpy.Qubit:
def _(qid: int) -> oqpy.Qubit:
# Integer virtual qubit, like `h(0)`
program.get_program_conversion_context().register_qubit(qid)
return oqpy.Qubit(_global_qubit_register(qid), needs_declaration=False)
return _global_qubit_register(qid)


@_qubit.register
def _(qid: oqpy._ClassicalVar) -> oqpy.Qubit:
# Indexed by variable, such as i in range(n); h(i)
if program.get_program_conversion_context().get_declared_qubits() is None:
raise errors.UnknownQubitCountError()
return oqpy.Qubit(_global_qubit_register(qid.name), needs_declaration=False)
return _global_qubit_register(qid.name)


@_qubit.register
Expand All @@ -111,7 +111,7 @@ def _(qid: oqpy.base.OQPyExpression) -> oqpy.Qubit:

oqpy_program = program.get_program_conversion_context().get_oqpy_program()
qubit_idx_expr = dumps(qid.to_ast(oqpy_program))
return oqpy.Qubit(_global_qubit_register(qubit_idx_expr), needs_declaration=False)
return _global_qubit_register(qubit_idx_expr)


@_qubit.register
Expand Down
2 changes: 1 addition & 1 deletion src/braket/experimental/autoqasm/pulse/pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import oqpy

from braket.circuits.qubit_set import QubitSet
from braket.experimental.autoqasm import program as aq_program
from braket.experimental.autoqasm.instructions.qubits import (
QubitIdentifierType,
Expand All @@ -32,6 +31,7 @@
from braket.pulse.frame import Frame
from braket.pulse.pulse_sequence import _validate_uniqueness
from braket.pulse.waveforms import Waveform
from braket.registers.qubit_set import QubitSet


def _pulse_instruction(name: str, frame: Frame, *args) -> None:
Expand Down

0 comments on commit 53ea006

Please sign in to comment.