2
$\begingroup$

I'm starting with Qiskit in Python.

My question is regarding to have registers and sub-register. Something like this

axreg=QuantumRegister(4,name='ax')
ahreg=QuantumRegister(axreg[:2],name='ah')
alreg=QuantumRegister(axreg[2:],name='al')

The constructor of QuantumRegister has only the number of qubits to create, and I find no way to add previously existing qubit to other register

$\endgroup$
1
$\begingroup$

If you want to add previously existing qubits to other register you can obviously compose or append to add previously existing qubits to other register, let's say we have have two qubits who are in state |++> and we want to add them to our register which has for example 4 qubits, we can do

sub_circuit = QuantumCircuit(2)
circuit = QuantumCircuit(4)
qr = circuit.qregs[0]
circuit.x(range(4))
sub_circuit.h(range(2))
circuit = circuit.append(sub_circ.to_instruction(), [qr[0], qr[1]])

You'll get something like this

picture of the final circuit

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank! I'll try the "subcircuit" approach. This is not exacty what I was looking for, but it's useful $\endgroup$ – Sourcerer Aug 18 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.