-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow to normalize inputs on StatePreparation
and Initialize
#7189
Conversation
The idea is that the user doesn't have to normalize their own input array and that by using normalize=True the user will understand that their input array needs to be normalized and that the Initializer will do it for them. |
To fix the last errors you should run black, e.g. by calling |
@daniel-fry are you still pursuing this? 🙂 |
Hi @Cryoris, yes I'm still pursuing this and I hope to finish it soon (as my first contribution to Qiskit). I just saw your last message about make black. Will work on this today. Might have a couple of questions. Thanks again. |
@Cryoris I can't find much for the "make black" command on Google. I assume it is coming from the black library for code style and I can follow this https://pypi.org/project/black/ ? |
I would suggest just using |
OK thanks @mtreinish I have used tox and it reformatted the initiailizer.py file and gave me a "congratulations :)" but the check error is still there so I must have uploaded it wrong. Working on it... |
I think your git config core.autocrlf true in the repository and that will change your setting for this repository only to the right thing. Unless you have a good reason not to, you probably want to make this setting apply to all your repositories, which you do with git config --global core.autocrlf true The effect of this command is that After you've changed your settings (either way), you can tell git add --renormalize qiskit/extensions/quantum_initializer/initializer.py
git commit -m "Fix line endings" and then push that commit to GitHub. So you don't have to just trust me to run random commands on your computer, here's the documentation from GitHub and from |
@jakelishman Thanks for the tip! |
Hi @Cryoris @jakelishman , I've done the things you suggested. My PR is failing only 1 check now I think. How do I better understand why it's failing? I can see something about azure pipeline... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the bottom of this page, you should see a list of tests across Azure (the blue rocket logo) and GitHub Actions. You can click on "details" on any one of them, which takes you to a GitHub summary page, and the most useful information is found by clicking the "View more details on Azure Pipelines" link that's on this new page. That gets you to Azure, where if you scroll down you should be able to see the failing job(s). If you keep clicking through the red crosses, you'll get to the logs - in this case it's a failure to build the documentation, with the error
/home/vsts/work/1/s/qiskit/extensions/quantum_initializer/initializer.py:
docstring of qiskit.extensions.quantum_initializer.initializer.initialize:25:
Definition list ends without a blank line; unexpected unindent.
Sphinx (the docs tool) errors can be pretty unintelligible at times. In this case it's because of the slightly odd indentation in the docstring of Initializer.__init__
. You can run the documentation build yourself locally with tox -e docs
, to try things out - it can be a bit frustrating at first to learn reStructuredText (RST) because it's a surprisingly finnicky language, but it's powerful in the end.
(Getting to the logs is a bit fiddly for some reason - both GitHub and Azure insert a couple of unnecessary landing pages, so you have to click about four times when you'd expect it to only be one.)
Please could you also add some tests of the new behaviour, including any failure paths (e.g. ensuring that we test that if you pass an unnormalized vector without normalize=True
, it errors). The failure-path tests might already be in place, but we've not historically been perfect about them, so they might not be.
Thanks for the great advice and tips. I appreciate it a lot. |
Yeah, exactly. In this case, you expect that if you try to pass an unnormalised array (like def test_initialize_errors_on_unnormalized_input(self):
qc = QuantumCircuit(3)
with self.assertRaisesRegex(QiskitError, "<part of the expected message>"):
qc.initialize(np.array([1, 2, 3]), normalize=False) The test will report a failure if that type of exception isn't raised, or if the message doesn't match. The documentation for |
@Cryoris @jakelishman Unfortunately I don't have the time to make progress on this and understand how to push it through. Could you take over this please? |
Pull Request Test Coverage Report for Build 5323977910
💛 - Coveralls |
It would probably be good to hold this off until #7666 is merged, since this here is the smaller change and will likely be easier to integrate 🙂 |
This is not blocked anymore, so we can proceed if you're still interested @daniel-fry! Since |
Hi @Cryoris , Unfortunately I don't have time to push it through the quality checks. Will you be able to do this? If there are any blocks I'd be grateful if you could tell me what they are and how to overcome them for next time. |
StatePreparation
and Initialize
Summary
Details and comments