Hot answers tagged

8

This is a example for loading QASM, executing and displaying the result. from qiskit import QuantumCircuit, Aer, execute qasm_str = """OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; creg c[2]; h q[0]; cx q[0],q[1]; measure q -> c; """ # From str. qc = QuantumCircuit.from_qasm_str(qasm_str) # If you want to read from file, use instead # qc = ...


6

OpenQASM3 is in an early release stage for circulation for feedback in the quantum community. OpenQASM3 aims to be a standardized language proposal for near-term quantum computing hardware with real-time computing capabilities. We hope that it will lay the foundation for extracting tangible benefits from real quantum computers in the coming years by ...


6

The easiest way is to use the QuantumCircuit methods QuantumCircuit.from_qasm_file() or QuantumCircuit.from_qasm_str() depending on if your loading the QASM from a file or Python string, respectively.


5

Q# is not compiled into QASM, so that would be tricky. Q# compilation and execution process is approximately as follows: Q# code is parsed into an internal data structure representing an abstract syntax tree. This data structure undergoes some transformations (for example, to generate adjoint and controlled versions of operations used in the code). I don't ...


5

The issue is that you are transpiling for a backend with 5 qubits, but this circuit is defined over a 16 qubit register (line 3 qreg q[16];). To avoid this error you can either update your qasm to work over a register of 5 qubits, or transpile for a different backend. I think that the simulator is the only available device that will run up to 16 qubits.


4

This is the matrix for $Z^t$: $$Z^t = \begin{bmatrix} 1&0\\0&(-1)^t \end{bmatrix} = \begin{bmatrix} 1&0\\0&e^{i \pi t} \end{bmatrix}$$ This is the matrix for $R_Z(\pi t)$: $$R_Z(\pi t) = e^{-iZt/2} = \begin{bmatrix} e^{-i \pi t / 2}&0\\0&e^{+i \pi t / 2} \end{bmatrix} = e^{-i \pi t/2} Z^t $$ Which means that $$Z^t \equiv R_Z(\pi ...


4

You'e just experienced code transpilation. Transpilation is when source-to-source compilation takes place, as you have mentioned here. You can prevent the rearranging of the gates by using the "barriers", the Barrier operation is used to make your quantum program more efficient, the compiler will try to combine gates. The barrier is an instruction ...


3

From the spec, $U_2(\phi, \lambda) = U ( \frac{\pi}{2}, \phi, \lambda)$. We can use Cirq's QasmUGate. import cirq from cirq.circuits.qasm_output import QasmUGate q0 = cirq.NamedQubit('q[0]') u2_gate = QasmUGate(0.5, 0, 1) # The angles are normalized to the range [0, 2) half_turns circuit = cirq.Circuit(u2_gate(q0))


3

IF gate can be used for controlling gates based on value in classical register, i.e. measured values of qubits. Lets see at this circuit: In this case qubit $q_0$ is in state $|1\rangle$ and qubit $q_1$ in state $|0\rangle$. After measurement you have value 1 in classical bit $c_1$ and value 0 in classical bit $c_0$. So $c_1c_0 = 10$ in binary or $2$ in ...


3

I think you can use noise in the statevector simulator. If nevertheless you want to use the qasm simulator, you can use snapshots: https://qiskit.org/documentation/apidoc/aer_extensions.html. Although in the lack of notebooks it's a little tricky to understand how to use. You can see examples here for how to insert a snapshot in a circuit: https://github....


3

A simulator executes just an algorithm on a classical hardware as Martin said. On a real quantum hardware, your circuit is calibrated before actually being executed. In addition, there are other tasks like loading pulses into waveform generator, qubits relaxation...which take time and explain the difference.


3

How is correct that new scheme of Controlled-$G^\dagger$ gate may be constructed from this known scheme of Controlled-G gate by reversing the order of used gates ($U$) and each $U$ in this scheme changes to the corresponding $U^\dagger$ (if $U≠U^\dagger$ of course)? It's 100% correct: Inverting a composed quantum gate is done with the algorithm you gave. ...


3

There are many forms of QASM, so I'll answer for OpenQASM 2.0, as is currently used by IBM. Declaring a gate to be random means that it would be randomly generated at compile time. Since QASM is used as an expression of a compiled circuit, such randomness must be resolved by the time the QASM is created. It is true that are transpilation processes in the ...


3

To extract the statevector with qiskit, you can do the following: from qiskit.aqua import QuantumInstance from qiskit.circuit import QuantumCircuit from qiskit import Aer, execute qc= QuantumCircuit(2, 2) qc.h(0) qc.cx(0,1) print(qc ) quantum_instance = QuantumInstance(backend = Aer.get_backend("statevector_simulator"), shots= 1) Result = ...


3

You can use qasm files to create a quantum circuit, two ways : via the methods from_qasm_str or from_qasm_file on a QuantumCircuit. See the documentation about this. For example : test = ''' OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; creg c[2]; h q[0]; cx q[0],q[1]; ''' from qiskit import QuantumCircuit qc = QuantumCircuit.from_qasm_str(test) ...


2

Note that $$RX(\phi) = \begin{pmatrix} \cos(\phi/2) & -i\sin(\phi/2) \\-isin(\phi/2) & \cos(\phi/2)\end{pmatrix}$$ Then $$RX(\pi q) = \begin{pmatrix} \cos(\pi q/2) & -i\sin(\pi q/2) \\-isin(\pi q/2) & \cos(\pi q/2)\end{pmatrix}.$$ Now, using that $\cos(\pi k + \pi/2) = 0 = \sin(\pi k)$ and $\cos(\pi k) = 1 = \sin(\pi k + \pi/2)$ for $k\in \...


2

You need to extract the compiled qasm from a qobj object. You can create this by compiling from qiskit import compile qobj = compile(qc,backend,shots=shots) If you want to create a batch job, where you send many circuits in at once, you can replace the single circuit qc with a list of circuits. Information about the circuits, the backend on which they'll ...


2

If I understand the question correctly, you're assuming that you have some gate $V$ that you've decomposed as $\prod_{i=1}^NU_i$ and you want to show that $V^\dagger$ is $\prod_{i=1}^NU_{N+1-i}^\dagger$ where the product is taken in the opposite order? In that case, you just need to show that $VV^\dagger=\mathbb{I}$ given that $U_iU_i^\dagger=\mathbb{I}$. ...


2

According to the openqasm spec the include statement will insert the contents of the files with the name relative to the current working directory: https://github.com/Qiskit/openqasm/blob/master/spec/qasm2.rst#language If you're using qiskit-terra as your parser this should work unless you name the local file "qelib1.inc". The parser included in the qiskit-...


2

The ibmq_qasm_simulator is a cloud-based simulator. You need to say from qiskit import IBMQ provider = IBMQ.load_account() sim = provider.backends.ibmq_qasm_simulator


2

In the web based composer there is currently no way to adjust the optimization level. As a workaround, you can put a barrier before and after each gate. This will prevent them from being joined.


2

I don't know if this will help. I have tried the code and it worked: I created a new file named ccu1_circuit.qasm with the instruction written in the question. Then in a separate Python file, I have written: from qiskit import * circuit = QuantumCircuit.from_qasm_file('/...The path.../ccu1_circuit.qasm') backend = BasicAer.get_backend('qasm_simulator') ...


2

It's a little difficult to tell without looking at your circuit, but I believe this is because your circuit contains a measurement in it. (edit: if there were no measurements the qasm simulator wouldn't work, so you obviously have a measurement happening in your circuit) The statevector_simulator simply gives you the state generated by your circuit. If you ...


2

If you mean at the circuit schedule level, then yes the transpiler supports scheduling a circuit and resolving all timing by inserting appropriate delays on all qubits according to the selected scheduling policy. See the transpiler option scheduling_method here. As KAJ226 notes, for more explicit control you may use the pulse level Schedule representation ...


2

Just note that $\alpha$ and $\beta$ are not probabilities but amplitudes. A qubit is in general described as superpositon $|q\rangle = \alpha|0\rangle + \beta|1\rangle$. Probability of measuring $0$ is $|\alpha|^2$ and probability of measuring $1$ is $|\beta|^2$. You can see both probabilities and state vector in circuit composer on IBM Q. For example assume ...


2

Parameterized circuit is not supported by the OpenQASM2 specification https://arxiv.org/abs/1707.03429 The .qasm output is a bit of notation abuse. There are experimental ideas to support a more comprehensive circuit serialization format https://github.com/Qiskit/qiskit-terra/pull/5578


2

I think you underestimated how long your circuit really is.... When running your circuit on the hardware, it has to be transpile into the set of gates that is known to the hardware. For IBM machines, these are $\{ CX, ID, RZ, SX, X \}$ . Furthermore, there is a constraint on the qubit layout of the hardware as well. Not all qubits are connected. Thus there ...


2

Indeed, you are working with OpenQASM version 2 (see your header OPENQASM 2.0;). OpenQASM 2 can only do conditionals on full classical registers and, as consequence, does not allow bit subindexing in the condition. Your arxiv reference is for OpenQASM 3 which supports conditioning on single qubits. The IBM Quantum Experience Composer only supports OpenQASM 2....


2

Firstly, you might be interested in paper Elementary gates for quantum computation explaining how complex gates can be decomposed to simpler ones. This would allow you understand how the matrix $U_j$ is decomposed. Before we proceeed further, we have to define gate $U1$ used on IBM Q computer: $$ U1(\lambda)= \begin{pmatrix} 1 & 0 \\ 0 & e^{i\lambda} ...


2

I expect you get the Noise Model from the calibrated data of the hardware, however I am not sure how often it is updated. I doubt that it is live or even daily. You can check the noise model by running noise_model._local_quantum_errors and noise_model._local_readout_errors For instance: device = provider.get_backend('ibmq_armonk') noise_model = NoiseModel....


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