# Tag Info

0

The qubit is in state ket $|1\rangle$. Apply on the qubit a Hadamard gate, $H|1\rangle=|-\rangle$.

1

I'm glad to see that you have increased the performance of the pulse path. The scheduler does need to be profiled, but this path will be deprecated in favor of pulse gate calibrations at the end of 2021. I would recommend creating the gate calibration and attaching it directly to the QuantumCircuit. This will be the long-term integration path for pulses in ...

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.

5

Qiskit uses "little endian" bit ordering. That means, if A and B are $2 \times 2$ unitary matrices then $B \otimes A$ (note the order) is equivalent to applying $A$ to first qubit and $B$ to second qubit. Hence, $$CNOT = I \otimes P_0 + X \otimes P_1$$ where $$P_0 = \left( {\begin{array}{*{20}{c}} 1&0 \\ 0&0 \end{array}} \right) , P_1 = \... 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: ... 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 ... 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. 1 "Runtime" is not so easily quantified, it depends a lot on the compilation, the other operations in your circuit and whether you simulate or have a real backend. Generally, the different methods trade off circuit depth (more gates, but less qubits) against circuit width (more qubits, less gates). If we define the runtime by the number of gates we ... 0 The values in the table represent the probability of the object's state before it is measured As @glS said, please split the questions. I answered the first point. The second point I will answer in a seperated question. This thematic is really complex. It doesn't get easier by having "multi" question. Thank you for understanding (and @glS) 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() 0 in general removing virtual orbitals needs careful consideration as it will often affect the final solution and lead to an answer outside what might be considered not chemically accurate. In this case the orbitals of LiH, from a chemistry perspective, were figured out to contribute very little to the solution and could be removed - there is a very slight ... 3 As stated in this tutorial, qiskit relies on a method from this paper from implementing the initialize function. Note that this algorithm is generic: it does not assume anything on the state one wants to prepare. However, it is not known how good this algorithm is in terms of CNOT gates for the initializing circuit. The example you took actually proves that ... 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. 0 Qiskit Textbook is fully open-source and maintained in GitHub: https://github.com/qiskit-community/qiskit-textbook You can submit issues following the predefine templates. If the issue is simple and you think that no discussion is needed, you can submit a PR directly and it will be reviewed by the project maintainers. 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, $$... 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. 1 Let \Phi be a channel acting on a state \rho (or more generally, a map acting on a linear operator; we don't actually need restrict to CPTP maps and states for these calculations). Let J(\Phi) be the Choi representation of \Phi, i.e.$$J(\Phi)\equiv \sum_{ij} \Phi(E_{ij})\otimes E_{ij},$$where E_{ij}\equiv|i\rangle\!\langle j|. Denote with J(\Phi)... 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 You want to calculate$$ \rho_{out}=2\text{Tr}_0(\rho_{in}^T\otimes I\cdot\rho^{sys}_{choi}). $$1 For any map \Lambda(\cdot) with Choi representation \rho_{C} defined as you are doing it (i.e. the channel on the second biparition of the maximally entangled state), the output \rho_{out} = \Lambda(\rho_{in}) can be calculated as:$$ \rho_{out} = \mathrm{tr}_{1}\big[\rho_{C}\big(\rho_{in}^{t} \otimes I\big)\big] $$where the trace is over the ancilla ... 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 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.... 1 Update I think the answer provided by @Adrien Suau could be more suitable for this case. You can use get_subsystems_counts. But first you need to measure each subsystem in its own classical register. And since you want to deal with individual qubits, you will need a classical register each qubit: # Add the classical registers. N is the total number of ... 1 I think without knowing any specific structure about the state, then you might just have to go through all the samples and count the states that have the property that you are looking for. For instance, suppose I have the following circuit: from qiskit import QuantumCircuit, BasicAer, execute circuit = QuantumCircuit(5,5) for i in range(5): circuit.h(i) ... 5 The first diagram is a generic construction showing how it is possible to build a \mathsf{CC}\mathbf{U} gate, which is the gate that applies \mathbf{U} to the third qubit only if both first qubits are in state |1\rangle. It uses the controlled version of the \mathbf{V} gate (and its inverse), which is a gate such that:$$\mathbf{V}^2=\mathbf{U} You ...

Top 50 recent answers are included