Tag Info

Hot answers tagged programming

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

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.

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

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

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

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

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.

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

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() ]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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