amazon-braket / amazon-braket-default-simulator-python

Quantum program simulators that can run locally
https://amazon-braket-default-simulator-python.readthedocs.io/
Apache License 2.0
67 stars 22 forks source link

Support non-contiguous qubit indices #252

Closed speller26 closed 1 week ago

speller26 commented 1 month ago

Describe the feature you'd like The local simulator should support programs which use non-contiguous qubit indices, including cases where the qubit indices do not start from qubit 0.

Right now, the local simulator requires all qubits to be contiguous; in other words, an $n$-qubit circuit must use exactly the qubits $0, 1, \ldots n - 1$, without omitting any or including any additional qubits:

from braket.circuits import Circuit
from braket.devices import LocalSimulator

# Won't run
circuit = Circuit().h(2).cnot(2, 9)
LocalSimulator().run(circuit, shots=1000)

This constraint is unnecessary, and it would be worth modifying the default simulator implementation to allow arbitrary qubit indices, as in the above example.

How would this feature be used? Please describe. This would allow users to test circuits on the local simulator before running them, unmodified, on a QPU. For example, without this feature, a circuit meant to run on a QPU with indices $2, 4, 7$ would first need to be modified to use qubits $0, 1, 2$ before it can be tested locally. This feature would also help prevent bugs that arise from translating qubit indices.

Describe alternatives you've considered Qubits could be mapped manually, but this is unnecessarily complicated.

rmshaffer commented 1 month ago

PR https://github.com/amazon-braket/amazon-braket-default-simulator-python/pull/237 contains a possible approach to implementing this in the local simulator.

rmshaffer commented 1 month ago

Just a note @AbdullahKazi500 - issues for unitaryHACK should only be assigned after the corresponding PR is accepted and merged. Feel free to continue to work on the PR in the meantime!

AbdullahKazi500 commented 3 weeks ago

hi @rmshaffer And @speller26 is it okay to modify the simulator function while getting the results as in LocalSimulator().run(circuit, shots=1000) this line

AbdullahKazi500 commented 3 weeks ago

@speller26 made a PR to fix I am assuming that there might be something about instantiate or initialising the local simulator which has something to do with backend but lets see how it goes added the tests as well

speller26 commented 3 weeks ago

The idea of this issue is to modify the simulator (namely, the BaseLocalSimulator) to support non-contiguous qubits. Adding that support will automatically enable the LocalSimulator to run such circuits (rather than modifying the initializer of the LocalSimulator class).

WingCode commented 2 weeks ago

I would like to submit my PR.

AbdullahKazi500 commented 2 weeks ago

@WingCode Good work all the best