Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay instruction is perhaps not working #6666

Closed
yaelbh opened this issue Jun 30, 2021 · 8 comments · Fixed by #6673
Closed

Delay instruction is perhaps not working #6666

yaelbh opened this issue Jun 30, 2021 · 8 comments · Fixed by #6673
Labels
bug Something isn't working

Comments

@yaelbh
Copy link
Contributor

yaelbh commented Jun 30, 2021

Information

  • Qiskit Terra version: main, stable
  • Python version: 3.9.5
  • Operating system: Linux (Ubuntu)

What is the current behavior?

Not sure if this issue belongs to the Terra repository or to another repository. I suspect that the machines ignore the delay instruction, because I don't see decoherence (i.e., excited qubits don't seem to tend towards the ground state as the delay increases).

Steps to reproduce the problem

from qiskit import IBMQ, QuantumCircuit, pulse

provider = IBMQ.load_account()
backend_names = ["armonk", "belem"]
backends = [provider.get_backend("ibmq_"+name) for name in backend_names]

delays = [1, 800]
delay_str = ["Short", "Long"]
methods = ["Delay", "Id"]
repeats = 4

print("Counts of ground state are expected to be small for short delay and large for long delay")
for backend, name in zip(backends, backend_names):
    id_length = backend.properties().gate_property("id", 0, "gate_length")[0]
    circs = []
    
    for method in methods:
        for d in delays:
            for i in range(repeats):
                circ = QuantumCircuit(1, 1)
                circ.x(0)
            
                if method == "Delay":
                    circ.delay(d, unit="us")
                else:
                    num_ids = int(d*1e-6 /  id_length)
                    assert(num_ids > 0)
                    for _ in range(num_ids):
                        circ.id(0)
                
                circ.measure(0, 0)
                circ.metadata = {"backend": name, "delay": d, "method": method}
                circs.append(circ)

    res = backend.run(circs).result()

    index = 0
    print("\nCounts of ground state in", name+":")
    for method in methods:
        print("  ", method, "instruction:")
        for d in delay_str:
            print("     ", d, "delay", repeats, "executions: ", end="")
            for i in range(repeats):
                print(res.get_counts(index)['0'], end=" ")
                index += 1
            print("")

Here's the output for Terra's main branch:

Counts of ground state are expected to be small for short delay and large for long delay

Counts of ground state in armonk:
   Delay instruction:
      Short delay 4 executions: 88 99 92 97 
      Long delay 4 executions: 108 99 97 105 
   Id instruction:
      Short delay 4 executions: 89 93 88 120 
      Long delay 4 executions: 958 942 947 950 

Counts of ground state in belem:
   Delay instruction:
      Short delay 4 executions: 96 86 93 93 
      Long delay 4 executions: 104 87 74 89 
   Id instruction:
      Short delay 4 executions: 104 115 129 101 
      Long delay 4 executions: 999 1008 1004 1001

The choice of machines is arbitrary, and I've observed the same behavior also for additional machines. Similar results are obtained for stable Terra. Apart from Terra I use the stable branches, e.g, stable IBMQ. Am I doing something wrong in the code?

@yaelbh yaelbh added the bug Something isn't working label Jun 30, 2021
@yaelbh
Copy link
Contributor Author

yaelbh commented Jun 30, 2021

Note that it's important to solve this issue, in order to enable characterization experiments in qiskit-experiments. @ajavadia @coruscating

@nonhermitian
Copy link
Contributor

It looks like the units are not understood. Doing dt seems to work whereas us does not

@nonhermitian
Copy link
Contributor

Actually I think any unit is is interpreted as dt. The unit seems to do nothing.

@nonhermitian
Copy link
Contributor

nonhermitian commented Jun 30, 2021

The circuit must be transpiled to go to dt after which it works. This is a bit confusing because delay is in the basis set, so one would naively assume that it can be executed just like any other gate in the basis set can be. There is nothing in the documentation that tells you this as well. There is also no warning that the circuit will not run as expected.

@yaelbh
Copy link
Contributor Author

yaelbh commented Jun 30, 2021

Yesterday I transpiled the circuit (the circuit then contained barriers, optimization level was 1); still I saw this phenomena in athens and santiago, but not in armonk. I'll try to reproduce.

@nonhermitian
Copy link
Contributor

The behavior is reproducible across systems such as Athens.

@yaelbh
Copy link
Contributor Author

yaelbh commented Jun 30, 2021

Consider the following code:

from qiskit import IBMQ, QuantumCircuit, execute

provider = IBMQ.load_account()
backend = provider.get_backend("ibmq_belem")

delays = [783, 790, 800]

circs = []
for d in delays:
    circ = QuantumCircuit(1, 1)
    circ.x(0)
    circ.delay(d, 0, unit="us")
    circ.measure(0, 0)
    circs.append(circ)

res = execute(circs, backend).result()
for i, d in enumerate(delays):
    print(d, ":", res.get_counts(i))

It works fine:

783 : {'0': 1016, '1': 8}
790 : {'0': 1010, '1': 14}
800 : {'0': 1010, '1': 14}

But removing 800 from the list of delays:

783 : {'1': 1024}
790 : {'1': 1024}

Can it be related to 800 being a multiple of 16 (thanks @eggerdj for the idea) ? Replacing 800 by 784 gives an incorrect result. Replacing 784 by 800 again gives again a correct result - the behavior looks consistent - you need to have 800 around in order for everything to work.

P.S. It also works fine when 800 is replaced by 816. But not 815. Can it be that the longest delay has to be a multiple of 16?

By the way, running transpile instead of execute results in circuits that make sense.

@ajavadia
Copy link
Member

Just as a reference the transpiled circuits are in dt, e.g.

                 ┌───┐┌────────────────────┐┌─┐
        q_0 -> 0 ┤ X ├┤ Delay(3523500[dt]) ├┤M├
                 └───┘└────────────────────┘└╥┘
  ancilla_0 -> 1 ────────────────────────────╫─
                                             ║ 
  ancilla_1 -> 2 ────────────────────────────╫─
                                             ║ 
  ancilla_2 -> 3 ────────────────────────────╫─

@mergify mergify bot closed this as completed in #6673 Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants