# How to create arbitrary superposition

**URL:** <https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821>\
**Category:** PennyLane Help\
**Created:** [July 25, 2025, 12:32pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821 "2025-07-25T12:32:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RisingPhoelix](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/risingphoelix/32/3942_2.png) [@RisingPhoelix](https://discuss.pennylane.ai/u/RisingPhoelix)\
**Post date:** [July 25, 2025, 12:32pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/1 "2025-07-25T12:32:43Z")

</div>

Hello Pennylane Community,

I am wondering what would be the most efficient way to create a superposition of two states in Pennylane? Say I have two quantum circuits `circuit1` and `circuit2` and they generate some states |\phi \rangle and |\psi \rangle. Is there a way in Pennylane to directly add them together and renormalize the state such that you get a new state like |\Phi \rangle = \alpha |\phi \rangle +\beta |\psi \rangle with arbitrary but normalization preserving \alpha and \beta? Of course I can also write a quantum circuit with post-selection that does it, but maybe there is (or should be) a way to do this directly in Pennylane so I dont need the memory for an additional ancilla.

I only found `qml.Superposition` to create superpositions of computational basis states but this is too restricted for me.

Thanks for any input 🙂

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [July 25, 2025, 9:44pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/2 "2025-07-25T21:44:39Z")

</div>

Hi @RisingPhoelix , welcome to the Forum!

I guess you could use [qml.StatePrep](https://docs.pennylane.ai/en/stable/code/api/pennylane.StatePrep.html). You would need to return the state of each subcircuit, do some processing, and then plug it into a new circuit using StatePrep. Note that StatePrep has a normalization option, so this part of the question would be solved.

Is this what you were looking for?

---

<div class="post-metadata">

**Author:** ![RisingPhoelix](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/risingphoelix/32/3942_2.png) [@RisingPhoelix](https://discuss.pennylane.ai/u/RisingPhoelix)\
**Post date:** [July 27, 2025, 2:18pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/3 "2025-07-27T14:18:43Z")

</div>

Hi @CatalinaAlbornoz, thanks for the suggestion! Does this work with the MPS device or would the state measurement create the full 2^N-dimensional state vector instead of simply adding the two MPS together? Anyways, I’ll give it a try and let you know, thank you!

---

<div class="post-metadata">

**Author:** ![RisingPhoelix](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/risingphoelix/32/3942_2.png) [@RisingPhoelix](https://discuss.pennylane.ai/u/RisingPhoelix)\
**Post date:** [July 27, 2025, 2:44pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/4 "2025-07-27T14:44:07Z")

</div>

Update: No, it doesnt work since qml.state() indeed returns the full state vector instead of the compressed MPS. Is there some way to extract an MPS, modify them and preparing it in a quantum circuit with Pennylane, @CatalinaAlbarnoz?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [July 29, 2025, 9:12pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/5 "2025-07-29T21:12:14Z")

</div>

Hi @RisingPhoelix , thanks for reporting this.  
Let me check and get back to you on this.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [July 30, 2025, 9:37pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/6 "2025-07-30T21:37:46Z")

</div>

Hi @RisingPhoelix ,

I’m having trouble finding an answer. Could you give me some more context for your question or some pseudocode of what you would like to do?

My understanding is that you want some compressed representation of the state from two separate circuits and then preparing a third circuit with a superposition of both states, but again in some compressed way. Is that right?

---

<div class="post-metadata">

**Author:** ![RisingPhoelix](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/risingphoelix/32/3942_2.png) [@RisingPhoelix](https://discuss.pennylane.ai/u/RisingPhoelix)\
**Post date:** [July 31, 2025, 2:54pm UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/7 "2025-07-31T14:54:18Z")

</div>

Hi @CatalinaAlbornoz ,

Exactly! Here’s an example what I want to do:

```python
import numpy as np
import pennylane as qml

qubits = 18 # works with 18 qubits, but not with 50 qubits as I would expect with MPS
dev = qml.device("default.tensor", wires=qubits, method="mps", max_bond_dim=10, contract="auto-mps")

@qml.qnode(dev)
def circuit_a(x1):
    for i in range(qubits):
        qml.RX(x1[i], wires=i)
        qml.CNOT(wires=[i, (i + 1) % 4])

    return qml.state()

@qml.qnode(dev)
def circuit_b(x2):
    for i in range(qubits):
        qml.RY(x2[i], wires=i)
        qml.CNOT(wires=[i, (i + 1) % 4])

    qml.X(wires=0)
    return qml.state()

x1 = np.array([0.1] * qubits)
x2 = np.array([0.2] * qubits)

psi = circuit_a(x1)
phi = circuit_b(x2)

# I want to add the MPS representations, not the actual 2^qubits-dimensional states.
# But psi and phi are not MPS, they are just states.
superposition = (psi + phi) / np.linalg.norm(psi + phi)

@qml.qnode(dev)
def superposition_circuit(state):
    qml.StatePrep(state, wires=range(qubits))
    
    for i in range(qubits):
        qml.RX(0.1, wires=i)

    return [qml.expval(qml.PauliZ(i)) for i in range(qubits)]

result = np.array(superposition_circuit(superposition))

print(result)

```

Hope this makes things clear. I know there is an alternative way by using an ancilla qubit with a post-selection measurement, but I would like to reduce the overhead as much as possible since MPS addition would be very simple and efficient.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [August 2, 2025, 12:03am UTC](https://discuss.pennylane.ai/t/how-to-create-arbitrary-superposition/8821/8 "2025-08-02T00:03:42Z")

</div>

Hi @RisingPhoelix ,

I think our demo on [Constant-depth preparation of matrix product states](https://pennylane.ai/qml/demos/tutorial_constant_depth_mps_prep) contains the solution to your question.

It has a `sequential_preparation` subroutine to prepare the Matrix Product States and then a section on [Fusion of MPS states](https://pennylane.ai/qml/demos/tutorial_constant_depth_mps_prep#fusion-of-mps-states-with-mid-circuit-measurements), and also one on [operator pushing](https://pennylane.ai/qml/demos/tutorial_constant_depth_mps_prep#operator-pushing) to correct some defect matrices. This looks a lot like what you’re describing.

I recommend that you take a close look at the full demo, try out the code and let me know if this works for what you need!
