Skip to content
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
11 changes: 6 additions & 5 deletions docs/install/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ sQUlearn requires a recent python3 (>=3.10) installation.
Additionally the following python packages are necessary: ::

bayesian-optimization>=1.4.3,<2,
dill>=0.3.4,
mapomatic>=0.10.0,
dill>=0.3.5,
mapomatic>=0.12.0,
networkx>=3.0,
numpy>=1.20,
numpy>=1.21,
pennylane>=0.34.0,
qiskit>=1.0.0,
qiskit-aer>=0.13.0,
qiskit-aer>=0.14.0.1,
qiskit-algorithms>=0.3.0,
qiskit-ibm-runtime>=0.20.0,
qiskit-ibm-runtime>=0.19.0,
qiskit-machine-learning>=0.7.0,
scipy>=1.8.0,
scikit-learn>=1.2.0,
sympy>=1.8,
tqdm>=4.1.0,
qulacs>=0.6.0,

Expand Down
30 changes: 19 additions & 11 deletions src/squlearn/util/optree/optree_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
)

QISKIT_SMALLER_1_2 = version.parse(qiskit_version) < version.parse("1.2.0")
QISKIT_SMALLER_2_0 = version.parse(qiskit_version) < version.parse("2.0.0")

from ..executor import (
QISKIT_SMALLER_2_0,
BaseSamplerV1,
BaseEstimatorV1,
BaseSamplerV2,
BaseEstimatorV2,
)

if QISKIT_SMALLER_1_2:

Expand All @@ -40,17 +47,18 @@ class BitArray:
else:

def _pauli_expval_with_variance(counts, paulis):
"""Dummy function for Qiskit >= 2.0."""
pass

"""Placeholder for Qiskit >= 2.0 when using legacy V1 sampler results.

from ..executor import (
QISKIT_SMALLER_2_0,
BaseSamplerV1,
BaseEstimatorV1,
BaseSamplerV2,
BaseEstimatorV2,
)
For Qiskit 2.x, `_pauli_expval_with_variance` from `backend_estimator` is no longer
available in the same form. If this function is reached, it indicates that a
legacy (V1) sampler result is being processed with Qiskit >= 2.0, which is not
supported by this compatibility layer.
"""
raise NotImplementedError(
"Support for evaluating expectation values via `_pauli_expval_with_variance` "
"with Qiskit >= 2.0 is not implemented. Ensure that you are not using a V1 "
"sampler with Qiskit 2.x, or update the code to use the V2 primitives."
)


def _check_tree_for_matrix_compatibility(element: Union[OpTreeNodeBase, OpTreeLeafBase]):
Expand Down
13 changes: 11 additions & 2 deletions src/squlearn/util/pennylane/pennylane_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,17 @@ def build_circuit_instructions(self, circuit: QuantumCircuit) -> tuple:
pennylane_gates_wires.extend(if_else_pennylane_gates_wires)

else:
# Add the condition None to the list of conditions
pennylane_conditions.append(None)
# Extract classical condition for non-if_else operations, if any
condition = None
if hasattr(op.operation, "condition") and op.operation.condition is not None:
classical_bits = op.operation.condition[0]
val = op.operation.condition[1]
if isinstance(classical_bits, Clbit):
bit_index = circuit.find_bit(classical_bits).index
else:
bit_index = [circuit.find_bit(b).index for b in classical_bits]
condition = (bit_index, val)
pennylane_conditions.append(condition)

# Get the parameter tuple of the operation
param_tuple = None
Expand Down
3 changes: 0 additions & 3 deletions tests/util/test_pennylane_circuit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Tests for PennyLaneCircuit, focusing on if_else gate handling."""

import pytest
import numpy as np
import pennylane as qml
import pennylane.numpy as pnp

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit import ParameterVector
Expand Down
Loading