Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

[QI2-1096] pennylane device implementation #7

Merged
merged 9 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ and [hardware backends](https://www.quantum-inspire.com/kbase/hardware-backends/

### Emulator backends

* `QX single-node simulator` - Quantum Inspire emulator run on a commodity cloud-based server, with 4GB RAM. It has a fast turn-around time for simulations up to 26 qubits. For basic users, the commodity cloud-based server will be sufficient.
* `QX emulator` - Quantum Inspire emulator run on a commodity cloud-based server, with 4GB RAM. It has a fast turn-around time for simulations up to 26 qubits. For basic users, the commodity cloud-based server will be sufficient.

## Installation

Expand All @@ -44,6 +44,32 @@ pip install -e pluginpath

where `pluginpath` is the location of the plugin. It will then be accessible via PennyLane.

## Submitting a Pennylane Circuit

Once a backend has been specified, it may be used to submit circuits.
For example, running a Bell State:

```python
import pennylane as qml
from pennylane_quantuminspire2.qi_device import QI2Device

# Obtain a specific backend by name (get_backends() returns all)
backend = QI2Device.get_backend("Spin")

# create the pennylane device from the desired backend
device = QI2Device(backend=backend)

# Create the quantum function
@qml.qnode(device=device)
def quantum_function():
qml.Hadamard(wires=[0])
return qml.expval(qml.PauliX(wires=[0]))

# Run the quantum funciont
print(quantum_function())

```

## Contributing

...
Expand All @@ -65,4 +91,4 @@ tox -e test
[Apache License 2.0].

[quantum inspire]: https://www.quantum-inspire.com/
[apache license 2.0]: https://github.com/qiskit-partners/qiskit-ionq/blob/master/LICENSE.txt
[apache license 2.0]: https://github.com/PennyLaneAI/pennylane/blob/master/LICENSE
21 changes: 21 additions & 0 deletions pennylane_quantuminspire2/qi_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Any, Optional, Sequence

from pennylane_qiskit import RemoteDevice
from qiskit_quantuminspire.qi_backend import QIBackend
from qiskit_quantuminspire.qi_provider import QIProvider


class QI2Device(RemoteDevice): # type: ignore[misc]

_qi_provider = QIProvider()

def __init__(self, backend: QIBackend, **kwargs: Any) -> None:
super().__init__(wires=backend.num_qubits, backend=backend, shots=backend.default_shots, **kwargs)

@classmethod
def backends(cls) -> Sequence[QIBackend]:
return cls._qi_provider.backends() # type: ignore[no-any-return]

@classmethod
def get_backend(cls, name: Optional[str] = None, id: Optional[int] = None) -> QIBackend:
return cls._qi_provider.get_backend(name, id)
Loading