Make it easier to efficiently construct large circuits from lists of operations

Open
#7,720 4 comments 0 reactions 2 assignees View on GitHub

Maintainers usually reply within 1 day

@AamindMandragora is already working on this.

Since Oct 23, 2026.

Assessment

This issue has not been assessed yet.

Description

area/operators area/performance help wanted kind/feature-request priority/before-1.8 triage/accepted

Is your feature request related to a use case or problem? Please explain

Say that I have a list of already created Operations that I want to make into a circuit. I know of at least three different ways of doing that, all with different performances.

import cirq

n_ops_per_moment = 100
n_moments = 500

def get_layer():
    return [cirq.X(cirq.q(i)) for i in range(n_ops_per_moment)]

layers = [get_layer() for _ in range(n_moments)]
Option 1
circuit = cirq.Circuit(layers)

150 ms ± 1.64 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

Option 2
circuit = cirq.Circuit.from_moments(*layers)

28.3 ms ± 251 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

Option 3
circuit = cirq.Circuit.from_moments(*[cirq.Moment.from_ops(*layer) for layer in layers])

13.1 ms ± 418 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Describe the solution you would prefer

The last one is the fastest, but also the most awkward to write. At the very least, it would be nice to have a method on Circuit that makes it easier

@classmethod
def from_ops(cls, ops: Sequence[Sequence[Operation]]) -> Circuit
    ...

But overall it would be beneficial if there weren't large performance differences between Circuit construction methods since it makes it hard for users to do the best thing.

How urgent is this for you? Is it blocking important work?

P2 – we should do it in the next couple of quarters

Dominant language
Python
Stars
5.1k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
48

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quantumlib/Cirq

All issues in quantumlib/Cirq

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.