# Quantum Hardware

**URL:** <https://discuss.pennylane.ai/t/quantum-hardware/3423>\
**Category:** PennyLane Help\
**Created:** [September 13, 2023, 3:52pm UTC](https://discuss.pennylane.ai/t/quantum-hardware/3423 "2023-09-13T15:52:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mass\_of\_15](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/mass_of_15/32/1430_2.png) [@mass\_of\_15](https://discuss.pennylane.ai/u/mass_of_15)\
**Post date:** [September 13, 2023, 3:52pm UTC](https://discuss.pennylane.ai/t/quantum-hardware/3423/1 "2023-09-13T15:52:07Z")

</div>

Hello, how do I run my script on quantum hardware in Pennylane? I saw that in the Pennylane Qiskit plugin, I have to write the backend:

```auto
import pennylane as qml
dev = qml.device('qiskit.ibmq', wires=2, backend='ibmq_qasm_simulator', ibmqx_token='XXX', hub='MYHUB', group='MYGROUP', project='MYPROJECT')

```

Is `ibmqx_token` from the above line my API token?  
So if I have access to `ibm_nairobi` from my IBM Account, can I just mention it?

Also, in Qiskit, I can transpile my circuit according to quantum hardware. In Pennylane-Qiskit Plugin, how to transpile the circuit?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 14, 2023, 6:27pm UTC](https://discuss.pennylane.ai/t/quantum-hardware/3423/2 "2023-09-14T18:27:04Z")

</div>

Hi @mass_of_15,

Thank you for your question!

Yes, `ibmqx_token` refers to your API token you can include it where it says `'XXX'`. Remember to never post this token online.

If you have access to `ibm_nairobi` you can choose it as your backend. So you would write `backend='ibm_nairobi'`.

When you refer to transpiling do you mean running on hardware? Or defining a specific coupling for the qubits which represent the hardware? We have a `transpile` function in PennyLane that allows you to define a specific connectivity. If you don’t need to specifically define this then you can just run your circuit on the device of your choice as-is. Below is an example.

```auto
import pennylane as qml
from pennylane import numpy as np
import qiskit_ibm_provider

# Save your API token
IBM_token = 'API Token'# Insert your token here
try:
    qiskit_ibm_provider.IBMProvider()
except:
    qiskit_ibm_provider.IBMProvider.save_account(token=IBM_token, overwrite=True)

# Define the backend that you will run on
b = "ibmq_qasm_simulator"
#b = "ibm_perth"

# Create your device
dev = qml.device(
    "qiskit.ibmq",
    wires=4,
    backend=b,
    shots = 10
)

# Create a QNode
@qml.qnode(dev)
@qml.transforms.transpile(coupling_map=[(0, 1), (1, 3), (3, 2), (2, 0)]) # Transpile it according to the layout of your circuit
def circuit(phi):
    qml.CNOT(wires=[0, 1])
    qml.CNOT(wires=[2, 3])
    qml.CNOT(wires=[1, 3])
    qml.CNOT(wires=[1, 2])
    qml.CNOT(wires=[2, 3])
    qml.CNOT(wires=[0, 3])
    qml.RX(phi,wires=0)
    return qml.probs(wires=[0, 1, 2, 3])

phi=np.array(0.1,requires_grad=True)

# Print your circuit
qml.draw_mpl(circuit)(phi);

```

Let me know if you have any further questions!

---

<div class="post-metadata">

**Author:** ![kevinkawchak](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kevinkawchak/32/1801_2.png) [@kevinkawchak](https://discuss.pennylane.ai/u/kevinkawchak)\
**Post date:** [September 15, 2023, 5:39am UTC](https://discuss.pennylane.ai/t/quantum-hardware/3423/3 "2023-09-15T05:39:46Z")

</div>

Hello @mass_of_15,

Also note, around November ibm\_nairobi is planned to be retired.

Reference:

> **[Slack is your productivity platform](https://qiskit.slack.com/?redir=%2Farchives%2FCJG2E9LQP%2Fp1690488935013449)**
>
> Slack is a new way to communicate with your team. It’s faster, better organized, and more secure than email.

---

<div class="post-metadata">

**Author:** ![mass\_of\_15](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/mass_of_15/32/1430_2.png) [@mass\_of\_15](https://discuss.pennylane.ai/u/mass_of_15)\
**Post date:** [September 15, 2023, 3:58pm UTC](https://discuss.pennylane.ai/t/quantum-hardware/3423/4 "2023-09-15T15:58:10Z")

</div>

Hi, when I meant `transpile`, I meant that let’s say I have the following circuit:

```auto
def CONVCircuit(phi, wires, i=0):
    """
    quantum convolution Node
    """
    # parameter
    theta = np.pi / 2

    qml.RX(phi[0] * np.pi, wires=0)
    qml.RX(phi[1] * np.pi, wires=1)
    qml.RX(phi[2] * np.pi, wires=2)
    qml.RX(phi[3] * np.pi, wires=3)

    qml.CRZ(theta, wires=[1, 0])
    qml.CRZ(theta, wires=[3, 2])
    qml.CRX(theta, wires=[1, 0])
    qml.CRX(theta, wires=[3, 2])
    qml.CRZ(theta, wires=[2, 0])
    qml.CRX(theta, wires=[2, 0])

    # Expectation value
    measurement = qml.expval(qml.PauliZ(wires=0))

    return measurement

```

Now if I choose `ibm_nairobi`, it doesn’t have all the connections between qubits. In this case, [2, 0], [2, 3] are the connections not possible in `ibm_nairobi`. So can it transpile like in Qiskit, which optimizes it for specific hardware?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 18, 2023, 3:36pm UTC](https://discuss.pennylane.ai/t/quantum-hardware/3423/5 "2023-09-18T15:36:13Z")

</div>

Hi @mass_of_15,

Thank you for clarifying! PennyLane uses the Qiskit transpiler under the hood so that your circuit can run on the specific backend of your choice. So since `ibm_nairobi` for example doesn’t have all connections, you can run your code as usual and PennyLane will make sure that it can run on this backend, no extra work from you 🙌.

However, if you want to use specific qubits within that device then you can use PennyLane’s [`transpile`](https://docs.pennylane.ai/en/stable/code/api/pennylane.transforms.transpile.html) function. In the example I showed before, I mentioned a coupling map, this is the information of which qubits are connected to which others. In my example I was specifying that qubit 0 and 1 were connected, 1 is connected with 3 and so on. Unless you want to use a specific set of qubits you shouldn’t need this.

Let me know if you have any further questions about this!
