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

Use typehints for **kwargs #2607

Open
2 tasks
purva-thakre opened this issue Dec 19, 2024 · 2 comments
Open
2 tasks

Use typehints for **kwargs #2607

purva-thakre opened this issue Dec 19, 2024 · 2 comments
Labels
good first issue Good for newcomers non-quantum Requires no knowledge of quantum physics to fix / work on. priority/low A non-urgent issue to fix or idea to discuss.

Comments

@purva-thakre
Copy link
Collaborator

As noted in #2589 (comment), typehint for kwargs are manually provided.

To close this issue:

@purva-thakre purva-thakre added good first issue Good for newcomers non-quantum Requires no knowledge of quantum physics to fix / work on. priority/low A non-urgent issue to fix or idea to discuss. labels Dec 19, 2024
@EmilyIsCoding
Copy link

Hello, I have some questions about the expected changes.

According to the updated documentation, would it look something like:

from typing import TypedDict, Unpack

class Method_Select(TypedDict):
    method: str

def execute_with_cdr(
    circuit: QPROGRAM,
    executor: Union[Executor, Callable[[QPROGRAM], QuantumResult]],
    observable: Optional[Observable] = None,
    *,
    simulator: Union[Executor, Callable[[QPROGRAM], QuantumResult]],
    num_training_circuits: int = 10,
    fraction_non_clifford: float = 0.1,
    fit_function: Callable[..., float] = linear_fit_function,
    num_fit_parameters: Optional[int] = None,
    scale_factors: Sequence[float] = (1,),
    scale_noise: Callable[[QPROGRAM, float], QPROGRAM] = fold_gates_at_random,
    **kwargs: Method_Select,
) -> float:

In which case I'm not sure what the advantage switching over to Unpack is. Thanks for your patience in explaining!

@purva-thakre
Copy link
Collaborator Author

purva-thakre commented Dec 20, 2024

HI @EmilyIsCoding, thank you for your interest in this issue!

In which case I'm not sure what the advantage switching over to Unpack is.

Right now, type hinting for kwargs is accomplished through manually providing the type. See below.

mitiq/mitiq/cdr/cdr.py

Lines 82 to 99 in c4d6a44

kwargs: Available keyword arguments are:
- method_select (string): Specifies the method used to select the
non-Clifford gates to replace when constructing the near-Clifford
training circuits. Can be 'uniform' or 'gaussian'.
- method_replace (string): Specifies the method used to replace the
selected non-Clifford gates with a Clifford when constructing the
near-Clifford training circuits. Can be 'uniform', 'gaussian', or
'closest'.
- sigma_select (float): Width of the Gaussian distribution used for
``method_select='gaussian'``.
- sigma_replace (float): Width of the Gaussian distribution used
for ``method_replace='gaussian'``.
- random_state (int): Seed for sampling.

If we switch to using Unpack, I believe we would no longer have to provide the manually added descriptions. Maybe there is a better way to do this. I am open to other options as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers non-quantum Requires no knowledge of quantum physics to fix / work on. priority/low A non-urgent issue to fix or idea to discuss.
Projects
None yet
Development

No branches or pull requests

2 participants