HQSquantumsimulations / qoqo-quest

Other
7 stars 8 forks source link

DefinitionComplex Length Check #180

Closed mlodi-hqs closed 2 weeks ago

mlodi-hqs commented 5 months ago

Just a draft that solves the following inconsistency:

from qoqo import Circuit
from qoqo import operations as ops
from qoqo_quest import Backend

number_qubits = 2
test_circuit = Circuit()
test_circuit += ops.DefinitionComplex(name="ro", length=1, is_output=True)
test_circuit += ops.DefinitionComplex(name="ri", length=1, is_output=True)
test_circuit += ops.PauliZ(0)
test_circuit += ops.PauliZ(1)
test_circuit += ops.PragmaGetDensityMatrix(readout="ro", circuit=None)
test_circuit += ops.PragmaGetStateVector(readout="ri", circuit=None)

backend = Backend(number_qubits)
bit_regs, float_regs, complex_regs = backend.run_circuit(test_circuit)

this runs fine at the moment, but the length of the DefinitionComplex isn't checked. With the addition, it now returns an error: RuntimeError: Running Circuit failed GenericError { msg: "Incorrect density matrix dimensions: 1 elements, but the DefinitionComplex register is 16 elements long." } The following code does not return an error:

from qoqo import Circuit
from qoqo import operations as ops
from qoqo_quest import Backend

number_qubits = 2
test_circuit = Circuit()
test_circuit += ops.DefinitionComplex(name="ro", length=4**number_qubits, is_output=True)
test_circuit += ops.DefinitionComplex(name="ri", length=1, is_output=True)
test_circuit += ops.PauliZ(0)
test_circuit += ops.PauliZ(1)
test_circuit += ops.PragmaGetDensityMatrix(readout="ro", circuit=None)
test_circuit += ops.PragmaGetStateVector(readout="ri", circuit=None)

backend = Backend(number_qubits)
bit_regs, float_regs, complex_regs = backend.run_circuit(test_circuit)

print(bit_regs)
print(float_regs)
print(complex_regs)

Not implemented yet, but the same would be true for the PragmaGetStateVector too.

rreiner-hqs commented 2 weeks ago

Closing because there is a refactoring in progress, and this fix will be incorporated in the refactored version.