Skip to content

Commit

Permalink
add qiskit-symb as an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gcattan committed Sep 29, 2024
1 parent 5440d47 commit 0a6d6ed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,20 @@ To check the installation, open a python shell and type:
import pyriemann_qiskit
```

To enable Qiskit GPU optimization when using quantum simulation, run:
To enable Qiskit GPU optimization (for Linux) when using quantum simulation, run:

```
pip install .[optim_linux]
```

To use symbolic quantum simulation, run:

```
pip install .[optim]
```

Which will enable [qiskit-symb](https://github.com/SimoneGasperini/qiskit-symb) integration.

Note, Qiskit only provide binaries for Linux. For other platforms, or if you want to
enable specific NVIDIA optimization for quantum, you need to build the binary
[yourself](https://github.com/Qiskit/qiskit-aer/blob/main/CONTRIBUTING.md#building-with-gpu-support).
Expand Down
1 change: 1 addition & 0 deletions pyriemann_qiskit/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def _init_algo(self, n_features):
self.gen_feature_map,
self._quantum_instance,
self.use_fidelity_state_vector_kernel,
not self.pegasos
)
if self.pegasos:
self._log("[Warning] `gamma` is not supported by PegasosQSVC")
Expand Down
23 changes: 18 additions & 5 deletions pyriemann_qiskit/utils/quantum_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
FidelityStatevectorKernel,
FidelityQuantumKernel,
)
from qiskit_symb.quantum_info import Statevector
try:
from qiskit_symb.quantum_info import Statevector
QISKIT_SYMB=True
except:
QISKIT_SYMB=False



class SymbFidelityStatevectorKernel:
Expand Down Expand Up @@ -209,14 +214,19 @@ def get_device(provider, min_qubits):


def get_quantum_kernel(
feature_map, gen_feature_map, quantum_instance, use_fidelity_state_vector_kernel
feature_map,
gen_feature_map,
quantum_instance,
use_fidelity_state_vector_kernel,
use_qiskit_symb
):
"""Get a quantum kernel
Return an instance of FidelityQuantumKernel or
FidelityStatevectorKernel (in the case of a simulation).
For simulation with a small number of qubits (< 9), qiskit-symb is used.
For simulation with a small number of qubits (< 9), and `use_qiskit_symb` is True,
qiskit-symb is used.
Parameters
----------
Expand All @@ -225,7 +235,10 @@ def get_quantum_kernel(
quantum_instance: BaseSampler
A instance of BaseSampler.
use_fidelity_state_vector_kernel: boolean
if True, use a FidelitystatevectorKernel for simulation.
If True, use a FidelitystatevectorKernel for simulation.
use_qiskit_symb: boolean
This flag is used only if qiskit-symb is installed.
If True and the number of qubits < 9, then qiskit_symb is used.
Returns
-------
Expand All @@ -242,7 +255,7 @@ def get_quantum_kernel(
quantum_instance._backend, AerSimulator
):
# For simulation:
if feature_map.num_qubits <= 9:
if QISKIT_SYMB and feature_map.num_qubits <= 9 and use_qiskit_symb:
# With a small number of qubits, let's use qiskit-symb
# See:
# https://medium.com/qiskit/qiskit-symb-a-qiskit-ecosystem-package-for-symbolic-quantum-computation-b6b4407fa705
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ docplex>=2.21.207
firebase_admin==6.5.0
tqdm
pandas
qiskit-symb

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
'scikit-learn==1.5.1',
'tqdm',
'pandas',
'qiskit-symb'
],
extras_require={'docs': [
'sphinx-gallery',
Expand All @@ -65,6 +64,7 @@
'tests': ['pytest', 'seaborn', 'flake8', 'mne', 'pooch'],
# GPU optimization not available on all platform.
# See https://github.com/Qiskit/qiskit-aer/issues/929#issuecomment-691716936
'optim': ['qiskit-aer-gpu==0.15.0']},
'optim': ['qiskit-symb'],
'optim_linux': ['qiskit-aer-gpu==0.15.0']},
zip_safe=False,
)

0 comments on commit 0a6d6ed

Please sign in to comment.