Randomized Compiling 1

This example will take a circuit and generate 30 randomly compiled circuits that implement the same unitary as the original circuit.

Note

Randomized compiling produces a new circuit collection after each call, so the output of this example will be different if it’s executed again.

Note

Cycles containing multi-qubit gates are assigned to be immutable by default, while single-qubit gates are mutable by default. Randomized compiling will not attempt to compile new gates into immutable cycles.

Import True-Q:

import trueq as tq

Define a circuit which applies alternating cycles, with an X gate on qubit 0 in one cycle and a controlled-Z gate on qubits 0 and 1 in the other cycle:

cycle1 = tq.Cycle({(0,): tq.Gate.x})
cycle2 = tq.Cycle({(0, 1): tq.Gate.cz})
circuit = tq.Circuit([cycle1, cycle2, cycle1, cycle2, cycle1])

Display the original circuit:

circuit
  •  
    • (0) Gate.x
      • Name:

        • Gate.x
      • Aliases:

        • Gate.x
        • Gate.cliff1
      • Generators:

        • 'X': 180.0
      • Matrix:

  • imm
    • (0, 1) Gate.cz
      • Name:

        • Gate.cz
      • Aliases:

        • Gate.cz
      • Likeness:

        • CNOT
      • Generators:

        • 'IZ': 90.0
        • 'ZI': 90.0
        • 'ZZ': -90.0
      • Matrix:

  •  
    • (0) Gate.x
      • Name:

        • Gate.x
      • Aliases:

        • Gate.x
        • Gate.cliff1
      • Generators:

        • 'X': 180.0
      • Matrix:

  • imm
    • (0, 1) Gate.cz
      • Name:

        • Gate.cz
      • Aliases:

        • Gate.cz
      • Likeness:

        • CNOT
      • Generators:

        • 'IZ': 90.0
        • 'ZI': 90.0
        • 'ZZ': -90.0
      • Matrix:

  •  
    • (0) Gate.x
      • Name:

        • Gate.x
      • Aliases:

        • Gate.x
        • Gate.cliff1
      • Generators:

        • 'X': 180.0
      • Matrix:



Call randomized compiling on the circuit:

compiled_circuit = tq.randomly_compile(circuit)

Display one of the randomly compiled circuits:

compiled_circuit[0]
  •  
    • (0) Gate.x
      • Name:

        • Gate.x
      • Aliases:

        • Gate.x
        • Gate.cliff1
      • Generators:

        • 'X': 180.0
      • Matrix:

    • (1) Gate.y
      • Name:

        • Gate.y
      • Aliases:

        • Gate.y
        • Gate.cliff2
      • Generators:

        • 'Y': 180.0
      • Matrix:

  • imm
    • (0, 1) Gate.cz
      • Name:

        • Gate.cz
      • Aliases:

        • Gate.cz
      • Likeness:

        • CNOT
      • Generators:

        • 'IZ': 90.0
        • 'ZI': 90.0
        • 'ZZ': -90.0
      • Matrix:

  •  
    • (0) Gate.id
      • Name:

        • Gate.id
      • Aliases:

        • Gate.id
        • Gate.i
        • Gate.cliff0
      • Likeness:

        • Identity
      • Generators:

        • 'I': 0
      • Matrix:

    • (1) Gate.y
      • Name:

        • Gate.y
      • Aliases:

        • Gate.y
        • Gate.cliff2
      • Generators:

        • 'Y': 180.0
      • Matrix:

  • imm
    • (0, 1) Gate.cz
      • Name:

        • Gate.cz
      • Aliases:

        • Gate.cz
      • Likeness:

        • CNOT
      • Generators:

        • 'IZ': 90.0
        • 'ZI': 90.0
        • 'ZZ': -90.0
      • Matrix:

  •  
    • (0) Gate.z
      • Name:

        • Gate.z
      • Aliases:

        • Gate.z
        • Gate.cliff3
      • Generators:

        • 'Z': -180.0
      • Matrix:

    • (1) Gate.z
      • Name:

        • Gate.z
      • Aliases:

        • Gate.z
        • Gate.cliff3
      • Generators:

        • 'Z': -180.0
      • Matrix:



Total running time of the script: ( 0 minutes 0.015 seconds)

Gallery generated by Sphinx-Gallery