-1

Here is my code

def gen_grover(width):
    oracle = QuantumCircuit(width, name='q') 
    oracle.z(width-1)
    full_circuit = GroverOperator(oracle, insert_barriers=False, name='q')
    full_circuit = dag_to_circuit(circuit_to_dag(full_circuit))
    full_circuit.qregs[0].name = 'q'
    full_circuit = full_circuit.decompose()
    full_circuit = transpile(full_circuit,optimization_level=3) 
    return full_circuit

I get the error below:

full_circuit.qregs[0].name = 'q' AttributeError: can't set attribute python-BaseException

MSpiller
  • 3,500
  • 2
  • 12
  • 24
  • What do you want to achieve? GroverOperator creates the circuit with registers with foxed names. If you want to assign custom names to the register, you have to build the circuit yourself. – MSpiller Feb 24 '23 at 16:44
  • how to assign custom name – Naeem Ullah Feb 24 '23 at 16:58
  • _how to assign custom name_ To what and why? – MSpiller Feb 24 '23 at 17:03
  • full_circuit.qregs[0].name = 'q' here i get error how to change it – Naeem Ullah Feb 24 '23 at 17:49
  • Again. You cannot change the name of a register, when the register is created automatically for you (here by using `GroverOperator`). You can name registers, when you create them manually.. So, WHY do you want to change the name of that register? – MSpiller Feb 27 '23 at 09:22

1 Answers1

0

Register name is a read-only property (getter). There is no setter.

See also https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumRegister.html#qiskit.circuit.QuantumRegister subclass which shows name Attribute

Steve Wood
  • 266
  • 1
  • 3