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

Add storage locations and methods for classical variables to QuantumCircuit #10924

Closed
Tracked by #10922
jakelishman opened this issue Oct 2, 2023 · 1 comment
Closed
Tracked by #10922
Assignees
Labels
mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Milestone

Comments

@jakelishman
Copy link
Member

jakelishman commented Oct 2, 2023

Add the new public-API methods and internal tracking to QuantumCircuit necessary to handle the new manual variables as described by Qiskit/RFCs#50.

Copied from the RFC, the new public API surface looks like:

class QuantumCircuit:
    def __init__(
        self,
        ...,  # existing structure
        *,
        inputs: Iterable[expr.Var] = (),
        captures: Iterable[expr.Var] = (),
        declarations: Mapping[expr.Var, expr.Expr] | Iterable[Tuple[expr.Var, expr.Expr]] = (),
    ): ...

    def add_var(self, name_or_var: str | expr.Var, / initial: expr.Expr) -> expr.Var: ...
    def add_capture(self, *vars: expr.Var): ...
    @overload
    def add_input(self, name_or_var: str, type: types.Type, /) -> expr.Var: ...
    @overload
    def add_input(self, name_or_var: expr.Var, /) -> expr.Var: ...

    def store(self, location: expr.Expr, value: expr.Expr, /): ...

    @overload
    def get_var[T](self, name: str, *, default=T) -> Union[expr.Var, T]: ...
    @overload
    def get_var(self, name: str, *, default=NotGiven) -> expr.Var: ...
    def has_var(self, var: Union[str | expr.Var]) -> bool: ...

    # All variables, including inputs and captures.
    def iter_vars(self) -> Iterable[expr.Var]: ...

    # All do what they say on the tin.
    def iter_declared_vars(self) -> Iterable[expr.Var]: ...
    def iter_input_vars(self) -> Iterable[expr.Var]: ...
    def iter_captured_vars(self) -> Iterable[expr.Var]: ...
@jakelishman jakelishman added this to the 0.45.0 milestone Oct 2, 2023
@jakelishman jakelishman added the mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library label Oct 2, 2023
@jakelishman jakelishman self-assigned this Oct 3, 2023
@jakelishman jakelishman modified the milestones: 0.45.0, 1.0.0 Oct 5, 2023
@jakelishman
Copy link
Member Author

Closed by #10974.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant