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
Implemented State Preparation Gate #4482
Conversation
Just the basic class setup.
No tests yet, just trying to import and run, basic framework ready, think this is how to make the state prep gate, by decomposing to cirq.reset() and cirq.MatrixGate().
Now the prepare gate gets imported in my local environment.
The code is almost complete, it should be very close to working, but the simulator refuses to simulate.
State preparation gate has all it's tests working, but it's still wrong, because changing the values of the target state in test_state_prep_gate leads to the unitary not being a unitary anymore.
A one line formatting error fixed in state preparation gate.
Tested on all real values, everything works. Fails on complex valued states.
Needed to take the conjugate in Gram-Schmidt process, now works.
Trying to get all complex cases to work. Ran autoformatter.
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.
My overall impression of this PR is positive - the new gate is fully realized as a Cirq type, with protocol methods, documentation, and testing in line with existing code. Comments are mostly style fixes and requests for additional tests.
Thanks for taking this on!
Changed the tests to be parametrized, moved a few functions around, fixed some comments.
…-cirq into gate/state-prep
A different implementation, doesn't decompose to a reset and a unitary, instead uses a kraus operator to set the values of the qubits. Adds a new test and match parameters in the pytest fail checks.
Equality for non-compatible datatypes, few additions in tests to get full coverage.
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.
Commented on the remaining items.
And fixed the tests.
…-cirq into gate/state-prep
@95-martin-orion : Hi, I have a question. I have studied several algorithms for preparing quantum states. There are different parameters. For example, some of them reduce circuit cost and depth but using ancilla qubits. Some of them are efficient for sparse states and etc. Hence, we can have different decompositions for different goals. Now my question is, where can I implement them? as a "decompose" function in the "state preparation gate" class? Thanks! |
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.
Looks good!
We only support a single |
def __repr__(self) -> str: | ||
return f'cirq.StatePreparationChannel({proper_repr(self._state)})' | ||
|
||
def __eq__(self, other) -> bool: |
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.
Why not use @value.value_equality
?
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.
Having problems with this, mentioned in the new PR.
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.
@AnimeshSinha1309 Left a few nit's. Please fix in a follow up PR.
Thanks for doing this!
|
||
|
||
def test_equality_of_gates(): | ||
state = np.array([1, 0, 0, 0], dtype=np.complex64) |
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.
Use EqualsTester
instead to check for equality. It will also help check that two StatePreparationChannel
s with different state
s are not equal.
@fmozafari I've opened #4500 to track this. |
Fixed many of the nits mentioned in quantumlib#4482, value-equality not a part of this commit.
* Fixing Minor Errors Fixed many of the nits mentioned in #4482, value-equality not a part of this commit. * Approx Equality support added State Preparation Channel got equality comparison similar to that of Matrix Gate. * Added name parameter to state preparation channel name parameter added to constructor, JSON, and repr serialization as well as test data. * Custom names in serialization tests The name has been changed in the JSON and repr protocol tests to make the older version fail. * Format and Lint Fix Had to run pylint. * Adding tests to ignore name Two gates with different names are still equal, added tests for that.
Implements a new gate to reset on all channels and prepare an arbitrary state over n-qubits by returning the Kraus operator for the same. Associated tests included. Closes quantumlib#4119.
* Fixing Minor Errors Fixed many of the nits mentioned in quantumlib#4482, value-equality not a part of this commit. * Approx Equality support added State Preparation Channel got equality comparison similar to that of Matrix Gate. * Added name parameter to state preparation channel name parameter added to constructor, JSON, and repr serialization as well as test data. * Custom names in serialization tests The name has been changed in the JSON and repr protocol tests to make the older version fail. * Format and Lint Fix Had to run pylint. * Adding tests to ignore name Two gates with different names are still equal, added tests for that.
Implements a new gate to reset on all channels and prepare an arbitrary state over n-qubits by returning the Kraus operator for the same. Associated tests included.
Closes #4119.