Hot answers tagged

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 ...


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)


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.


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 ...


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) ...


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! ...


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. ...


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

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}


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 ...


1

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


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

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

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 ...


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 ...


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=[...


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

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

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) ...


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}, $$ ...


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

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 = ...


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