I'm using qiskit_ionq API for simulating quantum circuits on ionq devices. Currently, I'm using the ionq_simulator
backend, but I think it performs noiseless simulations.
Is there any possibility of introducing noise in the simulations?
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.
Sign up to join this communityI'm using qiskit_ionq API for simulating quantum circuits on ionq devices. Currently, I'm using the ionq_simulator
backend, but I think it performs noiseless simulations.
Is there any possibility of introducing noise in the simulations?
At the moment, the only supported backends are ionq_qpu
and ionq_simulator
, and, as you say, the ionq_simulator
is noise-free.
As the ionq_simulator
does not accept a noise model, the best way to test with noise is to either create your own noise model and test locally, or pay to run on a QPU.
You can mimic the noise on an IonQ QPU if you know the gate fidelity. For example, Table 1 on this blog post gives you 1- and 2-qubit gate errors of 0.0005 and 0.0040 for the Aria QPU (at the time of writing). The vast majority of the noise you'll see on the device is from depolarizing errors, so we can pass them in directly. So:
If you have a Qiskit QuantumCircuit
called circuit
you can do something like:
from qiskit.compiler import transpile
from qiskit.providers.aer.noise import depolarizing_error, NoiseModel
one_qubit_gates = ["x", "h", "s", "sdg", "ry", "rz"]
two_qubit_gates = ["cx"]
basis_gates = one_qubit_gates + two_qubit_gates
# transpile to the gate set
transpiled_circuit = transpile(circuit, basis_gates=basis_gates)
one_qubit_depolarization_error = 0.0005 # IonQ Aria 1Q fidelity
two_qubit_depolarization_error = 0.0040 # IonQ Aria 2Q fidelity
noise_model = NoiseModel()
noise_model.add_all_qubit_quantum_error(
depolarizing_error(one_qubit_depolarization_error, 1), one_qubit_gates
)
noise_model.add_all_qubit_quantum_error(
depolarizing_error(two_qubit_depolarization_error, 2), two_qubit_gates
)
The reason we do the transpilation is to ensure that each gate in the circuit gets a noise model applied. If the gate isn't listed, it won't have any noise!
So when you define your quantum instance, you can pass in the noise_model
.
from qiskit import Aer
from qiskit.utils import QuantumInstance
shots = 1024 # or whatever
backend = Aer.get_backend("qasm_simulator") # local backend
quantum_instance = QuantumInstance(backend=backend, shots=shots, noise_model=noise_model)
You can use the IonQ rest API to perform a simulation with noise as IonQ explains here. I think that you will need to get an API-KEY via a google account, but simulations are free, so it shouldn't cost you money. IonQ detail here the different services you can get via the different cloud providers.
You may use this python code snippet to send the JSON job
import requests
def submit_job(json_file):
headers = {
'Authorization': f'apiKey {API_KEY}',
'Content-Type': 'application/json',
}
with open(json_file) as f:
data = f.read().replace('\n', '').replace('\r', '').encode()
response = requests.post('https://api.ionq.co/v0.3/jobs', headers=headers, data=data)
return response
And can use this to create the circuit JSON format, which you will later add to the master JSON job. You can find such JSON template in IonQ's explanation above.
import cirq_ionq as ionq
s = ionq.Serializer()
body = s.serialize(full_circ).body
to_save = str(body).replace("'", '"')
with open(file_full_path, 'w') as f:
f.write(to_save)
You can use a noise_model
backend option to use a noisy simulator:
from qiskit import QuantumCircuit
import qiskit_ionq
provider = qiskit_ionq.IonQProvider()
backend = provider.get_backend("ionq_simulator")
backend.set_options(noise_model="harmony") # or any QPU
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
job = backend.run(qc)
print(job.result().get_counts())
# {'00': 514, '01': 34, '10': 26, '11': 450}
You can check the API Docs for all QPUs to use as noise models.
I think you are looking for these: