2

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 ?

lufydad
  • 491
  • 5
  • 10

3 Answers3

2

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

1

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.

Yitian Wang
  • 1,008
  • 6
  • 16
0

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

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

MMK1137
  • 376
  • 1
  • 4