TransWikia.com

How to initialize classical register in Qiskit?

Quantum Computing Asked on March 19, 2021

I’m working on a Hybrid classical-quantum linear solver. For this, they make a loop on a quantum circuit (ie. below), and each time they change the value of the classical register and apply a X gate on the quantum register conditioned on the state of the classical register. quantum circuit

Therefore, I ask myself, is there a way to initialize the classical register ?

3 Answers

You might find this section of the documentation helpful, it goes over initializing and using registers.

https://qiskit.org/documentation/terra/quantum_circuits.html

Answered by MMK1137 on March 19, 2021

Classical registers are typically used for capturing measurement results, and may also be used for conditionally applying quantum operation. See: https://github.com/Qiskit/openqasm/blob/master/spec/qasm2.rst

Given the problem you described, one approach would be to have a classical program that iteratively: 1) defines and executes a quantum circuit on a quantum processor or simulator 2) reads the results from the classical registers for guidance in defining the circuit for the next iteration

Answered by James Weaver on March 19, 2021

Here comes an illustration code written by myself.

from qiskit import QuantumRegister,ClassicalRegister,QuantumCircuit,Aer,execute
from qiskit.providers.aer import QasmSimulator
qr=QuantumRegister(1)
cr0=ClassicalRegister(5)
circ=QuantumCircuit(qr,cr0)
circ.measure(qr,cr0[0])
circ.x(qr)
circ.measure(qr,cr0[2])
circ.measure(qr,cr0[3])
circ.x(qr)
circ.measure(qr,cr0[3])
circ.x(qr)
circ.measure(qr,cr0[4])
circ.h(qr)
circ.x(qr)
print(execute(circ,Aer.get_backend('qasm_simulator')).result().get_counts())

Quantum Circuit for the upper instruction

The upper code shows how to get varied values and assign them to different classical registers. Although this method still requires a qubit, at least it can save some time. Maybe you can use the partial trace method to improve this. I think you must be ok with how the c_if() function works.

Answered by Yitian Wang on March 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP