Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Operator.compose should allow indices #1088

Closed
Cryoris opened this issue Jul 1, 2020 · 2 comments · Fixed by #1144
Closed

Operator.compose should allow indices #1088

Cryoris opened this issue Jul 1, 2020 · 2 comments · Fixed by #1144
Labels
type: feature request New feature or request

Comments

@Cryoris
Copy link
Contributor

Cryoris commented Jul 1, 2020

What is the expected behavior?

The compose method of the OperatorBase requires the composed operators to have the same size.
This might not always be the case. We should allow passing indices in compose to be able to compose operators
of different sizes, much like in QuantumCircuit.compose.

One possible solution would be to add Pauli I operators to pad the smaller operator.

@Cryoris Cryoris added the type: feature request New feature or request label Jul 1, 2020
@dongreenberg
Copy link
Contributor

Just noting that it's worth considering how this squares with the existing permute function in the circuit ops. One option could be for the core path to be op1 @ op2.permute(indices) rather than (or alongside) op1.compose(op2, indices=indices). permute is a bit more general as it is valuable for other things as well.

@molar-volume
Copy link
Contributor

molar-volume commented Jul 25, 2020

CircuitOp.permute currently raises exception for the case of indices beyond num_qubit:

(X ^ Y).to_circuit_op().permute([0,2])

which is something that might be possible and then it can work as follows:

1) (X ^ Y).permute([0,2]) @ (X ^ Y ^ Z) ——> (X ^ I ^ Y) @ (X ^ Y ^ Z)

2) (X ^ Y) @ (X ^ Y ^ Z)  ——>  (X ^ Y ^ I) @ (X ^ Y ^ Z)

The interface for compose might be

def compose(self, other: 'OperatorBase', self_permute: List[int] = None, other_permute: List[int] = None) -> 'OperatorBase'

and will use permute behind the scenes.

This is more general than QuantumCircuit.compose.
QuantumCircuit.compose can pad and permute only 'other' circuit, if 'self' is smaller, it raises exception.

Or maybe we don't want to change the interface of compose, since 1) and 2) provide required functionality?

If you are OK with that, I would start the implementation of 1) and 2).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants