Skip to content

[DRAFT] Unitary Layer RB #1561

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

[DRAFT] Unitary Layer RB #1561

wants to merge 16 commits into from

Conversation

dcmckayibm
Copy link
Collaborator

Added a new class to do layer fidelity with an arbitrary set of 2Q unitary circuits for the entangling layer. Example usage:

rzz_gate_lst = []

for i in range(10):

    qc = QuantumCircuit(2)
    qc.rzz(np.pi/2/10*(i+1),0,1)
    print(np.pi/2/10*(i+1))

    rzz_gate_lst.append(qc.to_instruction())


rb_obj = LayerFidelityUnitary(physical_qubits = [0,1,2,3], 
                              two_qubit_layers = [[[0,1],[2,3]]], 
                              two_qubit_gates=rzz_gate_lst, 
                              lengths = [2,10,100], backend=backend, num_samples=1, seed=1, layer_barrier=False)

Copy link
Collaborator

@wshanks wshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good!

opts = self.experiment_options
# validate two_qubit_gate if it is set
if opts.two_qubit_gates:
# TO DO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a to do or are we dropping validation? It should be easy to add the check if we are keeping this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to check these gate instructions are in the right basis set already. Actually I noticed something that might throw a wrench in your comment passing in an RZZGate object directly

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Qiskit documentation for definition describes it as "Return definition in terms of other basic gates". For RZZ, it is in terms of CX and RZ. Elsewhere the documentation says that the transpiler uses the definition to reason about basis gate equivalence. So I think what you highlight is okay -- the gates just have definitions in terms for CX to help with transpilation.

We can check that the gates are in the target by doing target.instruction_suported(g.name, qargs), similar to the one qubit case below but looping over the pairs in two_qubit_layers instead of the individual physical qubits. (We could also pass parameters to instruction_supported but there is not much point now. There is no support for ranges of valid parameters so all angles will still give True).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looking at your other comment on gate vs instruction, I see that you are thinking of the case of submitting an arbitrary circuit which will be a unitary that could be benchmarked, while I am thinking in terms of a single named gate, like rzz. For the abitrary circuit, we would need to check that the target supports all of its instructions (assuming we would not want to transpile it).

backend: Optional[Backend] = None,
num_samples: int = 6,
seed: Optional[Union[int, SeedSequence, BitGenerator, Generator]] = None,
two_qubit_gates: Sequence[CircuitInstruction] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_instruction actually returns an Instruction rather than a CircuitInstruction. Instruction is an abstract instruction that can be applied and CircuitInstruction is a specific application (it includes the qubits to apply the instruction on). Could we just make the type Gate though? That is a subclass of Instruction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, that probably makes more sense. And then it would be from a circuit using .to_gate()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't change any other code I assume?

Copy link
Collaborator

@wshanks wshanks May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would change other code. If we only supported a named gate and not the output of QuantumCircuit.to_instruction/QuantumCircuit.to_gate, I think we could take out the change to clifford_utils.py where a special case for instructions with names starting with "circuit" was added. I think that is falling into the case of adding internal instructions one by one instead of just data.append like it could if RZZGate was passed directly.

backend=backend,
num_samples=num_samples,
seed=seed,
two_qubit_gates=[qc.to_instruction()],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do from qiskit.circuit.library import RZZGate and two_qubit_gates=[RZZGate(0.5)] here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was more illustrative of how it would be done in a general case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question is which is the general case -- passing a list of individual Qiskit gates or passing a list of gates that are derived from circuits and contain multiple instructions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants