# Implementing Partial Trace in IBMs quantum computer

I am trying to implement the partial trace operation on IBMs quantum computer. I am simulating the depolarising channel with the following code

#aim here is to build the decoherence channel
p=0.1;
z=0.5+0.5*math.sqrt(1-p);
desiredvec=[
math.sqrt(1-z),
math.sqrt(z)]
circuit2 = QuantumCircuit(4,3);
circuit2.initialize(desiredvec,0)
circuit2.initialize(desiredvec,1)
circuit2.initialize(desiredvec,2)
circuit2.cx(0,3)
circuit2.h(3)
circuit2.s(3)
circuit2.cx(1,3)
circuit2.h(3)
circuit2.s(3)
circuit2.cx(2,3)
circuit2.h(3)
circuit2.s(3)
circuit2.draw()


I would now like to trace out all but qubit 3 as it is the only qubit I am interested in. I can get around this by just ignoring the other qubits but I would rather not do this. Is there any easy way to trace out unwanted qubits?

Or equivalently is there a way to initalise the qubit in a mixed state so that the extra ancillary qubits aren't needed in the first place?

qiskit.quantum_info has a partial_trace method you can use for this.

It takes as input either a Statevector or a DensityMatrix object. Both these classes implement the from_instruction routine that you can use with the QuantumCircuit object you already have. You would have to do something along the lines of:

circuit2 = QuantumCircuit(4,3)

...
{"ft_lang_label":"__label__en","ft_lang_prob":0.7664929,"math_prob":0.98120534,"size":920,"snap":"2020-45-2020-50","text_gpt3_token_len":281,"char_repetition_ratio":0.19432314,"word_repetition_ratio":0.0,"special_character_ratio":0.26847827,"punctuation_ratio":0.16746412,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9900693,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-21T22:46:03Z\",\"WARC-Record-ID\":\"<urn:uuid:ed94dcb1-0e30-46e2-bbfb-2d07435e01bd>\",\"Content-Length\":\"155306\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:645564ff-77fe-45e6-bf01-44a37ec13c03>\",\"WARC-Concurrent-To\":\"<urn:uuid:81395a6f-c52f-49bb-83df-c2bbd5e21a34>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://quantumcomputing.stackexchange.com/questions/13781/implementing-partial-trace-in-ibms-quantum-computer/13819\",\"WARC-Payload-Digest\":\"sha1:SBBECDBHW5VG7DNLNJDD7446OUP2C4M6\",\"WARC-Block-Digest\":\"sha1:36236KP5OKSNTOWPNCR6GCPCOIY3I6Z7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107878633.8_warc_CC-MAIN-20201021205955-20201021235955-00139.warc.gz\"}"}