-
Notifications
You must be signed in to change notification settings - Fork 377
More powerful Operator.to_circuit #1089
Comments
Hi @Cryoris and raises error for non-unitary operators I will create PR as soon as I extend the tests. |
Thanks for looking into this. |
@Cryoris Referring to the opening comment in this issue: Are you suggesting supporting |
The idea was to add it only for derived classes, meaning: If we want we could also add it to the |
@Cryoris I moved the methods to the child classes, please see the PR. |
* 1) for ListOp, new method ‘to_circuit’ implemented, using existing to_circuit_op 2) for SummedOp, ‘to_circuit’ overriden to avoid infinite recursion * tests for ListOp.to_circuit * 1) to_circuit method moved from ListOp to child classes 2) removed unnecessary abstract to_circuit from OperatorBase * Update test/aqua/operators/test_op_construction.py * verify that ListOp.to_circuit() outputs correct quantum circuit * Check if to_circuit_op returns expected operator to avoid the #type: ignore. Else, exception is raised * test for to_circuit method for SummedOp([TensoredOp, TensoredOp]) * tests exposing the missing features in to_circuit, to_instruction and to_matrix of PrimitiveOps with Parameter * 1) SummedOp.to_circuit raises exception, if conversion to_matrix_op does not provide MatrixOp (which happens if respective summands are parametrized) 2) added unit test to cover this case Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
…nity#1124) * 1) for ListOp, new method ‘to_circuit’ implemented, using existing to_circuit_op 2) for SummedOp, ‘to_circuit’ overriden to avoid infinite recursion * tests for ListOp.to_circuit * 1) to_circuit method moved from ListOp to child classes 2) removed unnecessary abstract to_circuit from OperatorBase * Update test/aqua/operators/test_op_construction.py * verify that ListOp.to_circuit() outputs correct quantum circuit * Check if to_circuit_op returns expected operator to avoid the #type: ignore. Else, exception is raised * test for to_circuit method for SummedOp([TensoredOp, TensoredOp]) * tests exposing the missing features in to_circuit, to_instruction and to_matrix of PrimitiveOps with Parameter * 1) SummedOp.to_circuit raises exception, if conversion to_matrix_op does not provide MatrixOp (which happens if respective summands are parametrized) 2) added unit test to cover this case Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
…nity#1124) * 1) for ListOp, new method ‘to_circuit’ implemented, using existing to_circuit_op 2) for SummedOp, ‘to_circuit’ overriden to avoid infinite recursion * tests for ListOp.to_circuit * 1) to_circuit method moved from ListOp to child classes 2) removed unnecessary abstract to_circuit from OperatorBase * Update test/aqua/operators/test_op_construction.py * verify that ListOp.to_circuit() outputs correct quantum circuit * Check if to_circuit_op returns expected operator to avoid the #type: ignore. Else, exception is raised * test for to_circuit method for SummedOp([TensoredOp, TensoredOp]) * tests exposing the missing features in to_circuit, to_instruction and to_matrix of PrimitiveOps with Parameter * 1) SummedOp.to_circuit raises exception, if conversion to_matrix_op does not provide MatrixOp (which happens if respective summands are parametrized) 2) added unit test to cover this case Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
…iskit-community/qiskit-aqua#1124) * 1) for ListOp, new method ‘to_circuit’ implemented, using existing to_circuit_op 2) for SummedOp, ‘to_circuit’ overriden to avoid infinite recursion * tests for ListOp.to_circuit * 1) to_circuit method moved from ListOp to child classes 2) removed unnecessary abstract to_circuit from OperatorBase * Update test/aqua/operators/test_op_construction.py * verify that ListOp.to_circuit() outputs correct quantum circuit * Check if to_circuit_op returns expected operator to avoid the #type: ignore. Else, exception is raised * test for to_circuit method for SummedOp([TensoredOp, TensoredOp]) * tests exposing the missing features in to_circuit, to_instruction and to_matrix of PrimitiveOps with Parameter * 1) SummedOp.to_circuit raises exception, if conversion to_matrix_op does not provide MatrixOp (which happens if respective summands are parametrized) 2) added unit test to cover this case Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
…iskit-community/qiskit-aqua#1124) * 1) for ListOp, new method ‘to_circuit’ implemented, using existing to_circuit_op 2) for SummedOp, ‘to_circuit’ overriden to avoid infinite recursion * tests for ListOp.to_circuit * 1) to_circuit method moved from ListOp to child classes 2) removed unnecessary abstract to_circuit from OperatorBase * Update test/aqua/operators/test_op_construction.py * verify that ListOp.to_circuit() outputs correct quantum circuit * Check if to_circuit_op returns expected operator to avoid the #type: ignore. Else, exception is raised * test for to_circuit method for SummedOp([TensoredOp, TensoredOp]) * tests exposing the missing features in to_circuit, to_instruction and to_matrix of PrimitiveOps with Parameter * 1) SummedOp.to_circuit raises exception, if conversion to_matrix_op does not provide MatrixOp (which happens if respective summands are parametrized) 2) added unit test to cover this case Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
…iskit-community/qiskit-aqua#1124) * 1) for ListOp, new method ‘to_circuit’ implemented, using existing to_circuit_op 2) for SummedOp, ‘to_circuit’ overriden to avoid infinite recursion * tests for ListOp.to_circuit * 1) to_circuit method moved from ListOp to child classes 2) removed unnecessary abstract to_circuit from OperatorBase * Update test/aqua/operators/test_op_construction.py * verify that ListOp.to_circuit() outputs correct quantum circuit * Check if to_circuit_op returns expected operator to avoid the #type: ignore. Else, exception is raised * test for to_circuit method for SummedOp([TensoredOp, TensoredOp]) * tests exposing the missing features in to_circuit, to_instruction and to_matrix of PrimitiveOps with Parameter * 1) SummedOp.to_circuit raises exception, if conversion to_matrix_op does not provide MatrixOp (which happens if respective summands are parametrized) 2) added unit test to cover this case Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
What is the expected behavior?
Right now, the
to_circuit
method only works on the operator primitives but not onListOp
s. I think we should try to add this method for theListOp
s too. If in some cases it is not possible, e.g. because the operator is not unitary, we can raise an error.Example:
Though
i.to_circuit
andX.to_circuit
both work.Note that some combinations, such as
CircuitOp @ PauliOp
, work because the composition does not return aComposedOp
but the type of the left-hand-side operator.The text was updated successfully, but these errors were encountered: