I am trying to create this state: rho = = q . rho_{1,2} + r . rho_{2,3} + s . rho{1,3} + (1-q-r-s) . rho_separable

And I wrote this code:

   import random
import numpy as np
import cirq

circuit, circuit2, circuit3   = cirq.Circuit()
p = 0.2
q = 0.1
r = 0.3
alice, bob, charlie = cirq.LineQubit.range(1, 4)
rho_12 = circuit.append([cirq.H(alice), cirq.CNOT(alice, bob)]) 
#circuit.append([cirq.H(alice), cirq.CNOT(alice, bob)]) 
rho_23 = circuit.append([cirq.H(bob), cirq.CNOT(bob, charlie)]) 
rho_13 = circuit.append([cirq.H(alice), cirq.CNOT(alice, charlie)]) 
circuit = rho_12 + rho_23 + rho_13

In here I have 2 problem:

1)This line is not working: circuit = rho_12 + rho_23 + rho_13

2)I cannot multiply the state with p or q or r. What I mean is that I can't write this line:

rho_12 = circuit.append([cirq.H(alice), cirq.CNOT(alice, bob)]) * q 

Could you please show me how I can write this state?

  • $\begingroup$ append doesn't return anything, it adds into the circuit. Your circuit is in the circuit variable already; no need to add those things together. $\endgroup$ Oct 21, 2020 at 21:18
  • $\begingroup$ oh thank you very much and what about multiplying q or r or p. I can not write that: rho_12 = circuit.append([cirq.H(alice), cirq.CNOT(alice, bob)]) * q @CraigGidney $\endgroup$
    – quest
    Oct 21, 2020 at 21:26
  • $\begingroup$ You can multiply circuits like multiplied_circuit = cirq.Circuit(op1, op2) * 3. $\endgroup$ Oct 21, 2020 at 21:30
  • $\begingroup$ Hello, Thanks for the amswer but I want to multiply float number, we can think it like noise so with float number I cannot multiply $\endgroup$
    – quest
    Oct 21, 2020 at 22:06

1 Answer 1


You seem to think append is returning a circuit, instead of modifying the circuit you called it on. circuit.append(op) doesn't return anything, it adds an operation to circuit.

alice, bob, charlie = cirq.LineQubit.range(1, 4)
circuit = cirq.Circuit()
circuit.append([cirq.H(alice), cirq.CNOT(alice, bob)])
circuit.append([cirq.H(bob), cirq.CNOT(bob, charlie)]) 

Alternatively, you can make a new circuit for each of the pieces and then add them together:

rho_12 = cirq.Circuit(
    cirq.CNOT(alice, bob),
circuit = rho_12 + rho_23 + rho_13
  • $\begingroup$ Many thanks :) A small question: I wrote the same thing for ghz state too but I have a syntax error and I could not find. Maybe you can see can you have a look? ghz = cirq.Circuit( cirq.H(qubits[0]), for i in range (n-1): cirq.CNOT ( qubits [i] , qubits [i+1]), cirq.measure (* qubits , key ='x'), cirq.final_density_matrix(circuit), ) $\endgroup$
    – quest
    Oct 21, 2020 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.