Repository: PennyLaneAI/pennylane (python)

Issue:
int to qml.BasisEmbedding
### Feature details

Currently, to use `BasisEmbedding` we have to pass a list with the bits [0,1,0,0] for example to put a PauliX gate in the second qubit. It would be nice to be able to pass an integer number like:

```python
qml.BasisEmbedding(4, wires = range(4))
```
This result would be the same that:

```python
qml.BasisEmbedding([0,1,0,0], wires = range(4))
```
because 0100 is the number 4 in binary (note that PennyLane uses the convention $|q_0,q_1,\dots,q_{N-1}\rangle$ where $q_0$ is the most significant bit).

This feature have a lot of applications, for example for qRAMs where we could do things like this one:

```python
for i in range(16):
      qml.BasisEmbedding(i, wires = range(4))
     ### some stuff here
```

### Implementation

I'm using this functions to translate the integer to the list:

```python
def list_d(num, n_wires):

    mods = []
    while num != 0 or len(mods) != n_wires:
        mods.insert(0, num % 2)
        num //= 2

    return mods
```

```
list_d(4,5)
>>> [0,0,1,0,0]
```

Probably incorporating this routine will be enough. However, some checks should be added because if num > 2^n_wires, the code will fail.


### How important would you say this feature is?

1: Not important. Would be nice to have.

### Additional information

Make sure that the order of the list is the same as Pennylane. 
There are places where it is written from top to bottom and vice versa.

Pull request:
pass int in `BasisEmbedding`
Hi, this will close #2594.

*used if-else in the list instead of casting because it's faster.

Patch:
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 4630e2225..1a65e5b7e 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -104,6 +104,9 @@
 * Sparse Hamiltonians representation has changed from COOrdinate (COO) to Compressed Sparse Row (CSR) format. The CSR representation is more performant for arithmetic operations and matrix vector products. This change decreases the `expval()` calculation time, for `qml.SparseHamiltonian`, specially for large workflows. Also, the CRS format consumes less memory for the `qml.SparseHamiltonian` storage.
 [(#2561)](https://github.com/PennyLaneAI/pennylane/pull/2561)
 
+* `BasisEmbedding` can accept an int as argument instead of a list of bits (optionally). Example: `qml.BasisEmbedding(4, wires = range(4))` is now equivalent to `qml.BasisEmbedding([0,1,0,0], wires = range(4))` (because 4=0b100). 
+  [(#2601)](https://github.com/PennyLaneAI/pennylane/pull/2601)
+
 <h3>Breaking changes</h3>
 
 * The `qml.queuing.Queue` class is now removed.
diff --git a/pennylane/templates/embeddings/basis.py b/pennylane/templates/embeddings/basis.py
index 09df0c603..fec97bf68 100644
--- a/pennylane/templates/embeddings/basis.py
+++ b/pennylane/templates/embeddings/basis.py
@@ -23,8 +23,8 @@ from pennylane.wires import Wires
 class BasisEmbedding(Operation):
     r"""Encodes :math:`n` binary features into a basis state of :math:`n` qubits.
 
-    For example, for ``features=np.array([0, 1, 0])``, the quantum system will be
-    prepared in state :math:`|010 \rangle`.
+    For example, for ``features=np.array([0, 1, 0])`` or ``features=2`` (binary 10), the
+    quantum system will be prepared in state :math:`|010 \rangle`.
 
     .. warning::
 
@@ -72,6 +72,10 @@ class BasisEmbedding(Operation):
 
     def __init__(self, features, wires, do_queue=True, id=None):
 
+        if isinstance(features, int):
+            bin_string = f"{features:b}".zfill(len(wires))
+            features = [1 if d == "1" else 0 for d in bin_string]
+
         wires = Wires(wires)
         shape = qml.math.shape(features)
 
@@ -80,7 +84,9 @@ class BasisEmbedding(Operation):
 
         n_features = shape[0]
         if n_features != len(wires):
-            raise ValueError(f"Features must be of length {len(wires)}; got length {n_features}.")
+            raise ValueError(
+                f"Features must be of length {len(wires)}; got length {n_features} (features={features})."
+            )
 
         features = list(qml.math.toarray(features))
 


Test patch:
diff --git a/tests/templates/test_embeddings/test_basis.py b/tests/templates/test_embeddings/test_basis.py
index 3d00d87db..f34f9ba83 100644
--- a/tests/templates/test_embeddings/test_basis.py
+++ b/tests/templates/test_embeddings/test_basis.py
@@ -76,7 +76,20 @@ class TestDecomposition:
 class TestInputs:
     """Test inputs and pre-processing."""
 
-    @pytest.mark.parametrize("x", [[0], [0, 1, 1]])
+    @pytest.mark.parametrize(
+        ("feat","wires","expected"),
+        [(7, range(3), [1, 1, 1]), (2, range(4), [0, 0, 1, 0]), (8, range(5), [0, 1, 0, 0, 0])],
+    )
+    def test_features_as_int_conversion(self, feat, wires, expected):
+        """checks conversion from features as int to a list of binary digits
+           with length = len(wires)"""
+
+        assert (
+            qml.BasisEmbedding(features=feat, wires=wires).hyperparameters["basis_state"]
+            == expected
+        )
+
+    @pytest.mark.parametrize("x", [[0], [0, 1, 1], 4])
     def test_wrong_input_bits_exception(self, x):
         """Checks exception if number of features is not same as number of qubits."""