Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [pennylane]

PennyLane is a cross-platform Python library for quantum machine learning, automatic differentiation, and optimization of hybrid quantum-classical computations.

Filter by
Sorted by
Tagged with
1 vote
1 answer
55 views

How to correctly compute expectation value in QAOA?

In QAOA after prepating $|\psi(\gamma, \beta) \rangle$, expectation value $\langle \psi(\gamma, \beta)|H_c|\psi(\gamma, \beta) \rangle$ is computed. In tutorials, I see two approaches to this ...
Oleksii's user avatar
  • 21
1 vote
0 answers
25 views

qml.StronglyEntanglingLayers custom CNOT placement

The qml.StronglyEntanglingLayers function works great for what I need. However, I'd like to modify so that for each layer, only the first qubit is the control and the rest are targets of the control ...
TuktukTaxi's user avatar
2 votes
0 answers
33 views

IBMBackendValueError: number of circuits exceeds the maximum for this backend, 300

I am trying to run the QAOA on the IBMQ device. The QAOA circuit consists of 6 qubits, two layers. The number of total trainable parameters for the QAOA circuit is 14. The toy code is as follows: <...
Yang Qian's user avatar
2 votes
0 answers
32 views

Value error in variational quantum circuits

I am working on a project to find a unitary gate that arrives at a specific density matrix at the end. The circuit construct is shown below: ...
JiQing's user avatar
  • 35
0 votes
0 answers
26 views

How to convert DensityMatrixMP object in PennyLane to a numpy array?

I am trying to get the density matrix from the Pennylane code qml.density_matrix([0]). However, it seems that the return type is ...
JiQing's user avatar
  • 35
2 votes
0 answers
27 views

Quantum Convolutional Neural Network not producing gradients

I am trying to bulid a quantum convolutional neural network for image classification with Pennylane and Keras but the model isn't training and I keep getting the warning: WARNING:tensorflow:Gradients ...
Umm's user avatar
  • 21
1 vote
1 answer
56 views

Pennylane and Qutrit quantum circuit matrix representation bug

I want to find the operator that describes this qutrit quantum circuit. Where a TSub, some TRZ rotations and a TAdd are applied to 2 quitrits. I am using Pennylane 0.34.0. This is the code: ...
Daniele Trisciani's user avatar
1 vote
0 answers
40 views

Pennylane Spectral gap for Molecules

Pennylane's dataset has a lot of systems, including Quantum Chemistry molecules. Can I extract the spectral gap of the molecule from the dataset (assuming it contains the number). In the case that ...
Zee's user avatar
  • 391
0 votes
0 answers
24 views

Qnode model gradient of inputs (not parameters!) question

I am trying to use qml to do physics informed quantum machine learning within Tensorflow. I know with TF, to get derivatives of the network's inputs (df/dx, for example), you can use with tf....
Corey's user avatar
  • 127
1 vote
1 answer
127 views

Is there any library to create a uniformly random unitary matrix?

Is there any library to create a random special unitary $SU(N)$ that generates from Haar distribution? I understand in PennyLane there is qml.SpecialUnitary ...
Sudhir Kumar's user avatar
2 votes
1 answer
73 views

Optimizing a parametrized Quantum Circuit in batches does not decrease the cost function while unbatched optimization does

I want to optimize a variational quantum circuit to maximize the Hilbert-Schmidt Distance between the different classes of the UCI breast cancer data set. When I choose to use batched optimization, ...
jo87casi's user avatar
  • 141
0 votes
0 answers
30 views

Deriving a equation in "Data re-uploading for a universal quantum classifier" paper: U(phi1,phi2,phi3) U(x1,x2,x3) = U(theta + w *x)

In "Data re-uploading for a universal quantum classifier" paper the U(phi1,phi2,phi3) U(x1,x2,x3) is derived as U(theta + w *x) in compact state. How to derive the above equation ?
Aakash's user avatar
  • 1
0 votes
1 answer
177 views

Implementing a Quantum Recurrent Neural Network

I want to implement a Quantum Recurrent Neural Network and use it for time series forecasting. As a starting point, I chose to implement it using the architecture given in this paper: https://arxiv....
MoBlufiz's user avatar
0 votes
1 answer
122 views

Custom gate labels in PennyLane

I have a circuit with Rx gate, and I want to draw it with changed gate label. For example, instead of "RX" I want to have "custom_gate" written in the gate box. I have tried ...
Daniil Tarpanov's user avatar
1 vote
1 answer
126 views

How to save a hybrid Tensorflow and Pennylane model?

I implemented a hybrid model with Keras and Pennylane that looks like this: The quantum layer is basically a quantum circuit converted to a keras layer with the ...
Ryan Wang's user avatar
  • 247
1 vote
1 answer
124 views

Error loading saved hybrid quantum (pennylane + tensorflow keras) model: Unknown layer: 'KerasLayer'

I'm creating a hybrid model consisting of classical convolutional layers and a quantum output using Tensorflow. I can save the model in either .h5 or .keras format, but when I load them with the code <...
Ryan Wang's user avatar
  • 247
1 vote
0 answers
45 views

Classical Fisher Information for 1-qubit vs 2-qubit in PennyLane

I'm attempting to examine the Classical Fisher Information (CFI) for a 1-qubit system in comparison to a 2-qubit system.(PennyLane) I anticipated that the CFI for the 2-qubit system would be double(at ...
Donguk kim's user avatar
1 vote
0 answers
43 views

How can I pass multiple embeddings in my function?

I have a problem with my code. I would like to try multiple embeddings in my kernel (I'm using the adjoint method). My idea is to pass them to the function and use them depending on what I pass. ...
BootBootBoot's user avatar
2 votes
0 answers
100 views

Plotting Fisher Information using PennyLane

I made 2-qubit based circuit with post-selection method. Post-selection method is, Let $$ K = \begin{bmatrix} \sqrt{1-\gamma} & 0 \\ 0 & 1 \end{bmatrix}\,. $$ Then, $$ \rho_{\text{post-...
Donguk kim's user avatar
2 votes
0 answers
243 views

SLSQP optimizer(scipy.minimize) doesn't update parameters

I'm trying to find optimal parameters that minimize the cost functions. In cost function, it calculates the classical-fisher-information at a certain point(phi[0] = np.pi). Cost-function takes 3-...
Donguk kim's user avatar
2 votes
0 answers
95 views

Post-selection on pennylane

I want to do something like this: For a single-qubit Apply Hadamard -> Time_evolution -> Phase_damping -> Hadamard -> Post-selection -> Get CFI(classical fisher info) Density matrix ...
Donguk kim's user avatar
1 vote
1 answer
202 views

Create qnode with density matrix on pennylane

I'm using pennylane. What I want to do is Create a qnode with the 2*2 density matrix of a single qubit one. It has the parameter as phi Given density matrix: $$\...
Donguk kim's user avatar
2 votes
1 answer
130 views

Problems trying to plot the classical Fisher information with Pennylane

I'm working with pennylane. My goal is to plot CFI(Classical Fisher Information)with following quantum state. With the above equation I set gamma as 0. Then It becomes: If gamma is not equal to zero,...
Donguk kim's user avatar
1 vote
1 answer
73 views

Pennylane variational classifier demo - need for padding

In the variational classifier demo from Pennylane, the data loading is performed with ...
Sarvapriya Tripathi's user avatar
1 vote
1 answer
92 views

Implementing swap test on quantum register

I'm interested in implementing a controlled-swap operation on quantum registers. However, it appears that Qiskit's documentation primarily focuses on single qubits rather than registers. Could you ...
Yuval Idan's user avatar
1 vote
1 answer
82 views

Where is the input data X in the CV-QNN as presented in Pennylane?

I am referring to the tutorial of CV-QNN in Pennylane(Strawberry Fields). Each layer of CV-QNN can perform the operation below. Unlike other quantum neural network tutorials, where the input X and y ...
user48217's user avatar
1 vote
0 answers
283 views

Drawing circuit in pennylane

I am trying to draw the circuit in pennylane but even after my hours of trying I am completely unsuccessful. Below is my code. Any little guidance of yours can help me a lot. ...
Manu's user avatar
  • 63
1 vote
0 answers
60 views

Why VQE don't work?

I try to make VQE optimizer, but something goes wrong at the optimization stage, more precisely, the parameters do not change and there is no gradient descent. Please tell me what I'm doing wrong? <...
Сударь Сударев's user avatar
2 votes
1 answer
452 views

How can Mid-Circuit Measurements be performed in pennylane

I am trying to understand how to do mid circuit measurements in pennylane. As an example here is a simple preperation of a bell state: ...
Constantin Economides's user avatar
0 votes
0 answers
92 views

Data encoding (PennyLane) vs feature map (Qiskit)

I am new to quantum machine learning and I came across data encoding (in Pennylane) and feature map (in Qiskit). What are their similarities and differences?
sllama's user avatar
  • 1
2 votes
1 answer
203 views

Comparative analysis of TensorFlow-Quantum, Pennylane, and Qiskit, to implement quantum CNNs

I am currently working on a project wherein I have to implement a Quantum Convolutional Neural Network. The best options for NISQ devices are hybrid algorithms, so I will try integrating quantum ...
Chan's user avatar
  • 131
0 votes
0 answers
26 views

Ensemble classification with Rigetti and Qiskit devices : Params.npy

I want ask how the params.npy variable were obtained? It would be great if you provide the codes for my better understanding. ...
Mas Dim's user avatar
1 vote
1 answer
65 views

Qubits are drawn multiple times in circuit using pennylane

When I draw my circuits some qubits are drawn multiple times (see 'circuit 1'). Does this mean that 1) the circuit itself is the same as 'circuit 2' below or 2) do I have some bug in my code that ...
qcabepsilon's user avatar
1 vote
1 answer
252 views

Implementing time evolution gate for density matrix in PennyLane circuit

I am trying to create a circuit which time evolves a density matrix $\hat{\rho}$ with the parameterized Hamiltonian $$\hat{H}(\theta) = e^{(-i \sum_m \theta_m \Lambda_m)}\hat{H}_ce^{(i \sum_m \theta_m ...
Silly Goose's user avatar
1 vote
0 answers
111 views

What is an initial state of a qubit in PennyLane?

I just started trying to use the PennyLane Python package. It seems like the default.qubit device initializes each wire as an up-spin qubit. However, I am not ...
Silly Goose's user avatar
1 vote
1 answer
116 views

Getting High cost function in code implementation of VQLS pennylane tutorial

I am currently trying to implement the tutorial in pennylane https://pennylane.ai/qml/demos/tutorial_vqls.html for very complex example in 3 Qubit and cost function is very high in spite of adding ...
Nithin Reddy Govindugari's user avatar
1 vote
1 answer
308 views

How does Pennylane compute expected values of single-qubit operators over real hardware?

Imagine I have a quantum circuit of n qubits and I want to measure the expected value of a single-qubit operator (let's say PauliZ) for each qubit. This is easily done in Pennylane with the following ...
Paul's user avatar
  • 70
1 vote
1 answer
258 views

How to visualize the resulting state vector using CVNeuralNetLayers and Lightning qubit device

I'm trying to learn how to use PennyLane's CVNeuralNetLayers. I wrote this code below but I am not able to use the resulting state of the circuit generated by this layer. I looked for examples in the ...
Luccas Marim's user avatar
1 vote
1 answer
318 views

pennylane:fidelity calculation after swap test between entagled states. Swap test issue

What I am trying to do is first take an image and encode it into quantum states, for this I have taken an image from the MNIST dataset and then reshaped it to (4,4) and now I wrote the following ...
Pratyush's user avatar
2 votes
2 answers
145 views

pennylane: How to carry out MB rotation without CB rotation?

I'm looking at this MBQC tutorial where there's an example that shows that a MB and CB single qubit rotations give the same result. CB version : ...
unknown's user avatar
  • 2,207
0 votes
2 answers
505 views

How to transform an Hamiltonian operator to a controlled gate (Hadamard test) in Pennylane?

I would like to perform an Hadamard test on a given Hamiltonian operator $\hat{H}$ acting on a 2-qubits system. For instance, suppose $\hat{H}$ can be decomposed into a ...
Constantin Economides's user avatar
1 vote
1 answer
159 views

How can one append a pre-defined quantum function (circuit) to another quantum function in Pennylane?

I want to use a pennylane quantum function that i created earlier somewhere else, again in a new function but have it applied to certain wires. The reason for this is, that I have a quantum circuit of ...
Constantin Economides's user avatar
1 vote
0 answers
99 views

Convert an integer to its basis state in Cirq

I am trying to implement Quantum Adder using QFT in Cirq. I previously did the same problem using Pennylane, in which I converted an integer into its Basis state using the BasisStatePreparation method ...
CuriousMind's user avatar
1 vote
0 answers
71 views

The loss function decreases, but the test accuracy is always 0.5

...
Ren-Xin Zhao's user avatar
1 vote
0 answers
34 views

How do we know what angle formula X1 is encoded into qml.MottonenStatePreparation?

Known that X1 is a quantum state, it is prepared by qml.MottonenStatePreparation. How do we know what angle formula X1 is encoded into qml.MottonenStatePreparation? can be interpreted in python code. ...
Ren-Xin Zhao's user avatar
1 vote
0 answers
78 views

Universality : Working with one qubit

I am working on the Pennylane's code camp problems and I'm stuck with the challenge 4. I am utterly clueless about this question, as in what is it asking from me, they provide us with a $2\times 2$ ...
Marco Puerto's user avatar
2 votes
1 answer
783 views

Pennylane: take qml.state of one function and use it as the initialization for another

In Pennylane, I created a function to set the initial parameters of my qubit, and then called qml.state() to return the output. I now want to feed this initialization into another circuit, but I'm not ...
TuktukTaxi's user avatar
2 votes
1 answer
166 views

Computing gradients in parallel with cost from probs (Pennylane-Braket)

Do circuits that measure probabilities instead of expectation values benefit from parallel execution? The Computing gradients in parallel with Amazon Braket tutorial shows how the multiple device ...
ryanhill1's user avatar
  • 2,503
1 vote
1 answer
230 views

Pennylane: Pennylane can not train the parameters of the problem

I asked this question in the Pennylane forum, but there was no reply for a long time, the link is: https://discuss.pennylane.ai/t/why-does-the-embedding-metric-learning-case-not-work/2211?u=rx1 The ...
Ren-Xin Zhao's user avatar
0 votes
1 answer
534 views

Difference between qiskit SPSA optimize and minimize in runtime program

I use this tutorial with pennylane-qiskit.vqe_runtime_runner to familiarize myself with qiskit runtime using pennylane. Thereby, I wonder: What is the difference between qiskit.algorithms.optimizers....
qcabepsilon's user avatar