Parametric Quantum Programs¶
Parametric circuits can be found in many quantum hybrid schemes such as VQE and QNN. Here, we explain how to assign them concrete values and execute the assigned circuits.
Let's assume we have parametric circuits with the parameters a
and b
.
The assigned values are organized in a dictionary. Multiple values can also be
passed by defining arguments
as tuple of dictionaries:
# assigning set of values
arguments = {"a": 1, "b": 2}
# assigning multiple sets of values
arguments = ({"a": 1, "b": 2}, {"a": 3, "b": 4})
It is possible to pass these values to the circuit in several equivalent manners, but it is important not to combine more than one definition method.
- Using
QuantumProgram
class. - Using keyword argument to
execute
function. - USing positional argument to
execute
function.
circuit = model_designer.synthesize()
qasm_code = circuit.transpiled_circuit.qasm
executor = Executor(...)
# option 1:
program = QuantumProgram(code=qasm_code, arguments=arguments)
result = executor.execute(program)
# option 2:
result = executor.execute(qasm_code, arguments=arguments)
# option 3:
result = executor.execute(qasm_code, *arguments)
# option 4:
result = executor.execute(qasm_code, arguments)
Note that options 1 and 3 work only for arguments
being a tuple, whereas options 2 and 4 work both for arguments
being a tuple or being a dict (i.e. a single set of values)