# Tag Info

4

That looks right to me. Since, $HZH = X$ then we have that $\langle \psi | X | \psi \rangle = \langle \psi | HZH | \psi \rangle = \langle \psi H | Z | H\psi \rangle$. In your code, you generate $|\psi \rangle$ with a $U_3(\theta, \phi, \lambda)$ gate applied to $|0\rangle$. Then you applied the Hadamard gate ($H$) before measuring which is what needed ...

1

You can simply merge the lists of qubits from two quantum registers or more as any python lists using "+" sign. For example gate = UnitaryGate(random_unitary(2 ** 4).data, 'RND-U16') qr1 = QuantumRegister(2, 'q') qr2 = QuantumRegister(3, 'a') circ = QuantumCircuit(qr1, qr2) circ.mct(qr1[0:2] + qr2[0:2], qr2[2]) circ.append(gate, qr1[1:2] + qr2[0:...

1

This seems like a bug in the notebook / ReCirq - I filed https://github.com/quantumlib/ReCirq/issues/191. This is a JSON serialization issue when ReCirq is trying to save the task in JSON format.

1

I made a start and end_operation point with the method now(). At the end of the operation it will display the time it needed: from qiskit.utils import algorithm_globals from time import time as now algorithm_globals.random_seed = 1234 backend = provider.get_backend('ibmq_belem') #backend = Aer.get_backend('statevector_simulator') cobyla = COBYLA() cobyla....

2

A condensed answer: Any operation on a quantum computer, measurement and reset being exceptions, are described by a unitary matrix. This follows from Schrodinger equation which solution for discrete time steps is a unitary matrix. A unitary matrix is invertible and its columns form a orthonormal basis of a vector space. Hence, it defines a 1:1 mapping (a ...

6

It is due to the inherent linearity of Quantum Mechanics. By definition, applying a function to a quantum state means mapping this quantum state to another one. Now, a quantum state can be represented as a unitary vector lying in an Hilbert space, and every transformation it undergoes follows Shrödinger equation, ensuring that any such transformation is ...

0

If you use from qiskit.providers.aer.noise import NoiseModel to add noise in your U gate operation. Then it won't behave like an ideal gate, https://qiskit.org/documentation/tutorials/simulators/4_custom_gate_noise.html here you can get more information.

0

Just like running circuits you must build and submit your schedules to be run (note this code has not been tested and there may be minor bugs). with pulse.build(backend) as measure: pulse.play(pulse.MeasureChannel(0), pulse.Constant(22800, 0.2)) pulse.acquire(pulse.AcquireChannel(0), pulse.MemorySlot(0)) with pulse.build(backend) as ground: ...

1

I found something that could help you, it's a documentation with commands to do different operations between physical and virtual [qu]bits. You could use something like this: {(QuantumRegister(3, 'qr'), 0): 0, (QuantumRegister(3, 'qr'), 1): 1, (QuantumRegister(3, 'qr'), 2): 2} Can be written more concisely as follows: * virtual to physical:: {qr[0]: ...

0

Example 1 The backend defaults provide a starting point for how to use the backend. It contains estimates for qubit frequencies and default programs to enact basic quantum operators. We can access them with the following: backend_defaults = backend.defaults() As you can see backend itself is a command. You can change it with loading parameters (here ...

1

Qiskit uses the implementation of Shor's algorithm from Circuit for Shor's algorithm using 2n+3 qubits, so I recommend looking into that for more detail on how to implement the general case of Shor's algorithm. Values for $a$ Anyways, now regarding your specific question. The code snippet that you shared is for factorizing the number 15. I first refer to ...

1

I will answer using Python, but the underlying method can be easily adapted to another language. You can represent the mapping you describe in your question 1 -> 0 3 -> 1 0 -> 2 2 -> 3 as a map, or a Python dictionary in this case (it can also be represented as a simple array, but this complicates a little bit the code): logical2hardware_mapping ...

4

There was an issue raised on qiskit-tutorials about this duplicate drawing. The solution that was done there was to remove %matplotlib inline from the notebooks. If you would like to know more you can see the fix here https://github.com/Qiskit/qiskit-tutorials/pull/1206 which also links back to issues which report the problem.

0

I submitted an issue on GitHub here.

2

$\newcommand\dag\dagger$ The Lindblad superoperator is shorthand for a longer operation that generically reads $$\mathcal{L}[\hat{L}]\hat{\rho} = \hat{L} \hat{\rho} \hat{L}^\dag - \tfrac{1}{2}\left(\hat{L}^\dag\hat{L}\hat{\rho} + \hat{\rho}\hat{L}^\dag\hat{L} \right),$$ where the $\dag$ denotes the conjugate transpose (i.e. Hermitian adjoint) of the Lindblad ...

1

qApps as you have described them in your question don't exist yet. The number of qubits available through classical simulation or real quantum hardware is not enough and the noise present is too high to run applications that would require a framework like QuantumNode.js or similar. Right now, we are going through the NISQ era. Which stands for Noisy ...

1

I would suggest to learn quantum programming with IBM Quantum Computing Program. A good step by step guideline and tutorials. You will be able to program different scenarios with circuits by it's quantum computer. Another good point to get as a beginner to advanced information is to stick with Quantum-Inspires Knowledge Base. Try to understand these ...

2

If all what you want is a list of all job IDs for the jobs in a job set: job_set = job_manager.retrieve_job_set(job_set_id = 'XXX-YYY', provider = provider) id_list = [ job.job_id() for job in job_set.jobs() ]

1

qc.draw can output the figure to matplotlib. Simply call plt.show() at the end. import matplotlib.pyplot as plt from qiskit import QuantumCircuit qc = QuantumCircuit(3, 3) qc.draw(output="mpl") plt.show()

1

So yeah it is not the best choice. My guess is the individual who programmed it did not think about the physics of the problem. In short, it is best to use the raw input data as the starting point when measurement errors are small. In practice this gives you much faster convergence.

1

What you did is right. However, the reason for the result you observe is because your output state is in the state $|000\rangle$ with 100% certainty. To see this, note that your circuit has the form: That is, it starts in the state $|0000\rangle$, then all those control operations don't do anything since all the controlled qubits are in the state $|0\rangle$...

0

To build a noise model from scratch and compare with the backend noise model, you can do from qiskit import * from qiskit.providers.aer.noise import NoiseModel from qiskit.providers.aer.noise.device.models import (basic_device_readout_errors, basic_device_gate_errors) IBMQ.load_account() provider = IBMQ....

0

Thank Steve! finally it works inicializing the qubits and save_statevector and probabilities ans.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 0) ans.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 1) vqc.circuit.save_state() vqc.circuit.save_probabilities() vqc.circuit.save_statevector() Regards!

0

As the exception says, the gradient must be callable. The convert method return a ListOp object. From the documentation, to get a callable function, you can use gradient_wrapper method. From your code, simply substitute the grad with: grad = Gradient().gradient_wrapper(operator = op, bind_params = list(var_form.parameters)) After looking at the source code ...

0

Since the PiecewiseChebyshev object implements the transformation $U |x\rangle |0\rangle \to |x\rangle \Big(\cos(f(x))|0\rangle + \sin(f(x))|1\rangle\Big)$, you need to apply amplitude estimation process in order to retrieve the value $\sin(f(x))$ into some $m$-qubit quantum register. You can of course define $f$ such that the $\sin$ function disappear. I ...

1

You can have a look at how the QAOAAnsatz class is used in the tests here. Note that the link given @KAJ226 in the question comments does not use QAOAAnsatz directly but use the QAOA class that forward the given operator to the QAOAAnsatz class. So when the line result = qaoa.compute_minimum_eigenvalue(qubit_op) in cell 6 of KAJ226 link is executed, it will ...

1

The QAOAAnsatz was built for the QAOA algorithm, which if you look at the qaoa code in Qiskit you will see it builds a QAOAAnsatz instance internally. Hopefully looking at that helps you use it https://github.com/Qiskit/qiskit-terra/blob/5ca967557b21828c0760763b7f0c5870e5f032d9/qiskit/algorithms/minimum_eigen_solvers/qaoa.py#L131-L132

0

I believe this is a path issue. As already mentioned pip3 install qiskit will install the full package and configure the paths for you. You can find the search paths for all Python modules by import sys print(sys.path) If the full path to your Qiskit package is full/path/to/qiskit and '/full/path/to' is not in sys.path, then you need to append it by sys....

0

If you use memory=True in execute(), then you store the measurement outcomes for each individual shots. job.result().get_memory()[0] mean that you access measurement outcome of the first shot. The meaning of your output is for inp1, inp2, inp3, inp4 = 0, the measurement outcome of the first shot is 0000, for inp1, inp2, inp3 = 0, and inp4 = 1, the first shot ...

1

Following the tutorial, you can change the Gaussian and the add_calibration. To build a constant pulse shape, there is qiskit.pulse.library.Constant, and for the mapping, change the gate from 'h' to 'x' in circ.add_calibration. Here's the code: from qiskit import QuantumCircuit, pulse, transpile from qiskit.test.mock import FakeValencia from qiskit.pulse....

1

The pulse shape you specify in Qiskit is the envelop function of the drive, so you will need to set the area under the constant pulse to be the same as the area under the original $X$ gate pulse, which is usually a Gaussian or DRAG pulse. Specifically, suppose the qubit Hamiltonian is $$\hat{H}_d = -\frac{1}{2}\omega_q\hat{\sigma}_z + QV(t)\hat{\sigma}_x,$$...

1

I don't think there is a feature to download a folder, but you can download the folder by zipping it first. To zip the folder, write in a new cell: !zip -r MyFolder.zip path/to/folder Then you can download the zip file. If you only want to download the .txt files, you can write: !zip MyFolder.zip path/to/folder/*.txt

3

Upgrade qiskit to the lastest version. aer_simulator is introduced since qiskit 0.25.0. You can use pip install qiskit --upgrade to install the lastest version.

0

Try command pip install qiskit or pip3 install qiskit in cmd or Anaconda Prompt to install the qiskit module. Then try running the command you used. If it's still not working check whether your notebook is working in the same location where you installed the qiskit module. Tip: Use from qiskit import * as it saves time and imports all the packages in qiskit. ...

0

QSVC is really the sklearn SVC passing the quantum kernel to the SVC. Now I see SVC has a 'random_state' argument on its constructor to control any randomness of the SVC within sklearn - see https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html and https://scikit-learn.org/stable/common_pitfalls.html#controlling-randomness Since QSVC ...

1

I did such a function some months ago. Warning: this is a textual output. If you want something nice with $\LaTeX$ see Matthew's answer. The code: import numpy # Numbers below this threshold will be printed as 0 ABSOLUTE_TOLERANCE: float = 1e-5 def _real2str(num: float, decimals: int, atol: float, force_ones: bool) -> str: ret = "" ...

3

Qiskit doesn't expose a method to do this yet. There is a proposed feature under review now here: https://github.com/Qiskit/qiskit-terra/pull/6154 that adds a new output style for the Statevector.draw() method doing this which will generate LaTeX output in the ket notation. If you'd like to leverage this now it shouldn't be too difficult to adapt the code ...

3

Yeah, you can assign a label to a Gate or an Instruction object for this. For example, something like: from qiskit import QuantumCircuit from qiskit.extensions import UnitaryGate from qiskit.quantum_info import random_unitary qc = QuantumCircuit(2,1) randUnitary = UnitaryGate(random_unitary(4), label='My Special Unitary') qc.append(randUnitary, [0,1]) qc....

1

This looks like it could be a bug so it might be worth checking the Qiskit repo to raise an issue or see if anyone else has spotted it already. If you are simply looking to format the results, you can use Python's f strings, for example print(f'{outputstate:.3f}') would print outputstate to 3 decimal places.

0

Qiskit ML VQC is a lightweight sub-class of sklearn SVC that supplies the quantum kernel to the SVC. You can therefore leverage sklearns capabilities to say save/restore models see https://scikit-learn.org/stable/modules/model_persistence.html#python-specific-serialization

0

The source of the problem was numpy.polynomial.chebyshev.interpolate, which is used to approximate the input function but raises problems when approximating a constant function. The code in Qiskit has been changed adding a special case for such functions and explaining how constant functions should be declared, i.e. as f_x = constant rather than with the ...

2

Unfortunately, the Qiskit textbook does not cover this topic correctly. In general you do get negative values when inverting the calibration matrix. These are called quasiprobabilities. You can use these directly for computing expectation values. Alternatively you can use a bounded least squares method to get the maximum likelihood estimate for the nearest ...

1

Up until very recently, braket had no such feature. However, as of v1.7.0 (2021-06-25), unitary representations of circuits can now be calculated using the calculate_unitary function. Using the circuit you provided as an example: In [1]: from braket.circuits import Circuit ...: from braket.circuits.gate import Gate ...: from braket.circuits.instruction ...

1

Based on your new additional inputs, it seems like you want to transpile the individual circuit before appending them together to potentially reduce the extra work needed for the transpiler since it won't have to transpile a large circuit. The problem that you run into then is that when you tried to transpile each individual circuit, their new transpiled ...

4

It seems that Qiskit does not have this feature. However, you can get the matrix, inverse it using numpy.linalg.inv(), then convert it to operator object again: from qiskit.opflow import X, Y, Z from qiskit.opflow.primitive_ops import MatrixOp import numpy as np op = 2*(X^X)+0.5*(Z^Y) inv_matrix = np.linalg.inv(op.to_matrix()) operator = MatrixOp(inv_matrix)...

1

An example using .append(). If that does not answer to your need, it might be a start for you to explain what's wrong .... subcirc1 = QuantumCircuit(10) subcirc1.h(3) subcirc1.x(5) subcirc1.z(7) subcirc1.barrier() subcirc2 = QuantumCircuit(10) subcirc2.h(1) subcirc2.x(3) subcirc2.z(6) subcirc2.barrier() subcirc2.draw(idle_wires=False) circ = QuantumCircuit(...

0

I got an answer to my question from some guys on the python stack exchange: https://stackoverflow.com/questions/68249614/using-get-on-a-dictionary-of-2n-numbers-each-made-up-of-n-0s-or-1s-by-only-lo Basically if I call the results of my quantum circuit my_res, then the following code gives a simple one line way to get the number of counts for any given qubit ...

0

From qiskit documentation on pulses, here is a code that implement a constant (square) pulse. I also included the other examples given in the previous link. Note that the API used here is brand new and still in beta, so it might change in the near future. from math import pi import matplotlib.pyplot as plt from qiskit import pulse from qiskit.test.mock ...

0

In simulation mode, you can use appropriate partial trace on Density Matrix of Quantum Operator/Circuit to isolate statevector of specific qubit(s). # Sample Code: partial trace on Density Matrix from qiskit import QuantumCircuit import qiskit.quantum_info as qi from qiskit.visualization import plot_bloch_multivector # create a quantum circuit qc qc = ...

4

To add to the already existing answers you can also use qiskit.result.marginal_counts. To illustrate, I took the circuit from @KAJ226 answer verbatim: from qiskit import QuantumCircuit, BasicAer, execute circuit = QuantumCircuit(5,5) for i in range(5): circuit.h(i) circuit.measure([0,1,2,3,4],[0,1,2,3,4]) circuit.draw() # Get results backend = BasicAer....

Top 50 recent answers are included