Compare commits

...

4 Commits

Author SHA1 Message Date
Tom Dodd a1c74b64c0 v2o.4.7 2020-10-05 06:16:51 +01:00
Tom Dodd 74983cd10a v2o.4.7 2020-10-05 05:58:47 +01:00
Tom Dodd 9ca16ee321 v2o.4.7 2020-10-05 05:41:30 +01:00
Tom Dodd 6abd59c1d3 v2o.4.7 2020-10-05 05:21:42 +01:00
39 changed files with 754 additions and 198 deletions

View File

@ -1,3 +1,12 @@
v2o.4.7
+ Added quantum computer Python Qiskit code generation
* Code is now generated by using a code generator component rather than the controller
+ Added salt to recipe hash caching to avoid clashes (salt is incremented if a clash occurs and hashes are recalculated)
* Fixed broken quantum computer component recipes
v2o.4.6 v2o.4.6
+ Added huge glowing mushrooms + Added huge glowing mushrooms
@ -14,7 +23,7 @@ v2o.4.6
v2o.4.5 v2o.4.5
+ Added WIP OpenQASM code generation mode to quantum computers + Added WIP QASM code generation mode to quantum computers for use with IBM Q
* Fixed crash on placing Rock Crusher * Fixed crash on placing Rock Crusher

View File

@ -1,7 +1,7 @@
mc_version=1.12.2 mc_version=1.12.2
forge_version=14.23.5.2847 forge_version=14.23.5.2847
mapping_version=stable_39 mapping_version=stable_39
mod_version=2o.4.6 mod_version=2o.4.7
ic2_version=2.8.197-ex112 ic2_version=2.8.197-ex112
jei_version=4.15.0.293 jei_version=4.15.0.293

View File

@ -224,7 +224,7 @@ public class NCConfig {
public static double accelerator_supercooler_coolant; public static double accelerator_supercooler_coolant;
public static int quantum_max_qubits_live; public static int quantum_max_qubits_live;
public static int quantum_max_qubits_qasm; public static int quantum_max_qubits_code;
public static int quantum_angle_precision; public static int quantum_angle_precision;
public static int[] tool_mining_level; public static int[] tool_mining_level;
@ -758,8 +758,8 @@ public class NCConfig {
Property propertyQuantumMaxQubitsLive = config.get(CATEGORY_QUANTUM, "quantum_max_qubits_live", 7, Lang.localise("gui.nc.config.quantum_max_qubits_live.comment"), 1, 14); Property propertyQuantumMaxQubitsLive = config.get(CATEGORY_QUANTUM, "quantum_max_qubits_live", 7, Lang.localise("gui.nc.config.quantum_max_qubits_live.comment"), 1, 14);
propertyQuantumMaxQubitsLive.setLanguageKey("gui.nc.config.quantum_max_qubits_live"); propertyQuantumMaxQubitsLive.setLanguageKey("gui.nc.config.quantum_max_qubits_live");
Property propertyQuantumMaxQubitsQasm = config.get(CATEGORY_QUANTUM, "quantum_max_qubits_qasm", 16, Lang.localise("gui.nc.config.quantum_max_qubits_qasm.comment"), 1, 32); Property propertyQuantumMaxQubitsCode = config.get(CATEGORY_QUANTUM, "quantum_max_qubits_code", 16, Lang.localise("gui.nc.config.quantum_max_qubits_code.comment"), 1, 32);
propertyQuantumMaxQubitsQasm.setLanguageKey("gui.nc.config.quantum_max_qubits_qasm"); propertyQuantumMaxQubitsCode.setLanguageKey("gui.nc.config.quantum_max_qubits_code");
Property propertyQuantumAnglePrecision = config.get(CATEGORY_QUANTUM, "quantum_angle_precision", 16, Lang.localise("gui.nc.config.quantum_angle_precision.comment"), 2, 5760); Property propertyQuantumAnglePrecision = config.get(CATEGORY_QUANTUM, "quantum_angle_precision", 16, Lang.localise("gui.nc.config.quantum_angle_precision.comment"), 2, 5760);
propertyQuantumAnglePrecision.setLanguageKey("gui.nc.config.quantum_angle_precision"); propertyQuantumAnglePrecision.setLanguageKey("gui.nc.config.quantum_angle_precision");
@ -1216,7 +1216,7 @@ public class NCConfig {
List<String> propertyOrderQuantum = new ArrayList<>(); List<String> propertyOrderQuantum = new ArrayList<>();
propertyOrderQuantum.add(propertyQuantumMaxQubitsLive.getName()); propertyOrderQuantum.add(propertyQuantumMaxQubitsLive.getName());
propertyOrderQuantum.add(propertyQuantumMaxQubitsQasm.getName()); propertyOrderQuantum.add(propertyQuantumMaxQubitsCode.getName());
propertyOrderQuantum.add(propertyQuantumAnglePrecision.getName()); propertyOrderQuantum.add(propertyQuantumAnglePrecision.getName());
config.setCategoryPropertyOrder(CATEGORY_QUANTUM, propertyOrderQuantum); config.setCategoryPropertyOrder(CATEGORY_QUANTUM, propertyOrderQuantum);
@ -1540,7 +1540,7 @@ public class NCConfig {
accelerator_supercooler_coolant = propertyAcceleratorSupercoolerCoolant.getDouble(); accelerator_supercooler_coolant = propertyAcceleratorSupercoolerCoolant.getDouble();
quantum_max_qubits_live = propertyQuantumMaxQubitsLive.getInt(); quantum_max_qubits_live = propertyQuantumMaxQubitsLive.getInt();
quantum_max_qubits_qasm = propertyQuantumMaxQubitsQasm.getInt(); quantum_max_qubits_code = propertyQuantumMaxQubitsCode.getInt();
quantum_angle_precision = propertyQuantumAnglePrecision.getInt(); quantum_angle_precision = propertyQuantumAnglePrecision.getInt();
tool_mining_level = readIntegerArrayFromConfig(propertyToolMiningLevel); tool_mining_level = readIntegerArrayFromConfig(propertyToolMiningLevel);
@ -1864,7 +1864,7 @@ public class NCConfig {
propertyAcceleratorSupercoolerCoolant.set(accelerator_supercooler_coolant); propertyAcceleratorSupercoolerCoolant.set(accelerator_supercooler_coolant);
propertyQuantumMaxQubitsLive.set(quantum_max_qubits_live); propertyQuantumMaxQubitsLive.set(quantum_max_qubits_live);
propertyQuantumMaxQubitsQasm.set(quantum_max_qubits_qasm); propertyQuantumMaxQubitsCode.set(quantum_max_qubits_code);
propertyQuantumAnglePrecision.set(quantum_angle_precision); propertyQuantumAnglePrecision.set(quantum_angle_precision);
propertyToolMiningLevel.set(tool_mining_level); propertyToolMiningLevel.set(tool_mining_level);

View File

@ -193,6 +193,8 @@ public class NCBlocks {
public static Block quantum_computer_connector; public static Block quantum_computer_connector;
public static Block quantum_computer_code_generator;
public static void init() { public static void init() {
ore = withName(new BlockMeta.BlockOre(), "ore"); ore = withName(new BlockMeta.BlockOre(), "ore");
ingot_block = withName(new BlockMeta.BlockIngot(), "ingot_block"); ingot_block = withName(new BlockMeta.BlockIngot(), "ingot_block");
@ -394,6 +396,8 @@ public class NCBlocks {
quantum_computer_gate_swap = withName(new BlockQuantumComputerGate.Swap(), "quantum_computer_gate_swap"); quantum_computer_gate_swap = withName(new BlockQuantumComputerGate.Swap(), "quantum_computer_gate_swap");
quantum_computer_connector = withName(new BlockQuantumComputerConnector(), "quantum_computer_connector"); quantum_computer_connector = withName(new BlockQuantumComputerConnector(), "quantum_computer_connector");
quantum_computer_code_generator = withName(new BlockQuantumComputerCodeGenerator(), "quantum_computer_code_generator");
} }
} }
@ -599,6 +603,8 @@ public class NCBlocks {
registerBlock(quantum_computer_gate_swap, new ItemBlockMeta(quantum_computer_gate_swap, QuantumGateEnums.SwapType.class, TextFormatting.AQUA)); registerBlock(quantum_computer_gate_swap, new ItemBlockMeta(quantum_computer_gate_swap, QuantumGateEnums.SwapType.class, TextFormatting.AQUA));
registerBlock(quantum_computer_connector); registerBlock(quantum_computer_connector);
registerBlock(quantum_computer_code_generator, new ItemBlockMeta(quantum_computer_code_generator, BlockQuantumComputerCodeGenerator.Type.class, TextFormatting.AQUA));
} }
} }
@ -835,6 +841,10 @@ public class NCBlocks {
} }
registerRender(quantum_computer_connector); registerRender(quantum_computer_connector);
for (int i = 0; i < BlockQuantumComputerCodeGenerator.Type.values().length; i++) {
registerRender(quantum_computer_code_generator, i, "type=" + BlockQuantumComputerCodeGenerator.Type.values()[i].getName());
}
} }
} }

View File

@ -11,6 +11,7 @@ import nc.multiblock.fission.tile.port.*;
import nc.multiblock.heatExchanger.HeatExchangerTubeType; import nc.multiblock.heatExchanger.HeatExchangerTubeType;
import nc.multiblock.heatExchanger.tile.*; import nc.multiblock.heatExchanger.tile.*;
import nc.multiblock.qComputer.QuantumGateEnums; import nc.multiblock.qComputer.QuantumGateEnums;
import nc.multiblock.qComputer.block.BlockQuantumComputerCodeGenerator;
import nc.multiblock.qComputer.tile.*; import nc.multiblock.qComputer.tile.*;
import nc.multiblock.rtg.tile.TileRTG; import nc.multiblock.rtg.tile.TileRTG;
import nc.multiblock.turbine.TurbineDynamoCoilType; import nc.multiblock.turbine.TurbineDynamoCoilType;
@ -295,5 +296,8 @@ public class NCTiles {
GameRegistry.registerTileEntity(TileQuantumComputerConnector.class, Global.MOD_ID + ":quantum_computer_connector"); GameRegistry.registerTileEntity(TileQuantumComputerConnector.class, Global.MOD_ID + ":quantum_computer_connector");
GameRegistry.registerTileEntity(TileQuantumComputerPort.class, Global.MOD_ID + ":quantum_computer_port"); GameRegistry.registerTileEntity(TileQuantumComputerPort.class, Global.MOD_ID + ":quantum_computer_port");
GameRegistry.registerTileEntity(TileQuantumComputerCodeGenerator.Qasm.class, Global.MOD_ID + ":quantum_computer_code_generator_" + BlockQuantumComputerCodeGenerator.Type.QASM.getName());
GameRegistry.registerTileEntity(TileQuantumComputerCodeGenerator.Qiskit.class, Global.MOD_ID + ":quantum_computer_code_generator_" + BlockQuantumComputerCodeGenerator.Type.QISKIT.getName());
} }
} }

View File

@ -1,6 +1,6 @@
# The MIT License (MIT) # The MIT License (MIT)
Copyright (c) 2016 "ZeroNoRyouki" Copyright (c) 2020 "tomdodd4598"
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -92,5 +92,6 @@ public final class MultiblockHandler {
QuantumComputer.PART_CLASSES.add(TileQuantumComputerController.class); QuantumComputer.PART_CLASSES.add(TileQuantumComputerController.class);
QuantumComputer.PART_CLASSES.add(TileQuantumComputerQubit.class); QuantumComputer.PART_CLASSES.add(TileQuantumComputerQubit.class);
QuantumComputer.PART_CLASSES.add(TileQuantumComputerCodeGenerator.class);
} }
} }

View File

@ -38,8 +38,8 @@ public class QuantumComputer extends Multiblock<IQuantumComputerPart, Multiblock
protected Queue<QuantumGate> queue = new ConcurrentLinkedQueue<>(); protected Queue<QuantumGate> queue = new ConcurrentLinkedQueue<>();
public boolean qasmStart = false, qasmWrite = false; public int codeStart = -1, codeType = -1;
protected StringBuilder qasmStringBuilder = new StringBuilder(); protected StringBuilder codeBuilder;
public QuantumComputer(World world) { public QuantumComputer(World world) {
super(world); super(world);
@ -82,7 +82,7 @@ public class QuantumComputer extends Multiblock<IQuantumComputerPart, Multiblock
} }
public static int getMaxQubits() { public static int getMaxQubits() {
return Math.max(quantum_max_qubits_live, quantum_max_qubits_qasm); return Math.max(quantum_max_qubits_live, quantum_max_qubits_code);
} }
protected void onQuantumComputerFormed() { protected void onQuantumComputerFormed() {
@ -145,9 +145,9 @@ public class QuantumComputer extends Multiblock<IQuantumComputerPart, Multiblock
multiblock.setLastError(Global.MOD_ID + ".multiblock_validation.too_many_controllers", null); multiblock.setLastError(Global.MOD_ID + ".multiblock_validation.too_many_controllers", null);
return false; return false;
} }
int q = qubitCount(); int q = qubitCount(), max = getMaxQubits();
if (q > getMaxQubits()) { if (q > max) {
multiblock.setLastError(Global.MOD_ID + ".multiblock_validation.quantum_computer.too_many_qubits", null, q, getMaxQubits()); multiblock.setLastError(Global.MOD_ID + ".multiblock_validation.quantum_computer.too_many_qubits", null, q, max);
return false; return false;
} }
@ -173,10 +173,10 @@ public class QuantumComputer extends Multiblock<IQuantumComputerPart, Multiblock
boolean refresh = false; boolean refresh = false;
int q = qubitCount(); int q = qubitCount();
if (qasmStart) { if (codeStart >= 0) {
qasmStart = false; codeType = codeStart;
qasmWrite = true; codeStart = -1;
qasmStringBuilder = new StringBuilder(); codeBuilder = new StringBuilder();
} }
QuantumGate gate = queue.poll(); QuantumGate gate = queue.poll();
@ -198,15 +198,15 @@ public class QuantumComputer extends Multiblock<IQuantumComputerPart, Multiblock
} }
} }
if (qasmWrite) { if (codeType >= 0) {
if (q <= quantum_max_qubits_qasm) { if (q <= quantum_max_qubits_code) {
List<String> qasmCode = gate.qasmCode(); List<String> code = gate.getCode(codeType);
if (!qasmCode.isEmpty()) { if (!code.isEmpty()) {
qasmStringBuilder.append(IOHelper.NEW_LINE); codeBuilder.append(IOHelper.NEW_LINE);
} }
for (String line : qasmCode) { for (String line : code) {
qasmStringBuilder.append(line); codeBuilder.append(line);
qasmStringBuilder.append(IOHelper.NEW_LINE); codeBuilder.append(IOHelper.NEW_LINE);
} }
} }
} }
@ -673,44 +673,117 @@ public class QuantumComputer extends Multiblock<IQuantumComputerPart, Multiblock
gate(m); gate(m);
} }
public void qasmPrint(EntityPlayer player) { public void printCode(EntityPlayer player) {
if (!qasmWrite) { if (codeType < 0) {
return; return;
} }
qasmWrite = false; int codeType = this.codeType;
this.codeType = -1;
int q = qubitCount(); int q = qubitCount();
if (q > quantum_max_qubits_qasm) { if (q > quantum_max_qubits_code) {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.qasm_exit_too_many_qubits"))); player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.code_exit_too_many_qubits")));
return; return;
} }
String qasmString = qasmStringBuilder.toString(); String codeString = codeBuilder.toString();
qasmStringBuilder = new StringBuilder(); String s = IOHelper.NEW_LINE, d = s + s;
if (qasmString.isEmpty()) { if (codeType == 0) {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.qasm_exit"))); if (codeString.isEmpty()) {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.qasm_exit_empty")));
return; return;
} }
File out = new File("nuclearcraft/quantum/" + q + "_qubit_" + System.currentTimeMillis() + ".qasm"); File out = new File("nuclearcraft/quantum/qasm/" + q + "_qubit_" + System.currentTimeMillis() + ".qasm");
String s = IOHelper.NEW_LINE; codeString = "OPENQASM 2.0;" + s +
qasmString = "OPENQASM 2.0;" + s + "include \"qelib1.inc\";" + s + s + "qreg q[" + q + "];" + s + "creg c[" + q + "];" + s + qasmString; "include \"qelib1.inc\";" + d +
"qreg q[" + q + "];" + s +
"creg c[" + q + "];" + s +
codeString;
ITextComponent link = new TextComponentString(out.getName()); ITextComponent link = new TextComponentString(out.getName());
link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, out.getAbsolutePath())).setBold(true).setUnderlined(true); link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, out.getAbsolutePath())).setBold(true).setUnderlined(true);
try { try {
FileUtils.writeStringToFile(out, qasmString); FileUtils.writeStringToFile(out, codeString);
player.sendMessage(new TextComponentTranslation("info.nuclearcraft.multitool.quantum_computer.controller.qasm_print", new Object[] {link})); player.sendMessage(new TextComponentTranslation("info.nuclearcraft.multitool.quantum_computer.controller.qasm_print", new Object[] {link}));
} }
catch (IOException e) { catch (IOException e) {
NCUtil.getLogger().catching(e); NCUtil.getLogger().catching(e);
player.sendMessage(new TextComponentTranslation("info.nuclearcraft.multitool.quantum_computer.controller.qasm_error", new Object[] {link})); player.sendMessage(new TextComponentTranslation("info.nuclearcraft.multitool.quantum_computer.controller.qasm_error", new Object[] {out.getAbsolutePath()}));
}
}
else if (codeType == 1) {
if (codeString.isEmpty()) {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.qiskit_exit_empty")));
return;
} }
qasmString = ""; File out = new File("nuclearcraft/quantum/qiskit/" + q + "_qubit_" + System.currentTimeMillis() + ".ipynb");
codeString = "# Jupyter plot output mode" + s +
"%matplotlib inline" + d +
"# Standard Qiskit libraries" + s +
"from qiskit import *" + s +
"from qiskit.compiler import transpile, assemble" + s +
"from qiskit.providers.ibmq import least_busy" + s +
"from qiskit.visualization import *" + s +
"from qiskit.tools.monitor import job_monitor" + s +
"from qiskit.tools.jupyter import *" + d +
"# Python maths" + s +
"import numpy as np" + s +
"from numpy import pi" + d +
"# Number of qubits" + s +
"qubits = " + q + d +
"# Load IBMQ account" + s +
"provider = IBMQ.load_account()" + s +
"simulator = provider.get_backend('ibmq_qasm_simulator')" + s +
"device = provider.get_backend('ibmq_16_melbourne')" + s +
"# quiet = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= qubits" + s +
" # and not x.configuration().simulator" + s +
" # and x.status().operational==True))" + d +
"# Helper function" + s +
"def run_job(circ_, backend_, shots_ = 1024, optimization_level_ = 1):" + s +
" print('Using ', backend_)" + s +
" job = execute(circ_, backend=backend_, shots=shots_, optimization_level=optimization_level_)" + s +
" job_monitor(job)" + s +
" return job.result()" + d +
"# Construct circuit" + s +
"qc = QuantumCircuit(qubits, qubits)" + s +
codeString + s +
"# Run circuit" + s +
"result = run_job(qc, backend_=simulator)" + s +
"counts = result.get_counts(qc)" + s +
"print('\\n', counts)" + d +
"# Printing results" + s +
"# NOTE: only one diagram can be shown per Jupyter cell." + s +
"# Either comment out all but one drawing/plotting method" + s +
"# or move them into separate cells." + d +
"# Draw circuit" + s +
"# qc.draw()" + d +
"# Plot results" + s +
"# plot_histogram(counts)" + s;
ITextComponent link = new TextComponentString(out.getName());
link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, out.getAbsolutePath())).setBold(true).setUnderlined(true);
try {
FileUtils.writeStringToFile(out, codeString);
player.sendMessage(new TextComponentTranslation("info.nuclearcraft.multitool.quantum_computer.controller.qiskit_print", new Object[] {link}));
}
catch (IOException e) {
NCUtil.getLogger().catching(e);
player.sendMessage(new TextComponentTranslation("info.nuclearcraft.multitool.quantum_computer.controller.qiskit_error", new Object[] {out.getAbsolutePath()}));
}
}
else {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.code_exit_empty")));
return;
}
codeString = null;
} }
} }

View File

@ -2,9 +2,10 @@ package nc.multiblock.qComputer;
import java.util.*; import java.util.*;
import com.google.common.base.Strings;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.objects.*; import it.unimi.dsi.fastutil.objects.*;
import joptsimple.internal.Strings;
import nc.util.*; import nc.util.*;
public abstract class QuantumGate<GATE extends QuantumGate> { public abstract class QuantumGate<GATE extends QuantumGate> {
@ -46,8 +47,7 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
/** Adds the required decomposition of this gate to the list. */ /** Adds the required decomposition of this gate to the list. */
public abstract void addRequiredDecomposition(List<QuantumGate> decomposition); public abstract void addRequiredDecomposition(List<QuantumGate> decomposition);
/** Lines of QASM Python code */ public abstract List<String> getCode(int type);
public abstract List<String> qasmCode();
public static class Measurement extends QuantumGate<Measurement> { public static class Measurement extends QuantumGate<Measurement> {
@ -105,12 +105,23 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
IntList l = list(n); IntList l = list(n);
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < l.size(); i++) { for (int i = 0; i < l.size(); i++) {
out.add("measure q[" + l.getInt(i) + "] -> c[" + l.getInt(i) + "];"); out.add("measure q[" + l.getInt(i) + "] -> c[" + l.getInt(i) + "];");
} }
}
else if (type == 1) {
if (!l.isEmpty()) {
String s = pythonArray(l);
out.add("qc.barrier(" + s + ")");
out.add("qc.measure(" + s + ", " + s + ")");
}
}
return out; return out;
} }
} }
@ -164,12 +175,23 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
int q = qc.qubitCount(); int q = qc.qubitCount();
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < q; i++) { for (int i = 0; i < q; i++) {
out.add("reset q[" + i + "];"); out.add("reset q[" + i + "];");
} }
}
else if (type == 1) {
if (q != 0) {
String s = pythonArray(CollectionHelper.increasingList(q));
out.add("qc.barrier(" + s + ")");
out.add("qc.reset(" + s + ")");
}
}
return out; return out;
} }
} }
@ -215,16 +237,27 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
IntList l = list(n); IntList l = list(n);
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < l.size(); i++) { for (int i = 0; i < l.size(); i++) {
out.add(qasmLine(l.getInt(i))); out.add(qasmLine(l.getInt(i)));
} }
}
else if (type == 1) {
if (!l.isEmpty()) {
out.add(qiskitLine(l));
}
}
return out; return out;
} }
public abstract String qasmLine(int i); public abstract String qasmLine(int i);
public abstract String qiskitLine(IntList l);
} }
public static class X extends Basic { public static class X extends Basic {
@ -264,6 +297,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "x q[" + i + "];"; return "x q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.x(" + pythonArray(l) + ")";
}
} }
public static class Y extends Basic { public static class Y extends Basic {
@ -303,6 +341,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "y q[" + i + "];"; return "y q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.y(" + pythonArray(l) + ")";
}
} }
public static class Z extends Basic { public static class Z extends Basic {
@ -342,6 +385,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "z q[" + i + "];"; return "z q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.z(" + pythonArray(l) + ")";
}
} }
public static class H extends Basic { public static class H extends Basic {
@ -381,6 +429,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "h q[" + i + "];"; return "h q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.h(" + pythonArray(l) + ")";
}
} }
public static class S extends Basic { public static class S extends Basic {
@ -420,6 +473,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "s q[" + i + "];"; return "s q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.s(" + pythonArray(l) + ")";
}
} }
public static class Sdg extends Basic { public static class Sdg extends Basic {
@ -459,6 +517,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "sdg q[" + i + "];"; return "sdg q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.sdg(" + pythonArray(l) + ")";
}
} }
public static class T extends Basic { public static class T extends Basic {
@ -498,6 +561,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "t q[" + i + "];"; return "t q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.t(" + pythonArray(l) + ")";
}
} }
public static class Tdg extends Basic { public static class Tdg extends Basic {
@ -537,6 +605,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(int i) { public String qasmLine(int i) {
return "tdg q[" + i + "];"; return "tdg q[" + i + "];";
} }
@Override
public String qiskitLine(IntList l) {
return "qc.tdg(" + pythonArray(l) + ")";
}
} }
public static abstract class BasicAngle extends QuantumGate<BasicAngle> { public static abstract class BasicAngle extends QuantumGate<BasicAngle> {
@ -574,12 +647,21 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public abstract BasicAngle newMerged(double angle, IntSet c, IntSet t); public abstract BasicAngle newMerged(double angle, IntSet c, IntSet t);
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
IntList l = list(n); IntList l = list(n);
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < l.size(); i++) { for (int i = 0; i < l.size(); i++) {
out.add(qasmLine(angle, l.getInt(i))); out.add(qasmLine(angle, l.getInt(i)));
} }
}
else if (type == 1) {
if (!l.isEmpty()) {
out.add(qiskitLine(angle, l));
}
}
return out; return out;
} }
@ -596,6 +678,8 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
public abstract String qasmLine(double angle, int i); public abstract String qasmLine(double angle, int i);
public abstract String qiskitLine(double angle, IntList l);
} }
public static class P extends BasicAngle { public static class P extends BasicAngle {
@ -635,6 +719,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(double angle, int i) { public String qasmLine(double angle, int i) {
return "u1(" + Math.toRadians(angle) + ") q[" + i + "];"; return "u1(" + Math.toRadians(angle) + ") q[" + i + "];";
} }
@Override
public String qiskitLine(double angle, IntList l) {
return "qc.u1(" + Math.toRadians(angle) + ", " + pythonArray(l) + ")";
}
} }
public static class RX extends BasicAngle { public static class RX extends BasicAngle {
@ -674,6 +763,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(double angle, int i) { public String qasmLine(double angle, int i) {
return "rx(" + Math.toRadians(angle) + ") q[" + i + "];"; return "rx(" + Math.toRadians(angle) + ") q[" + i + "];";
} }
@Override
public String qiskitLine(double angle, IntList l) {
return "qc.rx(" + Math.toRadians(angle) + ", " + pythonArray(l) + ")";
}
} }
public static class RY extends BasicAngle { public static class RY extends BasicAngle {
@ -713,6 +807,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(double angle, int i) { public String qasmLine(double angle, int i) {
return "ry(" + Math.toRadians(angle) + ") q[" + i + "];"; return "ry(" + Math.toRadians(angle) + ") q[" + i + "];";
} }
@Override
public String qiskitLine(double angle, IntList l) {
return "qc.ry(" + Math.toRadians(angle) + ", " + pythonArray(l) + ")";
}
} }
public static class RZ extends BasicAngle { public static class RZ extends BasicAngle {
@ -752,6 +851,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String qasmLine(double angle, int i) { public String qasmLine(double angle, int i) {
return "rz(" + Math.toRadians(angle) + ") q[" + i + "];"; return "rz(" + Math.toRadians(angle) + ") q[" + i + "];";
} }
@Override
public String qiskitLine(double angle, IntList l) {
return "qc.rz(" + Math.toRadians(angle) + ", " + pythonArray(l) + ")";
}
} }
public static abstract class Control extends Basic { public static abstract class Control extends Basic {
@ -796,12 +900,12 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
if (c.isEmpty()) { if (c.isEmpty()) {
return withoutControl().qasmCode(); return withoutControl().getCode(type);
} }
else if (c.size() == 1) { else if (c.size() == 1) {
return singleControlQasmCode(); return singleControlCode(type);
} }
List<QuantumGate> decomposition = new ArrayList<>(); List<QuantumGate> decomposition = new ArrayList<>();
@ -809,7 +913,7 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
for (QuantumGate gate : decomposition) { for (QuantumGate gate : decomposition) {
out.addAll(gate.qasmCode()); out.addAll(gate.getCode(type));
} }
return out; return out;
@ -820,17 +924,33 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
return ";"; return ";";
} }
public List<String> singleControlQasmCode() { @Override
public final String qiskitLine(IntList l) {
return "";
}
public List<String> singleControlCode(int type) {
int c = list(this.c).getInt(0); int c = list(this.c).getInt(0);
IntList l = list(n); IntList l = list(n);
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < l.size(); i++) { for (int i = 0; i < l.size(); i++) {
out.add(singleControlQasmLine(c, l.getInt(i))); out.add(singleControlQasmLine(c, l.getInt(i)));
} }
}
else if (type == 1) {
if (!l.isEmpty()) {
out.add(singleControlQiskitLine(c, l));
}
}
return out; return out;
} }
public abstract String singleControlQasmLine(int c, int i); public abstract String singleControlQasmLine(int c, int i);
public abstract String singleControlQiskitLine(int c, IntList l);
} }
public static class CX extends Control { public static class CX extends Control {
@ -955,18 +1075,18 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
if (c.isEmpty()) { if (c.isEmpty()) {
return withoutControl().qasmCode(); return withoutControl().getCode(type);
} }
int c_size = c.size(); int c_size = c.size();
if (c_size == 1) { if (c_size == 1) {
return singleControlQasmCode(); return singleControlCode(type);
} }
else if (c_size == 2) { else if (c_size == 2) {
return doubleControlQasmCode(); return doubleControlCode(type);
} }
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
@ -974,7 +1094,7 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
addRequiredDecomposition(decomposition); addRequiredDecomposition(decomposition);
for (QuantumGate gate : decomposition) { for (QuantumGate gate : decomposition) {
out.addAll(gate.qasmCode()); out.addAll(gate.getCode(type));
} }
return out; return out;
} }
@ -984,20 +1104,38 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
return "cx q[" + c + "], q[" + i + "];"; return "cx q[" + c + "], q[" + i + "];";
} }
public List<String> doubleControlQasmCode() { @Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cx(" + c + ", " + pythonArray(l) + ")";
}
public List<String> doubleControlCode(int type) {
IntList c_list = list(c); IntList c_list = list(c);
int c1 = c_list.getInt(0), c2 = c_list.getInt(1); int c1 = c_list.getInt(0), c2 = c_list.getInt(1);
IntList l = list(n); IntList l = list(n);
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < l.size(); i++) { for (int i = 0; i < l.size(); i++) {
out.add(doubleControlQasmLine(c1, c2, l.getInt(i))); out.add(doubleControlQasmLine(c1, c2, l.getInt(i)));
} }
}
else if (type == 1) {
if (!l.isEmpty()) {
out.add(doubleControlQiskitLine(c1, c2, l));
}
}
return out; return out;
} }
public String doubleControlQasmLine(int c1, int c2, int i) { public String doubleControlQasmLine(int c1, int c2, int i) {
return "ccx q[" + c1 + "], q[" + c2 + "], q[" + i + "];"; return "ccx q[" + c1 + "], q[" + c2 + "], q[" + i + "];";
} }
public String doubleControlQiskitLine(int c1, int c2, IntList l) {
return "qc.ccx(" + c1 + ", " + c2 + ", " + pythonArray(l) + ")";
}
} }
public static class CY extends Control { public static class CY extends Control {
@ -1042,6 +1180,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "cy q[" + c + "], q[" + i + "];"; return "cy q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cy(" + c + ", " + pythonArray(l) + ")";
}
} }
public static class CZ extends Control { public static class CZ extends Control {
@ -1086,6 +1229,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "cz q[" + c + "], q[" + i + "];"; return "cz q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cz(" + c + ", " + pythonArray(l) + ")";
}
} }
public static class CH extends Control { public static class CH extends Control {
@ -1130,6 +1278,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "ch q[" + c + "], q[" + i + "];"; return "ch q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.ch(" + c + ", " + pythonArray(l) + ")";
}
} }
public static class CS extends Control { public static class CS extends Control {
@ -1174,6 +1327,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "cu1(pi/2) q[" + c + "], q[" + i + "];"; return "cu1(pi/2) q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cu1(pi/2, " + c + ", " + pythonArray(l) + ")";
}
} }
public static class CSdg extends Control { public static class CSdg extends Control {
@ -1218,6 +1376,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "cu1(-pi/2) q[" + c + "], q[" + i + "];"; return "cu1(-pi/2) q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cu1(-pi/2, " + c + ", " + pythonArray(l) + ")";
}
} }
public static class CT extends Control { public static class CT extends Control {
@ -1262,6 +1425,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "cu1(pi/4) q[" + c + "], q[" + i + "];"; return "cu1(pi/4) q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cu1(pi/4, " + c + ", " + pythonArray(l) + ")";
}
} }
public static class CTdg extends Control { public static class CTdg extends Control {
@ -1306,6 +1474,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(int c, int i) { public String singleControlQasmLine(int c, int i) {
return "cu1(-pi/4) q[" + c + "], q[" + i + "];"; return "cu1(-pi/4) q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(int c, IntList l) {
return "qc.cu1(-pi/4, " + c + ", " + pythonArray(l) + ")";
}
} }
public static abstract class ControlAngle extends BasicAngle { public static abstract class ControlAngle extends BasicAngle {
@ -1354,12 +1527,12 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
if (c.isEmpty()) { if (c.isEmpty()) {
return withoutControl().qasmCode(); return withoutControl().getCode(type);
} }
else if (c.size() == 1) { else if (c.size() == 1) {
return singleControlQasmCode(); return singleControlCode(type);
} }
List<QuantumGate> decomposition = new ArrayList<>(); List<QuantumGate> decomposition = new ArrayList<>();
@ -1367,7 +1540,7 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
for (QuantumGate gate : decomposition) { for (QuantumGate gate : decomposition) {
out.addAll(gate.qasmCode()); out.addAll(gate.getCode(type));
} }
return out; return out;
@ -1378,17 +1551,33 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
return ";"; return ";";
} }
public List<String> singleControlQasmCode() { @Override
public final String qiskitLine(double angle, IntList l) {
return "";
}
public List<String> singleControlCode(int type) {
int c = list(this.c).getInt(0); int c = list(this.c).getInt(0);
IntList l = list(n); IntList l = list(n);
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (type == 0) {
for (int i = 0; i < l.size(); i++) { for (int i = 0; i < l.size(); i++) {
out.add(singleControlQasmLine(angle, c, l.getInt(i))); out.add(singleControlQasmLine(angle, c, l.getInt(i)));
} }
}
else if (type == 1) {
if (!l.isEmpty()) {
out.add(singleControlQiskitLine(angle, c, l));
}
}
return out; return out;
} }
public abstract String singleControlQasmLine(double angle, int c, int i); public abstract String singleControlQasmLine(double angle, int c, int i);
public abstract String singleControlQiskitLine(double angle, int c, IntList l);
} }
public static class CP extends ControlAngle { public static class CP extends ControlAngle {
@ -1433,6 +1622,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(double angle, int c, int i) { public String singleControlQasmLine(double angle, int c, int i) {
return "cu1(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];"; return "cu1(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(double angle, int c, IntList l) {
return "qc.cu1(" + Math.toRadians(angle) + ", " + c + ", " + pythonArray(l) + ")";
}
} }
public static class CRX extends ControlAngle { public static class CRX extends ControlAngle {
@ -1477,6 +1671,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(double angle, int c, int i) { public String singleControlQasmLine(double angle, int c, int i) {
return "crx(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];"; return "crx(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(double angle, int c, IntList l) {
return "qc.crx(" + Math.toRadians(angle) + ", " + c + ", " + pythonArray(l) + ")";
}
} }
public static class CRY extends ControlAngle { public static class CRY extends ControlAngle {
@ -1521,6 +1720,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(double angle, int c, int i) { public String singleControlQasmLine(double angle, int c, int i) {
return "cry(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];"; return "cry(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(double angle, int c, IntList l) {
return "qc.cry(" + Math.toRadians(angle) + ", " + c + ", " + pythonArray(l) + ")";
}
} }
public static class CRZ extends ControlAngle { public static class CRZ extends ControlAngle {
@ -1565,6 +1769,11 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public String singleControlQasmLine(double angle, int c, int i) { public String singleControlQasmLine(double angle, int c, int i) {
return "crz(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];"; return "crz(" + Math.toRadians(angle) + ") q[" + c + "], q[" + i + "];";
} }
@Override
public String singleControlQiskitLine(double angle, int c, IntList l) {
return "qc.crz(" + Math.toRadians(angle) + ", " + c + ", " + pythonArray(l) + ")";
}
} }
public static class Swap extends QuantumGate<Swap> { public static class Swap extends QuantumGate<Swap> {
@ -1626,13 +1835,22 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
@Override @Override
public List<String> qasmCode() { public List<String> getCode(int type) {
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (i.size() == j.size()) { if (i.size() == j.size()) {
if (type == 0) {
for (int k = 0; k < i.size(); k++) { for (int k = 0; k < i.size(); k++) {
out.add("swap q[" + i.getInt(k) + "], q[" + j.getInt(k) + "];"); out.add("swap q[" + i.getInt(k) + "], q[" + j.getInt(k) + "];");
} }
} }
else if (type == 1) {
for (int k = 0; k < i.size(); k++) {
out.add("qc.swap(" + i.getInt(k) + ", " + j.getInt(k) + ")");
}
}
}
return out; return out;
} }
} }
@ -1685,15 +1903,16 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
@Override @Override
// TODO // TODO
public List<String> qasmCode() { public List<String> getCode(int type) {
if (c.isEmpty()) { if (c.isEmpty()) {
return super.qasmCode(); return super.getCode(type);
} }
List<String> out = new ArrayList<>(); List<String> out = new ArrayList<>();
if (i.size() == j.size()) { if (i.size() == j.size() && !i.isEmpty()) {
IntList l = list(c); IntList l = list(c);
if (type == 0) {
if (l.size() == 1) { if (l.size() == 1) {
String s = "cswap q[" + l.getInt(0) + "], "; String s = "cswap q[" + l.getInt(0) + "], ";
for (int k = 0; k < i.size(); k++) { for (int k = 0; k < i.size(); k++) {
@ -1702,15 +1921,34 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
} }
else { else {
out.add("// multi-controlled swap decomposition not yet implemented!"); out.add("// multi-controlled swap decomposition not yet implemented!");
String s = "// " + Strings.repeat('c', l.size()) + "swap "; String s = Strings.repeat("c", l.size()) + "swap ";
for (int k = 0; k < l.size(); k++) { for (int k = 0; k < l.size(); k++) {
s += "q[" + l.getInt(k) + "], "; s += ("q[" + l.getInt(k) + "], ");
} }
for (int k = 0; k < i.size(); k++) { for (int k = 0; k < i.size(); k++) {
out.add(s + "q[" + i.getInt(k) + "], q[" + j.getInt(k) + "];"); out.add(s + "q[" + i.getInt(k) + "], q[" + j.getInt(k) + "];");
} }
} }
} }
else if (type == 1) {
if (l.size() == 1) {
String s = "qc.cswap(" + l.getInt(0) + ", ";
for (int k = 0; k < i.size(); k++) {
out.add(s + i.getInt(k) + ", " + j.getInt(k) + ")");
}
}
else {
out.add("# multi-controlled swap decomposition not yet implemented!");
String s = "qc." + Strings.repeat("c", l.size()) + "swap(";
for (int k = 0; k < l.size(); k++) {
s += (l.getInt(k) + ", ");
}
for (int k = 0; k < i.size(); k++) {
out.add(s + i.getInt(k) + ", " + j.getInt(k) + ")");
}
}
}
}
return out; return out;
} }
@ -1924,4 +2162,20 @@ public abstract class QuantumGate<GATE extends QuantumGate> {
public static boolean full(double angle) { public static boolean full(double angle) {
return angle % 720D == 0D; return angle % 720D == 0D;
} }
public static String pythonArray(IntList list) {
return pythonArray(list, false);
}
public static String pythonArray(IntList list, boolean forceBrackets) {
if (!forceBrackets && list.size() == 1) {
return Integer.toString(list.getInt(0));
}
String out = "[";
for (int i : list) {
out += (i + ", ");
}
return StringHelper.removeSuffix(out, 2) + "]";
}
} }

View File

@ -0,0 +1,106 @@
package nc.multiblock.qComputer.block;
import nc.enumm.IBlockMetaEnum;
import nc.multiblock.qComputer.tile.TileQuantumComputerCodeGenerator;
import net.minecraft.block.properties.*;
import net.minecraft.block.state.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockQuantumComputerCodeGenerator extends BlockQuantumComputerMetaPart<BlockQuantumComputerCodeGenerator.Type> {
public final static PropertyEnum<Type> TYPE = PropertyEnum.create("type", Type.class);
public BlockQuantumComputerCodeGenerator() {
super(Type.class, TYPE);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {TYPE});
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return values[meta].getTile();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player == null) {
return false;
}
if (hand != EnumHand.MAIN_HAND || player.isSneaking()) {
return false;
}
return rightClickOnPart(world, pos, player, hand, facing);
}
public static enum Type implements IStringSerializable, IBlockMetaEnum {
QASM("qasm", 0),
QISKIT("qiskit", 1);
private final String name;
private final int id;
private Type(String name, int id) {
this.name = name;
this.id = id;
}
@Override
public String getName() {
return name;
}
@Override
public String toString() {
return getName();
}
@Override
public int getID() {
return id;
}
@Override
public int getHarvestLevel() {
return 0;
}
@Override
public String getHarvestTool() {
return "pickaxe";
}
@Override
public float getHardness() {
return 2F;
}
@Override
public float getResistance() {
return 15F;
}
@Override
public int getLightValue() {
return 0;
}
public TileEntity getTile() {
switch (this) {
case QASM:
return new TileQuantumComputerCodeGenerator.Qasm();
case QISKIT:
return new TileQuantumComputerCodeGenerator.Qiskit();
default:
return null;
}
}
}
}

View File

@ -21,11 +21,6 @@ public class BlockQuantumComputerController extends BlockQuantumComputerPart {
return new TileQuantumComputerController(); return new TileQuantumComputerController();
} }
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
super.onBlockAdded(world, pos, state);
}
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player == null) { if (player == null) {

View File

@ -34,8 +34,8 @@ public abstract class BlockQuantumComputerGate<T extends Enum<T> & IStringSerial
} }
@Override @Override
public TileEntity createNewTileEntity(World world, int metadata) { public TileEntity createNewTileEntity(World world, int meta) {
return QuantumGateEnums.SingleType.values()[metadata].getTile(); return QuantumGateEnums.SingleType.values()[meta].getTile();
} }
} }
@ -53,8 +53,8 @@ public abstract class BlockQuantumComputerGate<T extends Enum<T> & IStringSerial
} }
@Override @Override
public TileEntity createNewTileEntity(World world, int metadata) { public TileEntity createNewTileEntity(World world, int meta) {
return QuantumGateEnums.ControlType.values()[metadata].getTile(); return QuantumGateEnums.ControlType.values()[meta].getTile();
} }
} }
@ -72,8 +72,8 @@ public abstract class BlockQuantumComputerGate<T extends Enum<T> & IStringSerial
} }
@Override @Override
public TileEntity createNewTileEntity(World world, int metadata) { public TileEntity createNewTileEntity(World world, int meta) {
return QuantumGateEnums.SwapType.values()[metadata].getTile(); return QuantumGateEnums.SwapType.values()[meta].getTile();
} }
} }

View File

@ -0,0 +1,76 @@
package nc.multiblock.qComputer.tile;
import static nc.config.NCConfig.quantum_max_qubits_code;
import nc.multiblock.qComputer.QuantumComputer;
import nc.util.Lang;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
public abstract class TileQuantumComputerCodeGenerator extends TileQuantumComputerPart {
protected final int codeType;
protected TileQuantumComputerCodeGenerator(int codeType) {
super();
this.codeType = codeType;
}
public static class Qasm extends TileQuantumComputerCodeGenerator {
public Qasm() {
super(0);
}
@Override
protected String getUnlocalizedCodeStartMessage() {
return "info.nuclearcraft.multitool.quantum_computer.controller.code_qasm_start";
}
}
public static class Qiskit extends TileQuantumComputerCodeGenerator {
public Qiskit() {
super(1);
}
@Override
protected String getUnlocalizedCodeStartMessage() {
return "info.nuclearcraft.multitool.quantum_computer.controller.code_qiskit_start";
}
}
@Override
public void onMachineAssembled(QuantumComputer multiblock) {
doStandardNullControllerResponse(multiblock);
}
@Override
public void onMachineBroken() {}
@Override
public boolean onUseMultitool(ItemStack multitoolStack, EntityPlayer player, World world, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!player.isSneaking()) {
QuantumComputer qc = getMultiblock();
if (qc != null && qc.isAssembled()) {
if (qc.codeType >= 0) {
qc.printCode(player);
}
else if (qc.qubitCount() <= quantum_max_qubits_code) {
qc.codeStart = codeType;
player.sendMessage(new TextComponentString(Lang.localise(getUnlocalizedCodeStartMessage())));
}
else {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.code_too_many_qubits")));
}
return true;
}
}
return super.onUseMultitool(multitoolStack, player, world, facing, hitX, hitY, hitZ);
}
protected abstract String getUnlocalizedCodeStartMessage();
}

View File

@ -1,14 +1,9 @@
package nc.multiblock.qComputer.tile; package nc.multiblock.qComputer.tile;
import nc.config.NCConfig;
import nc.multiblock.qComputer.*; import nc.multiblock.qComputer.*;
import nc.util.Lang;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*; import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World; import net.minecraft.world.World;
public class TileQuantumComputerController extends TileQuantumComputerPart implements ITickable { public class TileQuantumComputerController extends TileQuantumComputerPart implements ITickable {
@ -49,27 +44,6 @@ public class TileQuantumComputerController extends TileQuantumComputerPart imple
} }
} }
@Override
public boolean onUseMultitool(ItemStack multitoolStack, EntityPlayer player, World world, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player.isSneaking()) {
QuantumComputer qc = getMultiblock();
if (qc != null) {
if (qc.qasmWrite) {
qc.qasmPrint(player);
}
else if (qc.qubitCount() <= NCConfig.quantum_max_qubits_qasm) {
qc.qasmStart = true;
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.qasm_start")));
}
else {
player.sendMessage(new TextComponentString(Lang.localise("info.nuclearcraft.multitool.quantum_computer.controller.qasm_too_many_qubits")));
}
return true;
}
}
return super.onUseMultitool(multitoolStack, player, world, facing, hitX, hitY, hitZ);
}
@Override @Override
public NBTTagCompound writeAll(NBTTagCompound nbt) { public NBTTagCompound writeAll(NBTTagCompound nbt) {
super.writeAll(nbt); super.writeAll(nbt);

View File

@ -26,6 +26,7 @@ public abstract class AbstractRecipeHandler<RECIPE extends IRecipe> {
protected @Nonnull List<RECIPE> recipeList = new ArrayList<>(); protected @Nonnull List<RECIPE> recipeList = new ArrayList<>();
protected @Nonnull Long2ObjectMap<RECIPE> recipeCache = new Long2ObjectOpenHashMap<>(); protected @Nonnull Long2ObjectMap<RECIPE> recipeCache = new Long2ObjectOpenHashMap<>();
protected long cacheSalt = 0L;
private static List<Class<?>> validItemInputs = Lists.newArrayList(IItemIngredient.class, ArrayList.class, String.class, Item.class, Block.class, ItemStack.class, ItemStack[].class); private static List<Class<?>> validItemInputs = Lists.newArrayList(IItemIngredient.class, ArrayList.class, String.class, Item.class, Block.class, ItemStack.class, ItemStack[].class);
private static List<Class<?>> validFluidInputs = Lists.newArrayList(IFluidIngredient.class, ArrayList.class, String.class, Fluid.class, FluidStack.class, FluidStack[].class); private static List<Class<?>> validFluidInputs = Lists.newArrayList(IFluidIngredient.class, ArrayList.class, String.class, Fluid.class, FluidStack.class, FluidStack[].class);
@ -52,7 +53,7 @@ public abstract class AbstractRecipeHandler<RECIPE extends IRecipe> {
public abstract void addRecipe(Object... objects); public abstract void addRecipe(Object... objects);
public @Nullable RecipeInfo<RECIPE> getRecipeInfoFromInputs(List<ItemStack> itemInputs, List<Tank> fluidInputs) { public @Nullable RecipeInfo<RECIPE> getRecipeInfoFromInputs(List<ItemStack> itemInputs, List<Tank> fluidInputs) {
RECIPE recipe = recipeCache.get(RecipeHelper.hashMaterialsRaw(itemInputs, fluidInputs)); RECIPE recipe = recipeCache.get(RecipeHelper.hashMaterialsRaw(itemInputs, fluidInputs, cacheSalt));
if (recipe != null) { if (recipe != null) {
RecipeMatchResult matchResult = recipe.matchInputs(itemInputs, fluidInputs); RecipeMatchResult matchResult = recipe.matchInputs(itemInputs, fluidInputs);
if (matchResult.matches()) { if (matchResult.matches()) {
@ -94,8 +95,14 @@ public abstract class AbstractRecipeHandler<RECIPE extends IRecipe> {
} }
public void refreshCache() { public void refreshCache() {
cacheSalt = 0L;
do {
recipeCache.clear(); recipeCache.clear();
}
while (!fillHashCache());
}
public boolean fillHashCache() {
recipeLoop: for (RECIPE recipe : recipeList) { recipeLoop: for (RECIPE recipe : recipeList) {
List<List<ItemStack>> itemInputLists = new ArrayList<>(); List<List<ItemStack>> itemInputLists = new ArrayList<>();
List<List<FluidStack>> fluidInputLists = new ArrayList<>(); List<List<FluidStack>> fluidInputLists = new ArrayList<>();
@ -134,26 +141,36 @@ public abstract class AbstractRecipeHandler<RECIPE extends IRecipe> {
for (Pair<List<ItemStack>, List<FluidStack>> materials : materialListTuples) { for (Pair<List<ItemStack>, List<FluidStack>> materials : materialListTuples) {
for (List<ItemStack> items : PermutationHelper.permutations(materials.getLeft())) { for (List<ItemStack> items : PermutationHelper.permutations(materials.getLeft())) {
for (List<FluidStack> fluids : PermutationHelper.permutations(materials.getRight())) { for (List<FluidStack> fluids : PermutationHelper.permutations(materials.getRight())) {
recipeCache.put(RecipeHelper.hashMaterials(items, fluids), recipe); long hash = RecipeHelper.hashMaterials(items, fluids, cacheSalt);
if (recipeCache.containsKey(hash)) {
cacheSalt++;
NCUtil.getLogger().info(getRecipeName() + " encountered a hash clash [" + RecipeHelper.getRecipeString(recipe) + " == " + RecipeHelper.getRecipeString(recipeCache.get(hash)) + "]! Incrementing salt to " + cacheSalt + " and restarting caching...");
return false;
}
else {
recipeCache.put(RecipeHelper.hashMaterials(items, fluids, cacheSalt), recipe);
} }
} }
} }
} }
} }
public static void addValidItemInput(Class itemInputType) { return true;
}
public static void addValidItemInput(Class<?> itemInputType) {
validItemInputs.add(itemInputType); validItemInputs.add(itemInputType);
} }
public static void addValidFluidInput(Class fluidInputType) { public static void addValidFluidInput(Class<?> fluidInputType) {
validFluidInputs.add(fluidInputType); validFluidInputs.add(fluidInputType);
} }
public static void addValidItemOutput(Class itemOutputType) { public static void addValidItemOutput(Class<?> itemOutputType) {
validItemOutputs.add(itemOutputType); validItemOutputs.add(itemOutputType);
} }
public static void addValidFluidOutput(Class fluidOutputType) { public static void addValidFluidOutput(Class<?> fluidOutputType) {
validFluidOutputs.add(fluidOutputType); validFluidOutputs.add(fluidOutputType);
} }

View File

@ -509,32 +509,32 @@ public class RecipeHelper {
return new OreIngredient(oreName, stackSize); return new OreIngredient(oreName, stackSize);
} }
public static long hashMaterialsRaw(List<ItemStack> items, List<Tank> fluids) { public static long hashMaterialsRaw(List<ItemStack> items, List<Tank> fluids, long salt) {
long hash = 1L; long hash = 1L;
Iterator<ItemStack> itemIter = items.iterator(); Iterator<ItemStack> itemIter = items.iterator();
while (itemIter.hasNext()) { while (itemIter.hasNext()) {
ItemStack stack = itemIter.next(); ItemStack stack = itemIter.next();
hash = 31L * hash + (stack == null || stack.isEmpty() ? 0L : RecipeItemHelper.pack(stack)); hash = 31L * hash + (stack == null || stack.isEmpty() ? 0L : RecipeItemHelper.pack(stack)) + salt;
} }
Iterator<Tank> fluidIter = fluids.iterator(); Iterator<Tank> fluidIter = fluids.iterator();
while (fluidIter.hasNext()) { while (fluidIter.hasNext()) {
Tank tank = fluidIter.next(); Tank tank = fluidIter.next();
hash = 31L * hash + (tank == null || tank.getFluid() == null ? 0L : tank.getFluid().getFluid().getName().hashCode()); hash = 31L * hash + (tank == null || tank.getFluid() == null ? 0L : tank.getFluid().getFluid().getName().hashCode()) + salt;
} }
return hash; return hash;
} }
public static long hashMaterials(List<ItemStack> items, List<FluidStack> fluids) { public static long hashMaterials(List<ItemStack> items, List<FluidStack> fluids, long salt) {
long hash = 1L; long hash = 1L;
Iterator<ItemStack> itemIter = items.iterator(); Iterator<ItemStack> itemIter = items.iterator();
while (itemIter.hasNext()) { while (itemIter.hasNext()) {
ItemStack stack = itemIter.next(); ItemStack stack = itemIter.next();
hash = 31L * hash + (stack == null || stack.isEmpty() ? 0L : RecipeItemHelper.pack(stack)); hash = 31L * hash + (stack == null || stack.isEmpty() ? 0L : RecipeItemHelper.pack(stack)) + salt;
} }
Iterator<FluidStack> fluidIter = fluids.iterator(); Iterator<FluidStack> fluidIter = fluids.iterator();
while (fluidIter.hasNext()) { while (fluidIter.hasNext()) {
FluidStack stack = fluidIter.next(); FluidStack stack = fluidIter.next();
hash = 31L * hash + (stack == null ? 0L : stack.getFluid().getName().hashCode()); hash = 31L * hash + (stack == null ? 0L : stack.getFluid().getName().hashCode()) + salt;
} }
return hash; return hash;
} }

View File

@ -443,42 +443,46 @@ public class CraftingRecipeHandler {
addShapedOreRecipe(NCBlocks.quantum_computer_controller, new Object[] {"EPE", "PFP", "EPE", 'E', "ingotExtreme", 'P', Items.ENDER_PEARL, 'F', "steelFrame"}); addShapedOreRecipe(NCBlocks.quantum_computer_controller, new Object[] {"EPE", "PFP", "EPE", 'E', "ingotExtreme", 'P', Items.ENDER_PEARL, 'F', "steelFrame"});
addShapedOreRecipe(NCBlocks.quantum_computer_qubit, new Object[] {"ESE", "PRP", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL, 'R', "blockRedstone"}); addShapedOreRecipe(NCBlocks.quantum_computer_qubit, new Object[] {"ESE", "PRP", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL, 'R', "blockRedstone"});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 0), new Object[] {"SES", "ECE", "SES", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 0), new Object[] {"SES", "EPE", "SES", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 1), new Object[] {"SES", "ECE", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 1), new Object[] {"SES", "EPE", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 2), new Object[] {"SSS", "ECE", "SSS", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 2), new Object[] {"SSS", "EPE", "SSS", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 3), new Object[] {"SES", "SCS", "SES", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 3), new Object[] {"SES", "SPS", "SES", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 4), new Object[] {"ESS", "ECE", "SSE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 4), new Object[] {"ESS", "EPE", "SSE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 6), new Object[] {"SSS", "ECE", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 6), new Object[] {"SSS", "EPE", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 8), new Object[] {"SSS", "SCS", "SEE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 8), new Object[] {"SSS", "SPS", "SEE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 0), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 9), Blocks.REDSTONE_TORCH}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 5), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 4)});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 1), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 10), Blocks.REDSTONE_TORCH}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 4), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 5)});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 2), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 11), Blocks.REDSTONE_TORCH}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 7), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 6)});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 4), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 5), Blocks.REDSTONE_TORCH}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 6), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 7)});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 5), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 4), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 6), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 7), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 7), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 6), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 9), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 0), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 10), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 1), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 11), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 2), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 0), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 9), "dustRedstone"}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 9), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 0), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 1), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 10), "dustRedstone"}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 10), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 1), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 2), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 11), "dustRedstone"}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 11), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 2), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 4), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 5), "dustRedstone"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 5), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 4), "dustRedstone"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 6), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 7), "dustRedstone"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 7), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 6), "dustRedstone"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 9), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 0), "dustRedstone"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 10), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 1), "dustRedstone"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 11), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, 2), "dustRedstone"});
for (int i = 0; i < QuantumGateEnums.SingleType.values().length; i++) { for (int i = 0; i < QuantumGateEnums.SingleType.values().length; i++) {
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, i), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, i)}); addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, i), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, i), "dustEnergetic"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, i), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_single, 1, i)});
} }
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 4), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 5)});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 6), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 7)});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 9), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 0), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 10), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 1), Blocks.REDSTONE_TORCH});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 11), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, 2), Blocks.REDSTONE_TORCH});
for (int i : new int[] {0, 1, 2, 3, 4, 6, 8, 9, 10, 11}) {
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_single, 1, i), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_control, 1, i)});
}
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_swap, 1, 0), new Object[] {"EES", "EPE", "SEE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_swap, 1, 1), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_swap, 1, 0), "dustEnergetic"});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_gate_swap, 1, 0), new Object[] {new ItemStack(NCBlocks.quantum_computer_gate_swap, 1, 1)});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_connector, 8), new Object[] {"ESE", "SPS", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL}); addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_connector, 8), new Object[] {"ESE", "SPS", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL});
addShapedOreRecipe(new ItemStack(NCBlocks.quantum_computer_code_generator, 1, 0), new Object[] {"ESE", "PBP", "ESE", 'E', "ingotExtreme", 'S', "ingotSteel", 'P', Items.ENDER_PEARL, 'B', Items.WRITABLE_BOOK});
addShapelessOreRecipe(new ItemStack(NCBlocks.quantum_computer_code_generator, 1, 1), new Object[] {new ItemStack(NCBlocks.quantum_computer_code_generator, 1, 0)});
} }
} }

View File

@ -0,0 +1,20 @@
{
"forge_marker": 1,
"defaults": {
"model":"cube_all"
},
"variants": {
"type": {
"qasm": {
"textures": {
"all":"nuclearcraft:blocks/quantum_computer/code_generator/qasm"
}
},
"qiskit": {
"textures": {
"all":"nuclearcraft:blocks/quantum_computer/code_generator/qiskit"
}
}
}
}
}

View File

@ -424,9 +424,14 @@ tile.nuclearcraft.quantum_computer_gate_swap.cswap.name=Quantum Computer Control
tile.nuclearcraft.quantum_computer_gate_swap.cswap.desc=Performs a controlled swap on two lists of qubits. tile.nuclearcraft.quantum_computer_gate_swap.cswap.desc=Performs a controlled swap on two lists of qubits.
tile.nuclearcraft.quantum_computer_connector.name=Quantum Computer Connector tile.nuclearcraft.quantum_computer_connector.name=Quantum Computer Connector
tile.nuclearcraft.quantum_computer_port.name=Quantum Computer Port (WIP) tile.nuclearcraft.quantum_computer_port.name=Quantum Computer OC Port (WIP)
tile.nuclearcraft.quantum_computer_port.desc=Used to access the quantum computer via OpenComputers. tile.nuclearcraft.quantum_computer_port.desc=Used to access the quantum computer via OpenComputers.
tile.nuclearcraft.quantum_computer_code_generator.qasm.name=Quantum Computer QASM Code Generator
tile.nuclearcraft.quantum_computer_code_generator.qasm.desc=Used to generate QASM code for use with IBM Q.
tile.nuclearcraft.quantum_computer_code_generator.qiskit.name=Quantum Computer Qiskit Code Generator
tile.nuclearcraft.quantum_computer_code_generator.qiskit.desc=Used to generate Qiskit code for use with IBM Q.
tile.nuclearcraft.fluid_oxygen.name=Oxygen tile.nuclearcraft.fluid_oxygen.name=Oxygen
fluid.oxygen=Oxygen fluid.oxygen=Oxygen
@ -2173,12 +2178,18 @@ info.nuclearcraft.multitool.quantum_computer.finish_second_swap_list=Gate now se
info.nuclearcraft.multitool.quantum_computer.control_swap_gate_info=Gate currently swapping qubits %s with qubits %s, controlled by qubits %s info.nuclearcraft.multitool.quantum_computer.control_swap_gate_info=Gate currently swapping qubits %s with qubits %s, controlled by qubits %s
info.nuclearcraft.multitool.quantum_computer.controller.qasm_start=Quantum Computer entering QASM mode! Gate operations will be recorded but not carried out in the game. info.nuclearcraft.multitool.quantum_computer.controller.code_qasm_start=Quantum Computer entering QASM mode! Gate operations will be recorded but not carried out in the game.
info.nuclearcraft.multitool.quantum_computer.controller.qasm_too_many_qubits=Quantum Computer can not enter QASM mode, too many qubits installed. info.nuclearcraft.multitool.quantum_computer.controller.code_qiskit_start=Quantum Computer entering Qiskit mode! Gate operations will be recorded but not carried out in the game.
info.nuclearcraft.multitool.quantum_computer.controller.code_too_many_qubits=Quantum Computer can not enter code generation mode, too many qubits installed.
info.nuclearcraft.multitool.quantum_computer.controller.code_exit_too_many_qubits=Quantum Computer exiting code generation mode, too many qubits installed.
info.nuclearcraft.multitool.quantum_computer.controller.code_exit_empty=Quantum Computer exiting code generation mode.
info.nuclearcraft.multitool.quantum_computer.controller.qasm_print=Quantum Computer exiting QASM mode, saved generated code to %s info.nuclearcraft.multitool.quantum_computer.controller.qasm_print=Quantum Computer exiting QASM mode, saved generated code to %s
info.nuclearcraft.multitool.quantum_computer.controller.qasm_error=Quantum Computer exiting QASM mode, an error occurred attempting save generated code to %s info.nuclearcraft.multitool.quantum_computer.controller.qasm_error=Quantum Computer exiting QASM mode, an error occurred attempting save generated code to %s
info.nuclearcraft.multitool.quantum_computer.controller.qasm_exit_too_many_qubits=Quantum Computer exiting QASM mode, too many qubits installed to generate code. info.nuclearcraft.multitool.quantum_computer.controller.qasm_exit_empty=Quantum Computer exiting QASM mode.
info.nuclearcraft.multitool.quantum_computer.controller.qasm_exit=Quantum Computer exiting QASM mode. info.nuclearcraft.multitool.quantum_computer.controller.qiskit_print=Quantum Computer exiting Qiskit mode, saved generated code to %s
info.nuclearcraft.multitool.quantum_computer.controller.qiskit_error=Quantum Computer exiting Qiskit mode, an error occurred attempting save generated code to %s
info.nuclearcraft.multitool.quantum_computer.controller.qiskit_exit_empty=Quantum Computer exiting Qiskit mode.
item.nuclearcraft.geiger_counter.name=Geiger Counter item.nuclearcraft.geiger_counter.name=Geiger Counter
item.nuclearcraft.geiger_counter.desc=Detects radiation and informs the player of their rad count. Can be used to read the irradiation of entities. Will be muted if off the hotbar. item.nuclearcraft.geiger_counter.desc=Detects radiation and informs the player of their rad count. Can be used to read the irradiation of entities. Will be muted if off the hotbar.
@ -2659,8 +2670,8 @@ gui.nc.config.category.quantum.tooltip=Configure quantum mechanical systems.
gui.nc.config.quantum_max_qubits_live=Max Live Qubits gui.nc.config.quantum_max_qubits_live=Max Live Qubits
gui.nc.config.quantum_max_qubits_live.comment=The maximum number of actively calculating qubits a single quantum computer multiblock can have. !!!WARNING!!! Allowing for complex circuits of more than seven qubits will begin to seriously impact performance and use up a huge amount of memory. Increase this limit with EXTREME caution! gui.nc.config.quantum_max_qubits_live.comment=The maximum number of actively calculating qubits a single quantum computer multiblock can have. !!!WARNING!!! Allowing for complex circuits of more than seven qubits will begin to seriously impact performance and use up a huge amount of memory. Increase this limit with EXTREME caution!
gui.nc.config.quantum_max_qubits_qasm=Max QASM Qubits gui.nc.config.quantum_max_qubits_code=Max Coding Qubits
gui.nc.config.quantum_max_qubits_qasm.comment=The maximum number of qubits a single quantum computer multiblock can have for generating QASM code. !!!WARNING!!! Gates with more control qubits will take increasingly more work and memory to decompile into basic operations, thus will generate increasingly mode code. IBMQ Experience's circuit composer will begin to struggle to deal with more than a few hundreds of lines of code. Increase this limit with EXTREME caution! gui.nc.config.quantum_max_qubits_code.comment=The maximum number of qubits a single quantum computer multiblock can have for generating code. !!!WARNING!!! Gates with more control qubits will take increasingly more work and memory to decompile into basic operations, thus will generate increasingly mode code. If generating QASM code, IBM Q Experience's circuit composer will begin to struggle to deal with more than a few hundred lines. Increase this limit with EXTREME caution!
gui.nc.config.quantum_angle_precision=Gate Angle Precision gui.nc.config.quantum_angle_precision=Gate Angle Precision
gui.nc.config.quantum_angle_precision.comment=Controls the precision allowed for setting the working angle of gates by defining the number of available angles, uniformly distributed from 0 to 360 degrees. gui.nc.config.quantum_angle_precision.comment=Controls the precision allowed for setting the working angle of gates by defining the number of available angles, uniformly distributed from 0 to 360 degrees.
@ -3149,6 +3160,7 @@ nuclearcraft.multiblock_validation.turbine.different_type_blades=The rotor blade
nuclearcraft.multiblock_validation.turbine.missing_blades=Each section of the rotor shaft must have rotor blades or stators of the same type extend fully to the wall for the turbine to form nuclearcraft.multiblock_validation.turbine.missing_blades=Each section of the rotor shaft must have rotor blades or stators of the same type extend fully to the wall for the turbine to form
nuclearcraft.multiblock_validation.quantum_computer.too_many_qubits=There are %s qubits connected to this quantum computer; there can only be %s at most for it to form nuclearcraft.multiblock_validation.quantum_computer.too_many_qubits=There are %s qubits connected to this quantum computer; there can only be %s at most for it to form
nuclearcraft.multiblock_validation.quantum_computer.too_many_qubits=There must be no more than one code generator connected to this quantum computer
nuclearcraft.collector.jei_name=Collector nuclearcraft.collector.jei_name=Collector
nuclearcraft.multiblock_gui.fission_moderator.jei_name=Fission Moderator nuclearcraft.multiblock_gui.fission_moderator.jei_name=Fission Moderator

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 710 B

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 706 B

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 702 B

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 708 B

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 696 B

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 714 B

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 714 B

After

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 722 B

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

View File

@ -1,6 +1,7 @@
Suggestions from: This probably wont happen but in stead of multiblock reactors Add salt-based fix for recipe hash caching (start from zero, if there's a clash, start again after incrementing)
Test with iron + coal alloy furnace recipe in modified Enigmatica 2 instance
Generate Qiskit code? Suggestions from: This probably wont happen but in stead of multiblock reactors
Adjacent MSR vessels with same filter form bundle to share flux, shared criticality factor is sum of single vessel criticality factors Adjacent MSR vessels with same filter form bundle to share flux, shared criticality factor is sum of single vessel criticality factors