New answers tagged

1

Parallelization in Qiskit simulation has three levels: experiment: multiple-circuits are simulated in parallel shot: multiple-shots are simulated in parallel state update: A state (such as statevector) is updated in parallel In any levels, Qiskit-Aer provides node-level and thread-level parallelization. The blog introduced experiment + node parallelization....


2

The rightmost two bits of each string correspond to a pixel (e.g. 010 and 110 both correspond to pixel 10). The frequency we measure the string with a leading 1 tells us the intensity of that pixel. Here's some quick code that decodes the counts dictionary: for pixel in range(4): # convert to pixel number to bit strings, i.e. (00, 01 etc.) bit_str = ...


2

Non-unitary gate is a bit of an oxymoron for reasons explained here and here. Qiskit support non-unitary instructions. Gates are Instructions subclasses. A gate, like XGate is an instruction, but not every instruction, such as Reset, is a gate: from qiskit.circuit import Gate, Instruction, Reset issubclass(Reset, Instruction) # True issubclass(Reset, Gate) ...


1

The percentage error rates in the calibration files give the average readout error across all qubits. So, in your example, $20000$ shots of which $5000$ measured $|00\rangle$ on a backend with an average qubit error rate of $1\%$ would correspond to an estimated uncertainty of $5000 \pm 50$. To more accurately quantify measurement uncertainty you'll want to ...


1

This is because of these lines of code: # bob reverse the initialization gate inverse_init_gate = init_gate.gates_to_uncompute() qc.append(inverse_init_gate, [2]) These two lines add the gates that set $q_2$ back to $|0\rangle$. Just remove them and the output should look like: {'1 1 1': 266, '1 0 0': 261, '1 1 0': 240, '1 0 1': 257}


2

From the algorithm's point of view (for any oracle-based algorithm) it needs the oracle to be a black box that implements the function reversibly, so that it can just be plugged in the rest of the algorithm. Using oracles in this way allows you to describe and discuss the algorithm in an abstract manner without always following it for a specific function. ...


1

By default execute function sets optimization_level value to $1$ which leads to some optimizations such as removing ID gates. Just set optimization_level to $0$ to override this behavior: results = (execute(qc,Aer.get_backend("aer_simulator"),noise_model=get_noise_model(0.2),optimization_level=0,shots=2048).result().get_counts()) The result should ...


0

"I wonder after the first mid-circuit measurement, how can I determine if this matrix is still the same?" I had one of my students do a daily benchmarking of the various IBM chips and part of this project was to monitor the calibration matrix as a function of time. Unfortunately, the calibration matrix is not a constant with respect to time. It ...


0

Add interactive : qubit.draw(output='mpl', fold=50, interactive= True)


0

You should add interactive argument, if you want to see the figure, example: qubit.draw(output='mpl', fold=50, interactive= True)


1

One way to do that is to use QuantumCircuit.unitary method as follows circ.unitary(Q1, [0, 1], 'Custom Label')


0

You can save your figure using the filepath argument, e.g. plot_histogram(counts, filepath="myfig") would save the plot as myfig.png in your current working directory. See API Reference: qiskit.visualization.plot_histogram


1

Repetition codes are great for helping to demonstrate some understanding of how things work. But they are not good quantum codes. In fact this is part of the reason why they are so good for demonstrating some of the ideas - they help bridge the gap between the classical intuition that we're used to and the quantum world which often feels a bit less ...


-1

To understand the answer of this question you have to look into no cloning theorem which states that you can't make a copy of an unknown quantum state. e.g. $\alpha|0> + \beta|1>$ where you don't exactly know the values of $\alpha$ and $\beta$. but you can make copy of states like $|0>$, $|1>$ or $\frac{1}{\sqrt2}(|0>+|1>)$. So unlike ...


1

If you run the following code you will see the output statevector plotted in Bloch sphere. qc = QuantumCircuit(1) qc.ry(3 * np.pi/4, 0) sim = Aer.get_backend('statevector_simulator') result = execute(qc, sim).result() output_state = result.get_statevector(qc) plot_bloch_multivector(output_state) Now from the picture you can see that the state lies near ...


1

This is a result of the periodicity of the gates you use to encode your features. The circuit you have encodes a pattern $\mathbf{x} = (x_0, x_1) \in \mathbb{R}^2$ as \begin{equation} |\psi(\mathbf{x})\rangle = \left[(R_z(2 x_0) \otimes R_z (2 x_1) )(H \otimes H) \right]^2 |00\rangle \end{equation} There's two issues here. First, since $R_z$ is $2\pi$-...


1

The combine_results() method is only available if you are using Job Manager. Without Job Manager you can simply do cal_results = cal_job.result(). Job Manager divides your circuits into multiple jobs and collect the their results. You can then use combine_results() to combine results from all jobs into a single Result object. Here's a tutorial on using Job ...


1

I think a good place to start is the chapter on quantum image processing in Qiskit Texbook. It introduces possible representations as well as some working code. A popular format for quantum storage of image data is FRQI. The chapter linked above treats about it in practice, though the original paper could be useful if you are interested in the intuition ...


3

This behavior is already documented for example here: The command AerSimulator(noise_model=noise_model) returns a simulator configured to the given noise model. In addition to setting the simulator’s noise model, it also overrides the simulator’s basis gates, according to the gates of the noise model.


1

Create an IBM Quantum account or log in to your existing account by visiting the IBM Quantum login page. Copy (and/or optionally regenerate) your API token from your IBM Quantum account page. Take your token from step 2, here called MY_API_TOKEN, and run: from qiskit import IBMQ IBMQ.save_account('MY_API_TOKEN') The command above stores your credentials ...


1

You can see the list of Qiskit Runtime jobs under Program jobs tab in the Jobs page on IBM Quantum platform. From there you can find the job id and the corresponding provider information (in HUB_NAME/GROUP_NAME/PROJECT_NAME format and the default provider is ibm-q/open/main) to retrieve the job using Qiskit on IBM Quantum Lab or on your local Jupyter ...


1

You can do something like this: from qiskit.opflow import X, Y, Z, I H = 5.9*(I^I^I) + 0.21*(Z^I^I) - 6.12*(I^Z^I) - 2.14*(X^X^I) - 2.14*(Y^Y^I) + 9.6*(I^I^I) - 9.6*(I^I^Z) - 3.9*(I^X^X) - 3.9*(I^Y^Y) You can check your answer by printing out the matrix: from qiskit.visualization.array import array_to_latex H_matrix = H.to_matrix() array_to_latex(H_matrix)


1

Would the Operator Flow feature be helpful? https://qiskit.org/documentation/tutorials/operators/01_operator_flow.html


1

The latest release of qiskit-aer should support the if else operation in your quantum circuit. You can see this documented in the release notes here: https://qiskit.org/documentation/release_notes.html#aer-0-10-0 That being said there is a general limitation around the classical control flow instruction in qiskit right now in that the transpiler doesn't know ...


3

From my experience, most of the time you can restructure your code to avoid the need for inserting gates in the middle of a circuit. That said, if you already know the insertion points at the time of circuit creation but you don't know the gates to be inserted, you can add placeholders at these places and replace them later with whatever gates you want. from ...


3

The short answer is no, there is no way to insert gates in a middle of a circuit. As explained, the issue https://github.com/Qiskit/qiskit-terra/issues/4736 has a longer explanation on why not. The mid size explanation is the following: generally speaking, a circuit is not a sequence of instructions and, therefore, there is no indices to insert things in. A ...


2

Applying a reset to a qubit is equivalent to measuring it, and then applying a bit flip to it conditioned on the measurement result. def reset(qubit): if measure(qubit) == ON: X(qubit) For example, in this Quirk circuit, you can see that the post-reset state matches the state you'd get when conditioning on a measurement-via-ancilla+bit-flip of ...


2

$Ry$ gate is defined as $$ Ry(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\ \sin(\theta/2) & \cos(\theta/2) \end{pmatrix}. $$ Hence $$ Ry(\pi/2) = \begin{pmatrix} \cos(\pi/4) & -\sin(\pi/4) \\ \sin(\pi/4) & \cos(\pi/4) \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix}. $$ Similarly for $...


2

You are using rz in your code, while the identity you are asking about uses $R_y$ Here is a qiskit code to check the identity: from qiskit import QuantumCircuit from qiskit.quantum_info.operators import Operator from qiskit.visualization import array_to_latex import numpy as np circ = QuantumCircuit(1) circ.ry(-np.pi / 2, 0) circ.z(0) circ.ry(np.pi / 2, 0) ...


0

I don't think Qiskit currently provides a straightforward way to exclude a certain transpiler pass. You can construct a pass manager that contains only the passes you want then use it. my_pass_manager = PassManager() my_pass_manager.append(my_list_of_passes) qc_foo_trans = transpile(qc_foo, backend=lima, pass_manager=my_pass_manager) However, this would be ...


0

Sorry, just registered for an account so this is me trying to reply! Thank you both for your input. So far I've tried to normalize the solution vector by the full 8192-element statevector 2-norm, is this correct? Or should I be normalizing it only by the 2-norm of the extracted 32-element solution vector? Strangely either way, I'm still getting erroneous ...


1

Use qtcodes Python library which is using qiskit. It is still a baby library, but this is the only thing I found. I am actually planning to override it and expand it.


1

You should compare the normalised classical solution to the normalised solution vector you compute from the Statevector. If the solution is still wrong it might be that you are using the wrong ordering of qubits, so maybe you have to take the reverse order with respect to what you were doing, i.e. $|0000000000001\rangle$ to $|1111100000001\rangle$


1

As @Cryoris said in his answer, it's still the same circuit. However, if you want the circuit plot to have the same gate alignment, there is a simple trick to do that: Add a barrier before the t-gates. Set the draw method's option plot_barriers to False. qc_AB = QuantumCircuit(3) qc_AB.h(2) qc_AB.cx(1,2) qc_AB.tdg(2) qc_AB.cx(0,2) qc_AB.t(2) qc_AB.cx(1,2) ...


2

It's still the same circuit -- but the circuit drawer shows the gates "as soon as possible", which means it'll move them to the left if possible. In your example, you'll notice that the drawer moved the last T gate on the wire of q_1 further to the left, through the CX gate. As this example shows, the common circuit representation is not unique! ...


1

You can use QuantumCircuit.decompose() for shallow decomposition circuit.decompose().draw('mpl') The result will be For further decomposition you can use Unroller transpiler pass from qiskit.transpiler.passes import Unroller from qiskit.converters import circuit_to_dag, dag_to_circuit # You can specify the target basis gate set: unroller = Unroller(basis=[...


4

You just forgot to add the highlighted gates to your code: Add them and your code should work as expected. Note that to add Toffoli gate to your circuit you can call toffoli method: qc_AB.toffoli(0, 1, 2)


1

"How to calculate it by hand? I am not sure this initial density matrix is correct or not..." If you initialize your states to $|000\rangle = |0\rangle\otimes |0\rangle \otimes|0\rangle$, and each $|0\rangle$ has a vector representation (in the "computational basis") of: $$\tag{1} |0\rangle \equiv\begin{pmatrix} 1 \\ 0 \end{pmatrix}, $$ ...


3

Asymmetric readout error While its hard to make strong claims about the noise characteristics of any given quantum device, one explanation for what you're observing is readout error. For superconducting qubits readout error tends to be asymmetric: the probability $p(0|1)$ of observing a "0" after performing measurement on a computational basis ...


1

Here is a code snippet with inline comments for using CDKMRippleCarryAdder adder = CDKMRippleCarryAdder(3, 'full', 'Full Adder') # Here we create a quantum register for each operand and another one for the carry in and carry out. # We can also use a single 8-qubit register. operand1 = QuantumRegister(3, 'o1') operand2 = QuantumRegister(3, 'o2') anc = ...


5

We have, $$\begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}Ry(\theta) = \exp\Big(-i \th Y\Big) = \begin{pmatrix} \cos{\th} & -\sin{\th} \\ \sin{\th} & \cos{\th} \end{pmatrix}\end{split}\end{aligned}\end{align}$$ If the input state is $|0\rangle$, then the probability of getting $|0\rangle$ as a ...


0

CDKMRippleCarryAdder is a quantum circuit, meaning a set of quantum gates operating on some quantum registers consisting of qubits (quantum bits.) The inputs to your adder are two quantum registers, which store qubits representing the numbers you want to add, and some helper qubits depending on the type of the adder (for ex. the default full adder needs an ...


0

503 Service Unavailable can be due to multiple reasons on IBM Quantum Lab based on my experience of running IBM Quantum Challenges when many users are accessing the platform at the same time. I can recommend the method resetting your notebook pod below which could solve the problem consistently during the challenges: From the File menu in Quantum Lab, ...


0

A simpler method is to use equiv method directly from the Operator class. Basically convert both the circuits to operators and then use equiv. You can check out the documentation for the Operator class here. The basic syntax would be something like, from qiskit import * from qiskit.quantum_info import Operator Op1 = Operator(qc1) Op2 = Operator(qc2) Op1....


0

OpenQASM 3.0 is still in pre-release: https://github.com/Qiskit/openqasm/releases I believe your observation is correct - your code is not interpreted as OpenQASM 3.0. Another test: the first example from Github starts with OPENQASM 3; (not 3.0.) Even trying this now I get QasmError: Unable to match any token rule, got -->O<-- Check your OPENQASM ...


0

You are creating a gate from a manually-inputed unitary, and Qiskit does not know how such unitary can be decomposed out of the box. You can either tell Qiskit transpiler not to decompose your unitary, or extend the Equivalence Library (basically, class that stores information on how gates are decomposed) to know how to decompose your gate. The answer to ...


Top 50 recent answers are included