People who code: we want your input. Take the Survey

Hot answers tagged

6

Qiskit supports translating to different continuous basis sets by specifying the basis_gates in the transpile method. So in your case you could just do >>> from qiskit import QuantumCircuit, transpile >>> from qiskit.circuit import Parameter >>> circuit = QuantumCircuit(1) >>> circuit.ry(Parameter('theta'), 0) >>> ...


6

Let us consider the state you are creating. Since there is no mention to the training dataset in your code, I'm assuming that you somehow got this state from previous knowledge. We have: psi = [0, 0, 0.5, 0, 0, -0.5, 0, 0, 1/(np.sqrt(2)*a), 0, x1/(np.sqrt(2)*a), x2/(np.sqrt(2)*a), x1/(np.sqrt(2)*a), x2/(np.sqrt(2)*a), 0, 0] which gives us: $$|\psi\rangle = \...


4

Here's a simple example if you're looking for a quick hack: import pennylane as qml import numpy as np def RXX(theta): rxx = np.array([ [np.cos(theta/2), 0, 0, -1j*np.sin(theta/2)], [0, np.cos(theta/2), -1j*np.sin(theta/2), 0], [0, -1j*np.sin(theta/2), np.cos(theta/2), 0], [-1j*np.sin(theta/2), 0, 0, np.cos(theta/2)] ]...


4

If I understand correctly, your circuit looks like this: from qiskit import * qc = QuantumCircuit(2) qc.initialize(0,0) qc.initialize(1,1) qc.h(0) qc.h(1) qc.cx(0,1) qc.h(0) qc.h(1) qc.draw('mpl') And you want to run it in the Aer unitary simulator. However, the simulator does not support the instruction initialize. So you need to transpile your circuit ...


4

The Qiskit standard gate list You can find the full list of Qiskit standard gates in the module qiskit.circuit.library.standard_gates (documentation). The matrix representation of a standard gate For each gate, you can see its matrix representation with the to_matrix method. For example: from qiskit.circuit.library import standard_gates standard_gates.HGate()...


3

One thing you can do is zero noise extrapolation. The idea of the technique is to deliberately add noise to your circuit (by stretching the duration of the pulses of your circuit: Extending the computational reach of a noisy superconducting quantum processor or by adding extra gates that do nothing: Option Pricing using Quantum Computers) and then ...


3

Measurement error, as the name says, is the error that is added to the qubits when you try to measure them. In this paper Mitigating measurement errors in multi-qubit experiments you can find different methods for measurement error mitigation. The logic behind these methods is to measure a circuit prepared in a certain known state and see the results. For ...


3

Easy Fix: It seems like it is because of the way you define $H$. You need the parenthesis around each of the term! So something like: H = (504.0 * I^I^I^I^I^I^I^Z) + (1008.0 * I^I^I^I^I^I^Z^I) + ( 2016.0 * I^I^I^I^I^Z^I^I) Just replace this in your code then it will work! Alternative (longer) way: Here I will offer another way to define the Hamiltonian ...


3

The reason for this is that the actual oracle used in the algorithm is not obtained from oracle.to_operator(). If you look up the code for Grover's algorithm, you can see the following: grover_operator = GroverOperator(oracle=oracle, state_preparation=state_preparation, reflection_qubits=...


3

Yes, it is possible to do this with Qiskit and Cirq. For Qiskit, you can read up this tutorial page here. There was an answer by Josh Izaac from Pennylane here awhile back about parameter shift rule and finite difference to do gradient on quantum circuit here: https://quantumcomputing.stackexchange.com/a/15445/9858 For any quantum software platform, you can ...


3

The way that I'd do it is to write out the stabilizers in a $10\times 8$ matrix in this case (number of rows= number of stabilizers, number of columns is double the number of qubits). For each row, take a stabilizer and write out, for the first 4 columns, if there's an $X$ on a given qubit, and in the last 4 columns, if there's a $Z$ on a given qubit (...


3

You can set the attribute parameters_bounds of a circuit to the desired intervals like below: from qiskit import QuantumCircuit from qiskit.circuit import Parameter a=Parameter('a') b=Parameter('b') ansatz=QuantumCircuit(2) ansatz.ry(a,0) ansatz.ry(b,1) ansatz.parameter_bounds=[[0,np.pi]]*2 Then you can run your vqe program.


3

With 'latex_source' you can save the LaTeX file and compile it later with pdflatex In an interactive console (such a Jupyter notebook), you can run the following: circuit.draw('latex_source', filename='./file.tex') !pdflatex file.tex This will create a file.pdf in actual PDF format. (I understand this is very unintuitive, I submitted a fix to it)


3

By the definition of $U1(\lambda) $ in qiskit, it is equivalent to $RZ$ up up a phase factor . Now note that: $$Z_0 Z_1 = Z \otimes Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \otimes \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 0\\ 0 & 0 & -1 & 0\\ 0 ...


2

There was an issue that was fixed with QAOA https://github.com/Qiskit/qiskit-aqua/pull/1316 whereby using all zeros as an initial point was changed since the optimizer could easily get stuck there. Given the version you have the easiest way to change things would just be to pass an initial point that is non-zero. I.e. instead of [0,0] which it uses with the ...


2

In this tutorial in PennyLane, they guide you to create a custom gate (Rxx gate) https://pennylane.ai/blog/2021/05/how-to-add-custom-gates-and-templates-to-pennylane/ After creating it you can simply use these code to add it: dev = qml.device('default.qubit', wires=3) dev.operations.add("RXX")


2

I would have written the thing differently. Something like this: def modelCircuit(self, printC=False):#, backend='qasm_simulator', shots=1000): circuit = self.model() .... def basicModel(self): circuit = qk.QuantumCircuit(self.n_quantum, self.n_classic) for i, feature in enumerate(self.feature_vector): circuit.rx(np.pi*feature, i) ...


2

You can do this through FermionicOperator, it is Deprecated in the newer update of qiskit though so you will get warning about this issue. Here is an example, I just made up some random second-quantized fermionic one-body operator (h1) to demonstrate how this works under the parity mapping: b = np.random.rand(2,2) one_body_operator = (b + b.T)/2 ferOp = ...


2

If you're looking for the actual time spent on the device, time_taken mentioned by @KAJ226b is the right attribute. If you're looking for the estimated job completion time, you can use the queue_info() method of IBMQJob. It gives you the estimated start/completion time, job priority, and queue position (if available).


2

I would do something like this : n = 5 #number of qubits N = 2**n #32 sup = [0.]*N start = 12 #your 13, considering list index starts at 0 norm = N-start #used for normalisation of the vector we'll pass for i in range(start, N): #creation of the list where the 0s are at indices on the first part you don't want sup[i]=np.sqrt(1/norm) qc = ...


2

Indeed, you are working with OpenQASM version 2 (see your header OPENQASM 2.0;). OpenQASM 2 can only do conditionals on full classical registers and, as consequence, does not allow bit subindexing in the condition. Your arxiv reference is for OpenQASM 3 which supports conditioning on single qubits. The IBM Quantum Experience Composer only supports OpenQASM 2....


1

Lab 8 explains exactly how to do this for LiH For more information, check out Introduction to Quantum Computing and Quantum Hardware Lecture 22 Quantum Chemistry I: Obtaining the Qubit Hamiltonian for H2 and LiH Part 1 Lecture 23 Quantum Chemistry I: Obtaining the Qubit Hamiltonian for H2 and LiH Part 2


1

This should work: backend=provider.get_backend('The backend that you used') #Example: 'ibmq_santiago' job = backend.retrieve_job('Put your JOB ID here') #You can get this on the ibmq web interface job_result = job.result() job_approx_execution_time = job_result.time_taken Note for the Job ID, you can see and copy it from the ibmq web interface: Also ...


1

Even I have implemented Iterative QPE and the basic QPE in qiskit using approximately the same approach. The point where my simulations also started producing random results was as the phase estimation got beyond 4 qubit precision. The question of how we mitigate this error is actually a bit wrong to ask at this point because we also need to start looking at ...


1

First note that your $P(\theta)$ and $R_z(\theta)$ gates are the same up to a global phase, so you will not be able to distinguish them. Now, according to qiskit.pulse.ShiftPhase documentation: The qubit phase is tracked in software, enabling instantaneous, nearly error-free Z-rotations by using a ShiftPhase to update the frame tracking the qubit state. So ...


1

The easiest thing to do would be to check the circuit or just run several qubits through the circuit and measure these qubits. If checking the circuit or running several qubits through the circuit is not possible, then I think applying a CNOT gate to said qubit and a predetermined qubit should allow us to know. Set said qubit to be the control qubit and the ...


1

It seems this is available via the classes Statevector and DensityMatrix. For StateVector, the example from the documentation : import numpy as np from qiskit.quantum_info import Statevector vec = np.zeros(2 * 10) vec[0] = 1 / np.sqrt(2) vec[-1] = 1 / np.sqrt(2) psi = Statevector(vec, dims=(2, 10)) print(psi.to_dict()) And for DensityMatrix : import numpy ...


1

When we make a measurement we project the state of the qubit to the z-basis (i.e 0 or 1) so in general it is not possible to measure a global phase. That said, Measuring such global phases is an important subroutine in many quantum algorithms such as Shor's algorithm. This can be done using the Quantum phase estimation algorithm. For details, check https://...


1

I came across the same issue last week and hence made corrections and opened a PR on the same to change the default values on the textbook. https://github.com/qiskit-community/qiskit-textbook/pull/1132 The key is to change the drive_power from 0.3 to 0.1 It's expected for such values to change, in fact, the pulses that represent circuit gates used by IBM are ...


1

I think you should take all these things into account: How to create a circuit and measurement in both QDK and Qiskit? How to apply quantum algorithm in both QDK and Qiskit? What are the backends that can be linked to by QDK and Qiskit? Special features between those two (Qiskit pulse, Azure quantum, ...) Performance between these two Any restrictions?


Only top voted, non community-wiki answers of a minimum length are eligible