QFT: no qml.transforms.decompose

I am following the tutorial on QFT (Intro to the Quantum Fourier Transform | PennyLane Demos). There is a command to expand the circuit to see the operators:
@partial(qml.transforms.decompose, max_expansion=1)
This line cannot run because “module ‘pennylane.transforms’ has no attribute ‘decompose’ .” Did you replace decompose with a different function?

Hi @mlowe ,

It’s nice to see that you’re exploring QFT. It’s an important topic.
We haven’t replaced qml.transforms.decompose, it’s actually still in the documentation.

I’m thinking you may not be using the latest PennyLane version. Are you using version v0.40? You can check by printing qml.about().

Hi Catalina,

I am using an older version of Pennylane (0.37.0). However even when I uninstall it and pip install Pennylane, I am not getting v0.40. How do I get the latest version?

Mary

Hi @mlowe ,

You should be able to do python -m pip install pennylane --upgrade.

If this doesn’t work I recommended that you create a new virtual environment to avoid any installation issues. (In fact it’s always a good practice.)

You can create a virtual environment with Conda and install PennyLane as follows:

  1. Install Miniconda following the instructions here.
  2. Open your terminal (mac) or command line (Windows).
  3. Create a new Conda environment with: conda create --name <name_of_your_environment> python=3.11
  4. Activate the environment with: conda activate <name_of_your_environment>
  5. Install PennyLane with: python -m pip install pennylane
  6. Install other useful packages with: python -m pip install jupyter matplotlib

Note that you will be installing 3 packages here: PennyLane, Jupyter, and Matplotlib. Also, note that where it says <name_of_your_environment> you can choose any name that you want.

In some rare cases this may not work. If that’s the case you can create a virtual environment with venv. I can share some instructions for venv if needed.

Let me know if this works for you!