Skip to content

Parametric Quantum Programs

Many quantum hybrid schemes such as VQE and QNN contain parametric circuits. This page explains how to assign them concrete values and execute the assigned circuits.

Assume parametric circuits with the parameters a and b.

The assigned values are organized in a dictionary. You can also pass multiple values by defining arguments as a 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:

  1. Using the QuantumProgram class.
  2. Using a keyword argument in the execute function.
  3. USing a positional argument in the execute function.
circuit = model.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: Options 1 and 3 work only for tuple arguments, whereas Options 2 and 4 work both for tuple and dict (i.e., a single set of values) arguments.