Skip to content

Add type hints in pulser.parametrized [unitaryHACK] (#16)#175

Merged
HGSilveri merged 17 commits intopasqal-io:developfrom
TripleRD:type-hint-parametrized
May 22, 2021
Merged

Add type hints in pulser.parametrized [unitaryHACK] (#16)#175
HGSilveri merged 17 commits intopasqal-io:developfrom
TripleRD:type-hint-parametrized

Conversation

@TripleRD
Copy link
Copy Markdown
Contributor

Type checked on decorators.py, paramabc.py, paramobj.py and variable.py

I have some doubts about the return type of the build function.

@HGSilveri
Copy link
Copy Markdown
Collaborator

I have some doubts about the return type of the build function.

The build method is complicated, it's probably better to leave it without type-hints in Parametrized and ParamObj. We can probably type hint it in Variable, though.

I'll review this asap. Make sure to address all the errors in the CI tests in the mean time.

@TripleRD
Copy link
Copy Markdown
Contributor Author

I have some doubts about the return type of the build function.

The build method is complicated, it's probably better to leave it without type-hints in Parametrized and ParamObj. We can probably type hint it in Variable, though.

I'll review this asap. Make sure to address all the errors in the CI tests in the mean time.

Okay, have corrected the errors in the CI test, updating the type hints on build.

Copy link
Copy Markdown
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, here are a few comments. Try to be more specific when you can (e.g. if you know the type of the keys and values of a dict, type-hint them too).

Comment thread pulser/parametrized/paramabc.py Outdated
Comment thread pulser/parametrized/paramabc.py Outdated
Comment thread pulser/parametrized/paramabc.py Outdated
Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/variable.py Outdated
Comment thread pulser/parametrized/variable.py Outdated
@TripleRD
Copy link
Copy Markdown
Contributor Author

TripleRD commented May 21, 2021

I'll review this asap. Make sure to address all the errors in the CI tests in the mean time.

Okay @HGSilveri, I'm on it.

Updates -

  • Untyped the build function from Parametrized and ParamObj
  • Changed few type hints
  • Wasn't able to solve pulser/tests/test_parametrized.py:31: error: List or tuple expected as variable arguments. Went through the function definition but didn't find any issue.
    pulse = Pulse.ConstantDetuning(bwf, *b)

@HGSilveri
Copy link
Copy Markdown
Collaborator

  • Wasn't able to solve pulser/tests/test_parametrized.py:31: error: List or tuple expected as variable arguments. Went through the function definition but didn't find any issue.
    pulse = Pulse.ConstantDetuning(bwf, *b)

Try to change that line to

pulse = Pulse.ConstantDetuning(bwf, b[0], b[1])

@TripleRD
Copy link
Copy Markdown
Contributor Author

Hey @HGSilveri, I have updated the suggested changes.

Copy link
Copy Markdown
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it's getting there!

Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/variable.py Outdated
Comment thread pulser/parametrized/variable.py Outdated
@TripleRD
Copy link
Copy Markdown
Contributor Author

Done

Copy link
Copy Markdown
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it's getting there! The next commit should do it

Comment thread pulser/parametrized/paramabc.py
Comment thread pulser/parametrized/paramobj.py Outdated
Comment thread pulser/parametrized/paramobj.py Outdated
@TripleRD
Copy link
Copy Markdown
Contributor Author

Done

Comment thread pulser/parametrized/paramabc.py Outdated
from abc import ABC, abstractmethod
from typing import Dict, Any

from pulser.parametrized import Variable
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what giving you the test error. Try this instead:

Suggested change
from pulser.parametrized import Variable
from pulser.parametrized.variable import Variable

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this doesn't work either, there's another option, but try this first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it didn't work. Try this then:

from typing import Dict, Any, TYPE_CHECKING

if TYPE_CHECKING:
    from pulser.parametrized import Variable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, updating it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have another import like this, you should change it too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment thread pulser/parametrized/paramobj.py Outdated
from pulser.parametrized import Parametrized, Variable
from pulser.json.utils import obj_to_dict
if TYPE_CHECKING:
from pulser.parametrized import Parametrized, Variable
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't really do this because Parametrized is needed even when you're not type checking. You have to split the import into two lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@HGSilveri
Copy link
Copy Markdown
Collaborator

Okay, now you have a coverage problem, which is to be expected... just add #pragma: no cover on the import Variable lines

Copy link
Copy Markdown
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good job!

@HGSilveri HGSilveri merged commit ffcdf56 into pasqal-io:develop May 22, 2021
@TripleRD
Copy link
Copy Markdown
Contributor Author

LGTM, good job!

Thanks for the guidance! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants