NOT working (HamLib)

Hi,

I used the original example (HamLib: Max-3-SAT ( HamLib: Max-3-SAT )) but made a minor change, specifically replacing qml.BasisStatePreparation with qml.BasisState.

However, the example code doesn’t work.

# Put code here
import pennylane as qml
from pennylane import numpy as np

[ds] = qml.data.load("hamlib-max-3-sat")
ham = ds.hamiltonians[1]

dev = qml.device("default.qubit", wires=4)

@qml.qnode(dev)
def circuit(basis_state):
    qml.BasisState(basis_state, wires=range(4))
    return qml.expval(ham)

# clauses satisfied when all variables are false
circuit([0,0,0,0]) # output: array(7.)
# clauses satisfied when some variables are true
circuit([0,0,1,1]) # output: array(5.)

If you want help with diagnosing an error, please put the full error message below:

# Put full error message here
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[6], line 2
      1 [ds] = qml.data.load("hamlib-max-3-sat")
----> 2 ham = ds.hamiltonians[1]
      4 dev = qml.device("default.qubit", wires=4)
      6 @qml.qnode(dev)
      7 def circuit(basis_state):

File c:\Users\ABC\AppData\Local\Programs\Python\Python313\Lib\site-packages\pennylane\data\attributes\list.py:112, in DatasetList.__getitem__(self, index)
    109     index = len(self) + index
    111 if not 0 <= index < len(self):
--> 112     raise IndexError(index)
    114 return self._mapper[str(index)].get_value()

IndexError: 1

And, finally, make sure to include the versions of your packages. Specifically, show us the output of qml.about().

Name: PennyLane
Version: 0.41.1
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing-extensions
Required-by: PennyLane-Catalyst, PennyLane-qiskit, PennyLane_Lightning

Platform info: macOS-26.1-arm64-arm-64bit
Python version: 3.12.8
Numpy version: 2.0.2
Scipy version: 1.13.0
Installed devices:

  • lightning.qubit (PennyLane_Lightning-0.41.0)
  • nvidia.custatevec (PennyLane-Catalyst-0.9.0)
  • nvidia.cutensornet (PennyLane-Catalyst-0.9.0)
  • oqc.cloud (PennyLane-Catalyst-0.9.0)
  • softwareq.qpp (PennyLane-Catalyst-0.9.0)
  • default.clifford (PennyLane-0.41.1)
  • default.gaussian (PennyLane-0.41.1)
  • default.mixed (PennyLane-0.41.1)
  • default.qubit (PennyLane-0.41.1)
  • default.qutrit (PennyLane-0.41.1)
  • default.qutrit.mixed (PennyLane-0.41.1)
  • default.tensor (PennyLane-0.41.1)
  • null.qubit (PennyLane-0.41.1)
  • reference.qubit (PennyLane-0.41.1)
  • qiskit.aer (PennyLane-qiskit-0.41.0.post0)
  • qiskit.basicaer (PennyLane-qiskit-0.41.0.post0)
  • qiskit.basicsim (PennyLane-qiskit-0.41.0.post0)
  • qiskit.remote (PennyLane-qiskit-0.41.0.post0)

Hi @HYW ,

Thank you very much for pointing this out!

I see that you’re using an older version of PennyLane, so I would recommend upgrading to the latest one, but even then the problem persists. I’m not sure what’s happening with the dataset but I’ve informed our team and we should be able to get back to you on this next week.

Thanks again for making us aware of this!

Hi @HYW nice catch, it looks like we have a bad URL somewhere and the dataset you’re downloading is empty. We’ll get a fix up for this as soon as possible.

But in the meantime you can try downloading the actual 4.8 GB dataset by clicking this link. Then manually opening the file via qml.data.Dataset.open as explained in the documentation.

This should be working now, the correct dataset is uploaded to the URL used by qml.data.load("hamlib-max-3-sat").

It may take some time until the CloudFront cache refreshes and the correct dataset is given.

Let us know if you continue to have issues.

1 Like

Hi @Diego and @HYW ,

I can confirm that the code below (which is almost the same as the example in the hamlib dataset page) now works.

The main difference is that in the dataset page we still have BasisStatePreparation instead of BasisState so we should change that in that page @Diego.

import pennylane as qml
from pennylane import numpy as np

[ds] = qml.data.load("hamlib-max-3-sat")
ham = ds.hamiltonians[1320]

dev = qml.device("default.qubit", wires=4)

@qml.qnode(dev)
def circuit(basis_state):
    qml.BasisState(basis_state, wires=range(4))
    return qml.expval(ham)

# clauses satisfied when all variables are false
circuit([0,0,0,0]) # output: array(7.)
# clauses satisfied when some variables are true
circuit([0,0,1,1]) # output: array(5.)

@HYW thanks for bringing this issue to our attention and let us know if you have any additional feedback!

Thanks @CatalinaAlbornoz

The main difference is that in the dataset page we still have BasisStatePreparation instead of BasisState so we should change that in that page

Just opened a pull request that fixes this.

1 Like

Thank you Diego and Catalina!

The website is updated BasisStatePreparationBasisState

All issues should be fixed now :slight_smile:

1 Like

Awesome!! Thanks Diego!