The use of Fake backend will make Amplitude Encoding unusable

Hello! If applicable, put your complete code example down below. Make sure that your code:

  • is 100% self-contained — someone can copy-paste exactly what is here and run it to
    reproduce the behaviour you are observing
  • includes comments
# Put code here
```backend = FakeAlmadenV2()
noise_model = NoiseModel.from_backend(backend)
dev = qml.device("qiskit.aer", wires=n_qubits, noise_model=noise_model)

def qnode(inputs, w000, w001, w002, w003,
          w016, w017, w018, w019,
          w032, w033, w034, w035,
          w100, w101, w102, w103,
          w116, w117, w118, w119,
          w132, w133, w134, w135):
    qml.AmplitudeEmbedding(features=inputs, wires=range(4), normalize=True)
    qml.RX(w000, wires=0)
    qml.RX(w001, wires=1)
    qml.RX(w002, wires=2)
    qml.RX(w003, wires=3)

    qml.RZ(w016, wires=0)
    qml.RZ(w017, wires=1)
    qml.RZ(w018, wires=2)
    qml.RZ(w019, wires=3)

    qml.CNOT(wires=[0, 1])
    qml.CNOT(wires=[1, 2])
    qml.CNOT(wires=[2, 3])
    qml.CNOT(wires=[3, 0])

    return (qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliZ(3)))


If you want help with diagnosing an error, please put the full error message below:

Put full error message here

qiskit.exceptions.QiskitError: ‘Sum of amplitudes-squared does not equal one.’

And, finally, make sure to include the versions of your packages. Specifically, show us the output of `qml.about()`. 
Platform info:           Linux-5.15.0-72-generic-x86_64-with-debian-bullseye-sid
Python version:          3.7.0
Numpy version:           1.21.6
Scipy version:           1.7.3
Installed devices:
- lightning.gpu (PennyLane-Lightning-GPU-0.26.0)
- lightning.qubit (PennyLane-Lightning-0.26.0)
- default.gaussian (PennyLane-0.26.0)
- default.mixed (PennyLane-0.26.0)
- default.qubit (PennyLane-0.26.0)
- default.qubit.autograd (PennyLane-0.26.0)
- default.qubit.jax (PennyLane-0.26.0)
- default.qubit.tf (PennyLane-0.26.0)
- default.qubit.torch (PennyLane-0.26.0)
- default.qutrit (PennyLane-0.26.0)
- qiskit.aer (PennyLane-qiskit-0.24.0)
- qiskit.basicaer (PennyLane-qiskit-0.24.0)
- qiskit.ibmq (PennyLane-qiskit-0.24.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.24.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.24.0)
- ionq.qpu (PennyLane-IonQ-0.23.0)
- ionq.simulator (PennyLane-IonQ-0.23.0)
- projectq.classical (PennyLane-PQ-0.17.0)
- projectq.ibm (PennyLane-PQ-0.17.0)
- projectq.simulator (PennyLane-PQ-0.17.0)
None

Hey @Duckling! Welcome to the forum :rocket:

Can you please provide a full example that gives you the error you’re seeing? Right now there’s just a QNode and nothing being executed. Make sure to copy-paste exactly what you’re running on your machine so that I can try to replicate it :slight_smile:

Traceback (most recent call last):
File “/mnt/data2/wrh/QSteal/Four class/Noisy_Cloud_Ampli_Circuit2.py”, line 211, in
test(model, device, test_loader)
File “/mnt/data2/wrh/QSteal/Four class/Noisy_Cloud_Ampli_Circuit2.py”, line 193, in test
outputs = model(images)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 1130, in _call_impl
return forward_call(*input, **kwargs)
File “/mnt/data2/wrh/QSteal/Four class/Noisy_Cloud_Ampli_Circuit2.py”, line 151, in forward
x = self.qlayer(x)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 1130, in _call_impl
return forward_call(*input, **kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 309, in forward
reconstructor = [self.forward(x) for x in torch.unbind(inputs)]
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 309, in
reconstructor = [self.forward(x) for x in torch.unbind(inputs)]
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 313, in forward
return self._evaluate_qnode(inputs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 328, in _evaluate_qnode
return self.qnode(**kwargs).type(x.dtype)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnode.py”, line 668, in call
**self.execute_kwargs,
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/execution.py”, line 444, in execute
tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_diff=max_diff, mode=_mode
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/torch.py”, line 248, in execute
return ExecuteTapes.apply(kwargs, *parameters)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/torch.py”, line 85, in forward
res, ctx.jacs = ctx.execute_fn(ctx.tapes, **ctx.gradient_kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/execution.py”, line 197, in wrapper
res = fn(execution_tapes.values(), **kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/execution.py”, line 122, in fn
return original_fn(tapes, **kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/contextlib.py”, line 74, in inner
return func(*args, **kwds)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 444, in batch_execute
compiled_circuits = self.compile_circuits(circuits)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 433, in compile_circuits
self.create_circuit_object(circuit.operations, rotations=circuit.diagonalizing_gates)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 246, in create_circuit_object
applied_operations = self.apply_operations(operations)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 307, in apply_operations
gate = mapped_operation(*par)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/qiskit/extensions/quantum_initializer/initializer.py”, line 57, in init
self._stateprep = StatePreparation(params, num_qubits)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/qiskit/circuit/library/data_preparation/state_preparation.py”, line 99, in init
num_qubits = self._get_num_qubits(num_qubits, params)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/qiskit/circuit/library/data_preparation/state_preparation.py”, line 202, in _get_num_qubits
raise QiskitError(“Sum of amplitudes-squared does not equal one.”)
qiskit.exceptions.QiskitError: ‘Sum of amplitudes-squared does not equal one.’

Hello, it’s my first time to use the support. Some operations are not very familiar. :face_exhaling:
The following is my error output:

Traceback (most recent call last):
File “/mnt/data2/wrh/QSteal/Four class/Noisy_Cloud_Ampli_Circuit2.py”, line 211, in
test(model, device, test_loader)
File “/mnt/data2/wrh/QSteal/Four class/Noisy_Cloud_Ampli_Circuit2.py”, line 193, in test
outputs = model(images)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 1130, in _call_impl
return forward_call(*input, **kwargs)
File “/mnt/data2/wrh/QSteal/Four class/Noisy_Cloud_Ampli_Circuit2.py”, line 151, in forward
x = self.qlayer(x)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 1130, in _call_impl
return forward_call(*input, **kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 309, in forward
reconstructor = [self.forward(x) for x in torch.unbind(inputs)]
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 309, in
reconstructor = [self.forward(x) for x in torch.unbind(inputs)]
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 313, in forward
return self._evaluate_qnode(inputs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnn/torch.py”, line 328, in _evaluate_qnode
return self.qnode(**kwargs).type(x.dtype)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/qnode.py”, line 668, in call
**self.execute_kwargs,
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/execution.py”, line 444, in execute
tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_diff=max_diff, mode=_mode
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/torch.py”, line 248, in execute
return ExecuteTapes.apply(kwargs, *parameters)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/torch.py”, line 85, in forward
res, ctx.jacs = ctx.execute_fn(ctx.tapes, **ctx.gradient_kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/execution.py”, line 197, in wrapper
res = fn(execution_tapes.values(), **kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane/interfaces/execution.py”, line 122, in fn
return original_fn(tapes, **kwargs)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/contextlib.py”, line 74, in inner
return func(*args, **kwds)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 444, in batch_execute
compiled_circuits = self.compile_circuits(circuits)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 433, in compile_circuits
self.create_circuit_object(circuit.operations, rotations=circuit.diagonalizing_gates)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 246, in create_circuit_object
applied_operations = self.apply_operations(operations)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/pennylane_qiskit/qiskit_device.py”, line 307, in apply_operations
gate = mapped_operation(*par)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/qiskit/extensions/quantum_initializer/initializer.py”, line 57, in init
self._stateprep = StatePreparation(params, num_qubits)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/qiskit/circuit/library/data_preparation/state_preparation.py”, line 99, in init
num_qubits = self._get_num_qubits(num_qubits, params)
File “/home/ruhan/anaconda3/envs/Pytorch/lib/python3.7/site-packages/qiskit/circuit/library/data_preparation/state_preparation.py”, line 202, in _get_num_qubits
raise QiskitError(“Sum of amplitudes-squared does not equal one.”)
qiskit.exceptions.QiskitError: ‘Sum of amplitudes-squared does not equal one.’

Can you share your code that you’re running?

Hey @Duckling! I see that you deleted your message. Were you able to solve your issue? If not, what I was able to copy-paste before you deleted your code seems to be missing test_loader.

Also, this is probably unrelated to the error you’re getting, but you should consider updating to v0.30 of Pennylane! :smiley:

1 Like