Skip to content

Incorrect boolean logic in [crates/transpiler/src/passes/inverse_cancellation.rs]: a && b || c should be a && (b || c) #15855

@Novchopin21

Description

@Novchopin21

Environment

  • Qiskit version: 2.5.0.dev0

What is happening?

The current condition of lines 267-271 in inverse_cancellation.rs is

if inst.qubits == next_inst.qubits
    && (inst.op.try_standard_gate() == Some(gate_0)
        && next_inst.op.try_standard_gate() == Some(gate_1))
    || (inst.op.try_standard_gate() == Some(gate_1)
        && next_inst.op.try_standard_gate() == Some(gate_0))

The a && b || c should be a && (b || c) here.

How can we reproduce the issue?

If nodes[i]'s gate is gate_1 and nodes[i+1]'s gate is gate_0, but their qubits are different,
then function std_inverse_pairs will still remove them.

What should happen?

The condition of lines 267-271 in inverse_cancellation.rs should be

if inst.qubits == next_inst.qubits
    && ((inst.op.try_standard_gate() == Some(gate_0)
        && next_inst.op.try_standard_gate() == Some(gate_1))
    || (inst.op.try_standard_gate() == Some(gate_1)
        && next_inst.op.try_standard_gate() == Some(gate_0)))

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions