# How to create this state?

**URL:** <https://discuss.pennylane.ai/t/how-to-create-this-state/1553>\
**Category:** PennyLane Help\
**Created:** [December 12, 2021, 11:10am UTC](https://discuss.pennylane.ai/t/how-to-create-this-state/1553 "2021-12-12T11:10:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit27kh](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ankit27kh](https://discuss.pennylane.ai/u/ankit27kh)\
**Post date:** [December 12, 2021, 11:10am UTC](https://discuss.pennylane.ai/t/how-to-create-this-state/1553/1 "2021-12-12T11:10:02Z")

</div>

The feature map described in the paper [A rigorous and robust quantum speed-up in supervised machine learning](https://arxiv.org/abs/2010.02174v2) is:  
 ![e1](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/1X/870d7a5a08b4c470aa1385b35092bd80252016da.png)  
They provide a theoretical description of how this state can be created, but no actual circuit is provided.

 ![Capture](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/1X/0d535958d10c553da7d363e01f7e6619eb10ca78.png)  
How to create this feature map?

---

<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:** [December 13, 2021, 8:54pm UTC](https://discuss.pennylane.ai/t/how-to-create-this-state/1553/2 "2021-12-13T20:54:48Z")

</div>

Hi @ankit27kh!

I don’t think we have an embedding for exactly this feature map. However you could use the [Arbitrary State Preparation template](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.ArbitraryStatePreparation.html) to build it yourself.

Why don’t you try to create it using this template and let us know how it goes? If you manage to implement it, it would be amazing if you could contribute it to PennyLane.

---

<div class="post-metadata">

**Author:** ![jmarrazola](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jmarrazola/32/255_2.png) [@jmarrazola](https://discuss.pennylane.ai/u/jmarrazola)\
**Post date:** [December 15, 2021, 4:28pm UTC](https://discuss.pennylane.ai/t/how-to-create-this-state/1553/3 "2021-12-15T16:28:55Z")

</div>

Hi @ankit27kh,

Yes, implementing this feature map is not straightforward.

Unless you’re planning to implement this on hardware, the simplest way to prepare these states is likely to use the [QubitStateVector](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.QubitStateVector.html) operation.

I haven’t checked the details of the paper, so the following code may be implementing a different state, but hopefully it gives you an idea of how you could implement what you want:

```python

import pennylane as qml
import numpy as np

g = 4
n_wires = 4

# creates a state vector corresponding to the desire state
# x and g should be integers
def phi(x): 
    dim = 2 ** n_wires
    state = np.zeros(dim)
    
    for i in range(dim):
        j = (x * g ** i) % dim
        state[j] += 1
        
    norm = np.linalg.norm(state)
        
    return state/norm

dev = qml.device('default.qubit', wires=n_wires)

@qml.qnode(dev)
def circuit(x):
    qml.QubitStateVector(phi(x), wires=range(n_wires))
    
    return qml.state()

```

Let me know if that helps!

Juan Miguel

---

<div class="post-metadata">

**Author:** ![ankit27kh](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ankit27kh](https://discuss.pennylane.ai/u/ankit27kh)\
**Post date:** [December 16, 2021, 10:27am UTC](https://discuss.pennylane.ai/t/how-to-create-this-state/1553/4 "2021-12-16T10:27:03Z")

</div>

Hey @jmarrazola, thanks for your input. I can not do all that I want to do without the actual circuit, but this does help out in at least getting somewhere.
