-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Controlled gate construction cannot construct some cases #4512
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
Comments
hi, is anyone working on this (in other words can I work on it?) |
@NoureldinYosri I've assigned it to you. |
Analysis: Solution: on the other hand the ability of having controlling the gates using independent qubits (in terms of the truth table of the control combinations) should still be supported not just for backward compatibility but also because it would make it easier to represent some truth tables my suggestion is to create a class that maintains two things
I already wrote a small demo for this idea but wanted to check with you before I continue implementing @vtomole |
Cirq cync: We have a potential solution with a prototype. This will likely need careful consideration and review, but is doable with the solution from @NoureldinYosri |
This is a prototype of my solution @dstrain115 @vtomole
output is [0, 0, 1] [1, 0, 0, 0, 1] |
@dabacon could you please review the solution? |
The one kind of strange thing about your implementation (which is quite ingenious!) is that the two cases are distinguished by a) list of int or (list of int) and b) list of list of (list of ints). This is a bit hard for most people to see the difference between, i.e. staring at the list of list of lists to see thats what it is isn't too easy. What I would suggest is that we keep this "raw" form, but maybe also add some helpers for people to write this, i.e. instead of a) you could provide FreeVars(0, [0,1]) and for b) you could provide ConstrainedVars([0, 1], [0, 1]). To be clear I think it could also accept the way you have things currently constructed, but just adding this as a convenience I think would make it more usable for most people. |
sounds good, I'll incorporate your suggestion into my code and create a PR |
…mlib#4512 - created control_values.py which contains the ControlValues class. - FreeVars and ConstrainedVars classes are provided for ease of use. - while the basic idea of ControlValues integrating it inside the code base was challening - the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities - the trickiest part to get right was the support for formatting! - I'll create a follow up PR for unit tests for control_values.py
…mlib#4512 - created control_values.py which contains the ControlValues class. - FreeVars and ConstrainedVars classes are provided for ease of use. - while the basic idea of ControlValues integrating it inside the code base was challening - the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities - the trickiest part to get right was the support for formatting! - I'll create a follow up PR for unit tests for control_values.py
…mlib#4512 quantumlib#4714 - created control_values.py which contains the ControlValues class. - FreeVars and ConstrainedVars classes are provided for ease of use. - while the basic idea of ControlValues integrating it inside the code base was challening - the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities - the trickiest part to get right was the support for formatting! - I'll create a follow up PR for unit tests for control_values.py
…mlib#4512 - created control_values.py which contains the ControlValues class. - FreeVars and ConstrainedVars classes are provided for ease of use. - while the basic idea of ControlValues integrating it inside the code base was challening - the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities - the trickiest part to get right was the support for formatting! - I'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class.\nFreeVars and ConstrainedVars classes are provided for ease of use.\nwhile the basic idea of ControlValues integrating it inside the code base was challening\nthe old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities\nthe trickiest part to get right was the support for formatting!\nI'll create a follow up PR for unit tests for control_values.py
…mlib#4512 created control_values.py which contains the ControlValues class. FreeVars and ConstrainedVars classes are provided for ease of use. while the basic idea of ControlValues integrating it inside the code base was challening the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities the trickiest part to get right was the support for formatting!
…mlib#4512 created control_values.py which contains the ControlValues class. FreeVars and ConstrainedVars classes are provided for ease of use. while the basic idea of ControlValues integrating it inside the code base was challening the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities the trickiest part to get right was the support for formatting!
…mlib#4512 created control_values.py which contains the ControlValues class. FreeVars and ConstrainedVars classes are provided for ease of use. while the basic idea of ControlValues integrating it inside the code base was challening the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities the trickiest part to get right was the support for formatting!
…mlib#4512 created control_values.py which contains the ControlValues class. FreeVars and ConstrainedVars classes are provided for ease of use. while the basic idea of ControlValues integrating it inside the code base was challening the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities the trickiest part to get right was the support for formatting!
@NoureldinYosri still working on this? It'll be required for deferred measurements #4818. Or, at least some way of defining the condition "at least one qubit is not zero". |
I think all I'd really need here is just another parameter Edit: Looks like such a thing should be possible, as everywhere the existing |
@daxfohl my GH-4714 has been pending review for sometime in the PR I create a ControlValues class which supports the operations needed, the contructor for it can support both the _exact way for defining the allowed values as well as the old way, this way adding support for more ways to define control values would be as simple as creating a child class that reads the new form of input (e.g. list of ints) and set the internal variables correctly and maybe override some internal function(s). so lets get GH-4714 reviewed and submitted :) |
…mlib#4512 created control_values.py which contains the ControlValues class. FreeVars and ConstrainedVars classes are provided for ease of use. while the basic idea of ControlValues integrating it inside the code base was challening the old way of using control_values assumed it's a tuple of tuples of ints and was used as thus (comparasion, hashing, slicing, fomatting, conditioning, and loops), the ControlValues class had to provide these functionalities the trickiest part to get right was the support for formatting!
Closes #4818, Also reimplements `mux` simulation based on this, in preparation to deprecate `ignore_measurement_results`. Needs a follow-up after #4512 to support classical controls on multi-qubit measurements, as we need some way of defining the condition "at least one qubit is not zero" to match the classical interpretation of a multi-qubit measurement.
Closes quantumlib#4818, Also reimplements `mux` simulation based on this, in preparation to deprecate `ignore_measurement_results`. Needs a follow-up after quantumlib#4512 to support classical controls on multi-qubit measurements, as we need some way of defining the condition "at least one qubit is not zero" to match the classical interpretation of a multi-qubit measurement.
…n that replicates current behaviour. refactored the code for control_values and abstracted its calls this is a first step towards implementing more ways to represent control values in order to solve quantumlib#4512
Created a concrete implementation that replicates current behaviour. refactored the code for control_values and abstracted its calls this is a first step towards implementing more ways to represent control values in order to solve #4512
This class allows the creation of control values that can't be factored into simple products hence solving quantumlib#4512
This class allows the creation of control values that can't be factored into simple products hence solving #4512
This is now completed. See #5788 for details on usage and tests. |
Closes quantumlib#4818, Also reimplements `mux` simulation based on this, in preparation to deprecate `ignore_measurement_results`. Needs a follow-up after quantumlib#4512 to support classical controls on multi-qubit measurements, as we need some way of defining the condition "at least one qubit is not zero" to match the classical interpretation of a multi-qubit measurement.
…5362) Created a concrete implementation that replicates current behaviour. refactored the code for control_values and abstracted its calls this is a first step towards implementing more ways to represent control values in order to solve quantumlib#4512
This class allows the creation of control values that can't be factored into simple products hence solving quantumlib#4512
Closes quantumlib#4818, Also reimplements `mux` simulation based on this, in preparation to deprecate `ignore_measurement_results`. Needs a follow-up after quantumlib#4512 to support classical controls on multi-qubit measurements, as we need some way of defining the condition "at least one qubit is not zero" to match the classical interpretation of a multi-qubit measurement.
…5362) Created a concrete implementation that replicates current behaviour. refactored the code for control_values and abstracted its calls this is a first step towards implementing more ways to represent control values in order to solve quantumlib#4512
This class allows the creation of control values that can't be factored into simple products hence solving quantumlib#4512
Is your feature request related to a use case or problem? Please describe.
Suppose you want a three qubit controlled gate like
(|00><00| + |11><11|) X + (|01><01| + |10><10| I
which flips the third qubit if the first qubit is either 00 or 11. This currently isn't possible to construct given the way cirq specifiedcontrol_values
. This is becausecontrol_values
is a sequence of length equal to the number of controls, and this sequence is eitherint
s or sequences ofint
s. In the second case the sequence means "either of these". Thus you might think this would construct the gate above, but it does not(this flips the third qubit for all inputs)
Or maybe this
(this flips the third qubit if the first control is zero and the second is one.
Describe the solution you'd like
Not sure we can fix this now, as this interface is used throughout :(
Probably the better interface would have been sequence of ints, same interperation, sequence of sequence either zipped up to get possible control positive values, or sequence of sequence where inner sequence is sequence of ints describing a positive control value. If you really want to include unions for any of these, places where there is an int could have either an indicator value or another sequence to unionize what this means.
[optional] Describe alternatives/workarounds you've considered
Create two ops in a row that do what you want. Custom gate controlled gate.
What is the urgency from your perspective for this issue? Is it blocking important work?
P2 - we should do it in the next couple of quarters
The text was updated successfully, but these errors were encountered: