Skip to content

StatePreparation causes "Circuit cannot be mapped without using Swaps" on IBM #279

@cgogolin

Description

@cgogolin

Consider the following rather simple program:

import projectq as pq
from projectq.ops import All, X, StatePreparation, Measure
from projectq import MainEngine
import projectq.setups.ibm as ibm_setup

backend = pq.backends.IBMBackend(user='XXX', password='XXX')
eng = MainEngine(backend, engine_list=ibm_setup.get_engine_list())

qureg = eng.allocate_qureg(4)
StatePreparation([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) | qureg
All(Measure) | qureg
eng.flush()

which should be realizable by an application of X operations to some of the qubits.

On the IBM backend, it results in the following error:

RuntimeError: Circuit cannot be mapped without using Swaps. Mapping failed.
 raised in:
'  File "/home/cgogolin/.local/lib/python3.5/site-packages/projectq/cengines/_ibm5qubitmapper.py", line 137, in _run'
'    raise RuntimeError("Circuit cannot be mapped without using "'

The same happens for any other StatePreparation of basis state, including the trivial one, which shouldn't do anything. On up to three qubits all basis state preparations work flawlessly.

After changing to the simulator by putting

backend = pq.backends.Simulator()
eng = MainEngine(backend)

instead of the corresponding lines in the code above, everything also works on four qubits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions