I am trying to solve the first exercise but it looks like I am having an issue implementing the right state. There is my code:
num_wires = 3
dev = qml.device('default.qubit', wires=num_wires)
@qml.qnode(dev)
def make_basis_state(basis_id):
"""Produce the 3-qubit basis state corresponding to |basis_id>.
Note that the system starts in |000>.
Args:
basis_id (int): An integer value identifying the basis state to construct.
Returns:
array[complex]: The computational basis state |basis_id>.
"""
##################
lis=[i for i in range(-basis_id, basis_id+1)]
lis_1 = []
for i in lis:
a=np.binary_repr(i,width=3)
lis_1.append(a)
list_2 = []
for j in range(len(lis_1)):
string_list= list(lis_1[j])
list_2.append(list(map(int, string_list)))
#del list_2[3]
for k in list_2:
qml.BasisEmbedding(np.array(k), wires=range(basis_id))
#quantum_state = circuit(data_list)
##################
# CREATE THE BASIS STATE
return qml.state()
basis_id = 3
print(f"Output state = {make_basis_state(basis_id)}")
And the error that I get is:
Error: Features must be of length 0; got length 3 (features=[0 0 0]).
And, finally, the output is:
Output state = [0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j]
I would be delighted to receive y’all propositions on how to solve it.