Repository: rigetti/quil-rs (language: python)

Issue:
Argument serialization for DEFCIRCUIT is incorrect
The below script reproduces the issue:

```py
from quil.program import Program
quil = """
DECLARE params REAL[3]
DEFCIRCUIT ZXZXZ(%phi, %lambda, %theta) q:
    RZ(%phi) q
    RX(pi/2) q
    RZ(%lambda) q
    RX(pi/2) q
    RZ(%theta) q

ZXZXZ(params[0], params[1], params[2]) 0
"""
print(Program.parse(quil).to_quil())
Program.parse(Program.parse(quil).to_quil())
```

Output:

```
DECLARE params REAL[3]
DEFCIRCUIT ZXZXZ(%phi%lambda%theta) q:
	RZ(%phi) q
	RX(pi/2) q
	RZ(%lambda) q
	RX(pi/2) q
	RZ(%theta) q

ZXZXZ(params[0], params[1], params[2]) 0

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
quil.PyProgramError: error while parsing: at line 2, column 1 (COMMAND(DEFCIRCUIT)): failed to parse arguments for DEFCIRCUIT
```


Discussion / hints:

Fix patch:
diff --git a/quil-rs/src/instruction/circuit.rs b/quil-rs/src/instruction/circuit.rs
index 411f5b80..90e4ccba 100644
--- a/quil-rs/src/instruction/circuit.rs
+++ b/quil-rs/src/instruction/circuit.rs
@@ -41,7 +41,7 @@ impl Quil for CircuitDefinition {
                 write!(writer, "%{}", p)?;
             }
             for p in iter {
-                write!(writer, "%{}", p)?;
+                write!(writer, ", %{}", p)?;
             }
             write!(writer, ")")?;
         }
@@ -102,6 +102,49 @@ mod test_circuit_definition {
     )]
     #[case(
         "CircuitDefinition With Params",
+        CircuitDefinition {
+            name: "BELL".to_owned(),
+            parameters: vec!["a".to_owned(), "b".to_owned()],
+            qubit_variables: vec!["a".to_owned(), "b".to_owned()],
+            instructions: vec![
+                Instruction::Gate(Gate {
+                    name: "RZ".to_owned(),
+                    parameters: vec![Expression::Variable("a".to_owned())],
+                    qubits: vec![Qubit::Variable("a".to_owned())],
+                    modifiers: vec![],
+                }),
+                Instruction::Gate(Gate {
+                    name: "RZ".to_owned(),
+                    parameters: vec![Expression::Variable("b".to_owned())],
+                    qubits: vec![Qubit::Variable("a".to_owned())],
+                    modifiers: vec![],
+                }),
+                Instruction::Gate(Gate {
+                    name: "RX".to_owned(),
+                    parameters: vec![Expression::Variable("a".to_owned())],
+                    qubits: vec![Qubit::Variable("a".to_owned())],
+                    modifiers: vec![],
+                }),
+                Instruction::Gate(Gate {
+                    name: "RZ".to_owned(),
+                    parameters: vec![Expression::Variable("a".to_owned())],
+                    qubits: vec![Qubit::Variable("a".to_owned())],
+                    modifiers: vec![],
+                }),
+                Instruction::Gate(Gate {
+                    name: "CNOT".to_owned(),
+                    parameters: vec![],
+                    qubits: vec![
+                        Qubit::Variable("a".to_owned()),
+                        Qubit::Variable("b".to_owned())
+                    ],
+                    modifiers: vec![],
+                })
+            ]
+        }
+    )]
+    #[case(
+        "CircuitDefinition With Single Param",
         CircuitDefinition {
             name: "BELL".to_owned(),
             parameters: vec!["a".to_owned()],


Test patch:
diff --git a/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Params.snap b/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Params.snap
index 4857f20f..8d61c97d 100644
--- a/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Params.snap
+++ b/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Params.snap
@@ -2,8 +2,9 @@
 source: quil-rs/src/instruction/circuit.rs
 expression: circuit_def.to_string()
 ---
-DEFCIRCUIT BELL(%a) a b:
+DEFCIRCUIT BELL(%a, %b) a b:
 	RZ(%a) a
+	RZ(%b) a
 	RX(%a) a
 	RZ(%a) a
 	CNOT a b
diff --git a/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Single Param.snap b/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Single Param.snap
new file mode 100644
index 00000000..74a75f4f
--- /dev/null
+++ b/quil-rs/src/instruction/snapshots/quil_rs__instruction__circuit__test_circuit_definition__display@CircuitDefinition With Single Param.snap
@@ -0,0 +1,10 @@
+---
+source: quil-rs/src/instruction/circuit.rs
+expression: circuit_def.to_quil_or_debug()
+---
+DEFCIRCUIT BELL(%a) a b:
+	RZ(%a) a
+	RX(%a) a
+	RZ(%a) a
+	CNOT a b
+